I've recently discovered, that when I open a new text file (extension .txt
) in nano
, there is actually a limited syntax coloring:
That is, if a line starts with number sign/hash, it is colored.
I think this is great, and I really like this (for a txt file, I really don't need any other syntax color, but one marking comment, with the same comment syntax as in bash
), so I was wondering how/where it was defined.
According to How to set nano default syntax highlighting for files with no extension?, syntax coloring files for nano are in /usr/share/nano/
directory, and are "imported" via /etc/nanorc
file.
So, I tried checking:
$ grep -r txt /usr/share/nano/
/usr/share/nano/cmake.nanorc:syntax cmake "(CMakeLists\.txt|\.cmake)$"
... but the only reference to .txt
is from cmake
, and I don't think this is what sets the coloring for test.txt
.
So, how does nano
determine the syntax coloring for a test.txt
file?
Simple grepping for
#
in the/usr/share/nano/
directory gives the following important result among others:The whole file on Ubuntu 20.04 LTS is the following:
So it is some dynamic highlighter in action.
Next things to check trigger - enter
GNU nano 4.8
to get it in red and some e-mail<[email protected]>
to get it in magenta. Newer versions have URLs in lightblue and so on. See image below: