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.

3 Answers 3


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.

On writing the above in December 2015, the most recent release of nano was version 2.4.2 (July 2015). At that point, nano was 23336 lines (7657 statements) in C, which was a small fraction of the 131621 lines of text files (counting the ".po" message files). At the moment (October 2021, six years later), the program size is about the same size (fewer lines, more statements), but the other text files have roughly doubled the size of its source-tree (253036 lines). It's not exactly "small" any longer (but nowhere near the size of vim). A couple of weeks before releasing nano 5.0 in July 2020, the developer added eight names for entries in xterm's 256-color palette, in src/rcfile.c:

const char hues[COLORCOUNT][8] = { "red", "green", "blue",
                                   "yellow", "cyan", "magenta",
                                   "white", "black", "normal",
                                   "pink", "purple", "mauve",
                                   "lagoon", "mint", "lime",
                                   "peach", "orange", "latte",
                                   "grey", "gray" };

                              COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA,
                              COLOR_WHITE, COLOR_BLACK, THE_DEFAULT,
                              204, 163, 134, 38, 48, 148, 215, 208, 137,
                              COLOR_BLACK + 8, COLOR_BLACK + 8 };

That doesn't appear to be extensible (but at least it uses ncurses). However, it does not address OP's question because it does not provide a hex or RGB method for configuring nano. In developing ncurses, I created an example which reads the X11 rgb.txt file, as part of making the program display X pixmap files in color. But it also reads and displays using a data file for xterm's 256-color palette. For screenshots, see the discussion of the picsmap program.

  • Since GNU Nano version 5.0, on terminals that support at least 256 colors, nine new color names are available (in addition to the 8 predefined ANSI colors): pink, purple, mauve, lagoon, mint, lime, peach, orange, and latte. Commented Oct 8, 2021 at 16:08

Some six years after this question was asked, a version of nano with this feature was released:

This release also introduces 14 new color names, including crimson, beet, brick, brown, ocher, plum, rosy, sage, sand, sea, sky, slate, tawny, and teal, as well as the ability to specify colors as three-digit hexadecimal numbers, in the rgb format.

And from the manpage of nanorc:

On terminal emulators that can do at least 256 colors, [...] the color may also be specified as a three-digit hexadecimal number prefixed with #, with the digits representing the amounts of red, green, and blue, respectively. This tells nano to select from the available palette the color that approximates the given values.


From the news page for the nano 6.0 release (2021):

Colors can now be specified also as three-digit hexadecimal numbers, in the format #rgb. This picks from the 216 index colors (that most terminals know) the color that is nearest to the given values. For users who dislike numbers, there are fourteen new color names: rosy, beet, plum, sea, sky, slate, teal, sage, brown, ocher, sand, tawny, brick, and crimson.

  • Same as: unix.stackexchange.com/a/708647/70524 This should be an edit there
    – muru
    Commented May 23 at 2:16
  • 1
    @muru Certainly not. That answer is basically a link-only answer, and it links to a blog post which is both less informative and less authoritative than nano's official news page. By the time I edit in a different link, and provide important details not found in that answer's link (the actual syntax of the color format), it's a new answer. I still upvoted that one as well, mind you. Commented May 23 at 5:41
  • Alright, I edited in the details there, so this post is now obsolete.
    – muru
    Commented May 23 at 5:56
  • 1
    @muru You have increased the quality of that answer by about 1000%, and proven that your first comment was wrong -- if the two answers were the same, you wouldn't have needed to take all the info from this answer and add it to that one. Commented May 23 at 6:01
  • 1
    @muru Yes, I noticed that you went out of your way to find a different source for the same information... Would you have known to look for it if this answer hadn't been here? Again, the answers were not the same before you added all that. Commented May 23 at 6:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .