I'm trying to customize nano to my needs, I copied nanorc from the /etc directory in my home directory and haven't edited anything so far.
My goal is to enable syntax highlighting for config files such as .bashrc. Syntax highlighting already works when I assign an extension to files such as file.py but it doesn't work for config files which are usually full of comments and options unless I explicitly type nano configfile --syntax=sh
. I would like this flag to be enabled by default.
When looking into the nanorc file I noticed the statement include /usr/share/nano/*.nanorc
. When sourcing the file with source .nanorc
I get the following error:
.nanorc:236: command not found: include
Why is this happening and how can I fix it? Thanks!
I found a solution to the problem!
In order to perform syntax highlighting, nano uses a set of configuration files which located (in Ubuntu 16.04) in the directory /usr/share/nano. For example, you have a file related to syntax highlighting of shell scripts (sh.nanorc), Python scripts (python.nanorc), etc...
The syntax highlighting rules to be used is determined based on some pattern matching criteria specified in each file. Python files are matched based on the .py extension for instance.
When there is no match between the file characteristics (extension, interpreter line, etc...) nano uses the default file "default.nanorc".
This means that when you are opening a generic text file such as ~/.bashrc (for example) syntax highlighting is going to be performed using the regex rules contained in the file "default.nanorc". Just edit this file according to your required rules and then save it. Next time you open nano the changes are already stored and effective.
By the way, you can edit syntax highlighting for all other kind of files or the matching criteria between files and syntax highlighting rules by simply editing the corresponding *.nanorc file.