How to Change the Colors of Nano

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
455
Reaction score
316
Credits
3,611
Preamble:
Nano, a venerable project, originally designed as a sort of replacement for pico, using GNU licensing, has been around since the late 90s. In all these years, it's been my go-to terminal editor, and I was pleasantly surprised when I found out it was being included in vanilla installs of many distros. Also, in all those years, I never knew it could do colors!

Last evening, while helping a user on another forum who had a question about nano and colors, I decided to jump in and see what I could do. Here's what I learned.

This thread isn't a big, in depth research and analysis. It's just a bit of knowledge I impart to you for the "fun" of it. Ignore it if you wish. Appreciate it for what it is.

Getting started:
Note: Nano is full of options. However, I am concentrating on nano colors here.
You can make system-wide config changes by editing the file /etc/nanorc. This file includes most of the standard options, and you can just uncomment those you want to enable.
Each user can set their own nano config by creating and editing the file ~/.nanorc. Yes, ugh, it's in the root of home, rather than ~/.config, which sucks. But it is what it is. Moving forward ...

This is my ~/.nanorc file:
Code:
# colors
# nano 5.4 color declarations:
# red, green, blue, magenta, yellow, cyan, white, black, and normal
# 256 color terminals may also allow:
# pink, purple, mauve, lagoon, mint, lime, peach, orange, latte
# bold and italic supported
#set titlecolor lightwhite,yellow
#set keycolor italic,white,blue
#set functioncolor normal,normal
#set numbercolor italic,white,magenta
#set errorcolor lightwhite,red
#set scrollercolor green,white
#set selectedcolor black,white
#set stripecolor black,white
#set statuscolor black,white

# nano 5.8 color declarations:
# white, black, blue, green, red,  cyan,  yellow, magenta, and normal
# The name of the foreground color may be prefixed with bright.
# bold and italic not supported
set titlecolor brightwhite,yellow
set keycolor white,blue
set functioncolor normal,normal
set numbercolor white,magenta
set errorcolor brightwhite,red
set selectedcolor black,white
set stripecolor black,white
set statuscolor black,white

You should notice, I have two sets of declarations. What? Well, you can blame the nano devs for that, I guess. I built my original .nanorc file one my play machine, which is running Linux Mint Debian Edition 5, and is running nano 5.4. When I copied it over to my main machine, running Linux Mint 20.3, and nano 5.8, I got a bunch of nano config errors! Yeah. So. It ends up that nano 5.8 changed color definitions, and removed support for bold, and italic text. What a bummer.

So, apparently, nano 5.4 uses the term "light", versus 5.8's "bright" when defining lighter colors, e.g. "lightblue", "brightblue". Maybe this is to conform better to some ANSI color definitions?
I'm not sure why they would remove bold and italic in 5.8. But they did.

The astute of you might also notice that the scrollercolor definition is not in the 5.8 colors. In 5.4, nano supports a scrollbar (enabled with the -q option). In 5.8, it appears the scrollbar is no longer supported.

Another thing to point out is that there are no definitions for content text color. I didn't do a whole lot of research, but this appears to be intentional, allowing nano to handle context highlighting dynamically.

More info:
man nano
man 5 nanorc
 


C

CrazedNerd

Guest
Wow, great post, i hate the default color scheme for nano when you include the numbering.
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
8,942
Reaction score
7,916
Credits
37,641
I missed seeing this Thread when it first appeared, and it was only when friend @CrazedNerd commented that I picked up on it. I have some input to provide by end of weekend, but I would ask the OP

When I copied it over to my main machine, running Linux Mint 20.3, and nano 5.8, I got a bunch of nano config errors!

... if that version number is a typo? It should be 4.8.

Change log notes reveal, at

https://lists.gnu.org/archive/html/info-gnu/2020-07/msg00010.html

amongst other changes, that with version 5.0

• All color names can be preceded with "bold," and/or "italic,"
(in that order) to get a bold and/or italic typeface.
Back with more when I tie it together.

Cheers

Wizard
 
C

CrazedNerd

Guest
I missed seeing this Thread when it first appeared, and it was only when friend @CrazedNerd commented that I picked up on it. I have some input to provide by end of weekend, but I would ask the OP



... if that version number is a typo? It should be 4.8.

Change log notes reveal, at

https://lists.gnu.org/archive/html/info-gnu/2020-07/msg00010.html

amongst other changes, that with version 5.0


Back with more when I tie it together.

Cheers

Wizard
Awwweee, we're friends!

Over the past week, i've learned so much about nano and i think it's the best text editor ever...atleast when it just comes to plain text editing. Lot's and lots of keyboard shortcuts, i'm still getting used to it but i've been able to minimize my keystrokes for taking notes on what i learn.
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
10,088
Reaction score
8,670
Credits
83,383
It'd be nice if I could just set the theme as 'solarized' (or other common/near-universal theme names).

That should be a thing... That should definitely be a thing.
 
OP
SlowCoder

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
455
Reaction score
316
Credits
3,611
... if that version number is a typo? It should be 4.8.
Yes, it is! And that is why my confusion that they would remove functionality. In reality, it looks to be the reverse, since I misread the versions! Good eye!
 
OP
SlowCoder

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
455
Reaction score
316
Credits
3,611
It'd be nice if I could just set the theme as 'solarized' (or other common/near-universal theme names).

That should be a thing... That should definitely be a thing.
Based solely on the 5.0 release notes wizardfromoz posted, it doesn't look like nano supports rgb colors, but they did add a few 256 color terminal colors. Maybe you can approximate a theme and publish here?
 

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,519
Reaction score
1,249
Credits
11,087
Lot's and lots of keyboard shortcuts,
Yeah. https://www.nano-editor.org/dist/latest/cheatsheet.html
i've learned so much about nano and i think it's the best text editor ever
I wouldn't go that far, but I do agree in that it is a great text editor.
Each user can set their own nano config by creating and editing the file ~/.nanorc.
Or, you can grab these https://github.com/scopatz/nanorc place them in ~/config and enjoy :)
 

Members online

No members online now.

Latest posts

Top