I enabled syntax highlight in nano (PHP), but not happy with the default, I would like for example to have the comments displayed in very light grey.

However, the documentation I found seems to suggest I can only write colors like "yellow", "red" etc.

Is there a way to specify a color by its hex/RGB code? Is there a limitation in the number of colors bash/nano and so on can display? Obviously I am not very experienced with the Linux world.

Same question for VIM, I might switch to VIM if that is not possible.


nano is small. In this case, it limits the choices to the 8 predefined ANSI colors (plus bright/bold) so that it can use the predefined symbols from curses.h (such as COLOR_BLUE) as a guide to naming.

Many terminals support 256 predefined colors; nano can't take advantage of them, but Vim can.

Terminals which allow directly specifying the R/G/B content of a color are an exception rather than a rule—unlike GUIs.

Some terminals (including Xterm, which I maintain) support the escape sequence \e]4;N;#RRGGBB\a to change palette color N to the specified RGB value, and \e[38;2;R;G;Bm to set the foreground color to the closest approximation in the palette of the specified RGB value (use 48 instead of 38 for the background color). However, changing a palette color is not useful for nano, because it is taking advantage of the existing palette, in contrast with (the much larger) Vim, which can do this with an add-on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.