Link them to your user's nano configuration file (present at ~/.nanorc, ${XDG_CONFIG_HOME}/nano/nanorc, or ~/.config/nano/nanorc, whichever is encountered first) with something similiar to this line:
nits@nits-excalibur:~$ cat ~/.nanorc
include /usr/share/nano/sh.nanorc
Now, syntax highlighting is enabled in nano for whatever file you linked (You could also link multiple files)
Note: Sometimes you might get a segmentation fault after you have edited your ~/.nanorc file. If such an error occurs, unsetting the LANG environment variable helps. You can unset it with unset LANG in the terminal. (Solution obtained from here)
There are also other solutions if you are not satisfied with your bash highlighting. One example of such can be found here
You can also write include /usr/share/nano/* to the ~/.nanorc file to enable all languages to be highlighted if your nano version supports it.
Yes you can, however the default syntax definitions are quite poor and incomplete. I'm maintaining a more accurate set of definitions here, for anyone who finds them useful.
To install, run:
git clone https://github.com/scopatz/nanorc.git
cd nanorc
make install
Add these lines to the ~/.nanorc
include ~/.nano/syntax/html.nanorc
include ~/.nano/syntax/css.nanorc
include ~/.nano/syntax/php.nanorc
include ~/.nano/syntax/ALL.nanorc
Specify the ones you want to have colorizing for, and you will have to tune these colors to your preferences. The ALL.nanorc describes features for all yet unclassified files. These are the tools you need to get started, not the end polished product.
Also mentioned, to enable highlighting for a language, you add include and the path to the language definition you want to enable to your ~/.nanorc file. So, for example, to enable C/C++ you would add this line.
include /usr/share/nano/c.nanorc
The find command searches for files or directories within the specified directory.
The -iname flag tells it to only look for files with a name that ends with .nanorc.
The -exec flags defines a command to execute on each file found.
The {} gets replaced with the file name.
\; is used to signify the end of the command to execute to the find command.
Lastly, >> ~/.nanorc causes the output to be appended to your ~/.nanorc file.
I thought I might suggest something more fresh and up-to-date as of almost 2020 :
Scopatz's nanorc on Git has all you need. it is still regularly updated.
and is delivered with a pretty neat install guide & documented installer that allows you to get things rolling fast, clean, & easy.
Note : You might have to drop some of the highlighters from the nanorc file or comment them out (etc-host, html, and html.j2) as they seem to be faulty, but no big deal
The most complete and up to date syntax hilighters for nano are maintained here.
To install all highlighters for your user just run:
cd /tmp
git clone https://github.com/tech4david/nano-highlight.git
cd nano-highlight/
make install
echo "include ~/.nano/syntax/ALL.nanorc" >> ~/.nanorc
For those who are having trouble after following the instructions above, also check if you have duplicate definitions. These will disable all syntax highlighting for all files. I ran into this after adding a nanorc.nanorc file, and not realising that my ~/.nanorc already had an identical section, i.e.:
## Here is an example for nanorc files.
##
syntax "nanorc" "\.?nanorc$"
## Possible errors and parameters
icolor brightwhite "^[[:space:]]*((un)?set|include|syntax|i?color).*$"
## Keywords
icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|$
icolor green "^[[:space:]]*(set|unset|include|syntax)\>"
(...)
The nano editor provides syntax highlighting for a few languages and scripts by itself. Check out
/usr/share/nano/
Link them to your user's nano configuration file (present at
~/.nanorc
,${XDG_CONFIG_HOME}/nano/nanorc
, or~/.config/nano/nanorc
, whichever is encountered first) with something similiar to this line:Now, syntax highlighting is enabled in nano for whatever file you linked (You could also link multiple files)
Note: Sometimes you might get a
segmentation fault
after you have edited your~/.nanorc
file. If such an error occurs, unsetting the LANG environment variable helps. You can unset it withunset LANG
in the terminal. (Solution obtained from here)There are also other solutions if you are not satisfied with your bash highlighting. One example of such can be found here
You can also write
include /usr/share/nano/*
to the ~/.nanorc file to enable all languages to be highlighted if your nano version supports it.Yes you can, however the default syntax definitions are quite poor and incomplete. I'm maintaining a more accurate set of definitions here, for anyone who finds them useful.
To install, run:
Add these lines to the ~/.nanorc
Specify the ones you want to have colorizing for, and you will have to tune these colors to your preferences. The
ALL.nanorc
describes features for all yet unclassified files. These are the tools you need to get started, not the end polished product.I used this command to quickly enable all available languages.
As mentioned in other answers,
/usr/share/nano/
contains the definitions for different languages.Also mentioned, to enable highlighting for a language, you add
include
and the path to the language definition you want to enable to your~/.nanorc
file. So, for example, to enable C/C++ you would add this line.The
find
command searches for files or directories within the specified directory.-iname
flag tells it to only look for files with a name that ends with.nanorc
.-exec
flags defines a command to execute on each file found.{}
gets replaced with the file name.\;
is used to signify the end of the command to execute to thefind
command.>> ~/.nanorc
causes the output to be appended to your~/.nanorc
file.This should include all the syntax highlighting plugins included by default, and any you add to /usr/share/nano:
Or, edit /etc/nanorc and see if you can uncomment the includes.
This works if you have a version of nano that refuses to accept wildcards in the .nanorc file.
Just run this line every time you add an additional .nanorc colour config.
You can use this to include all: (add this to
~/.nanorc
file)Happy coding!
I accidentally disabled highlighting using the keyboard shortcut Alt+Y. It can be turned on again with the same keyboard shortcut.
I have some nano syntax highlighting at my github.
There are live example screenshots for html and php:
and
I thought I might suggest something more fresh and up-to-date as of almost 2020 :
Scopatz's nanorc on Git has all you need. it is still regularly updated.
and is delivered with a pretty neat install guide & documented installer that allows you to get things rolling fast, clean, & easy.
Note : You might have to drop some of the highlighters from the nanorc file or comment them out (etc-host, html, and html.j2) as they seem to be faulty, but no big deal
The most complete and up to date syntax hilighters for nano are maintained here.
To install all highlighters for your user just run:
For those who are having trouble after following the instructions above, also check if you have duplicate definitions. These will disable all syntax highlighting for all files. I ran into this after adding a
nanorc.nanorc
file, and not realising that my~/.nanorc
already had an identical section, i.e.: