This page was already viewed 429times
A .nanorc file is a configuration file used to customize the behavior and appearance of the nano text editor. It allows users to set options such as syntax highlighting, key bindings, and line numbering preferences.
By editing the .nanorc file, users can personalize their nano editor experience to better suit their needs and workflow.
In linux,All .nanorc files are located in /usr/share/nano/
* What is the issue with python3 highlights in nano ?When opening a python file with nano, you may experience this stange behavior of the file not properly colorizing the 'print()' and 'exec()' directives.
In fact, you may experience that python2 'print text' syntax is properly colored while python3 'print("text")' is not.
this issue can be easily observed simply by reading any python file with nano
* How to resolve it ?root@linux:#nano anyscript.py
This is due to a specific configuration in the python.nanorc file.
This issue may be resolved very easily by patching the python.nanorc file in /usr/share/nano/.
See section below to perform the required steps to resolve this issue.
To resolve this issue, it is necessary to patch the /usr/share/nano/python.nanorc file.
* Prerequisitebefore doing any alteration, be sure to save the current python.nanorc file as backup in case of trouble.
* Patch python3.nanorc fileroot@linux:#cp /usr/share/nano/python.nanorc /usr/share/nano/python.nanorc.backup
Open /usr/share/nano/python.nanorc, and add the following direective, right after the existing 'color brightcyan "\<(exec|print)([[:blank:]]|$)"' usually at line 23.
color brightcyan "\<(exec|print)\>"
Below is an easy automated way to fix python.nanorc file by patching it with only one linux command based on sed to update the file content.
root@linux:#sed -i '/\<(exec\|print)(/a color brightcyan "\\<(exec|print)\\>"' /usr/share/nano/python.nanorc
You can now verify the result by observing the nano screen of a python script display.
root@linux:#nano anyscript.py
any of its print() and exec() directives syntax in python3 format should be properly detected and colorized as expected.
Thats it. Thanks for reading.