Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr3486 :: Unleash the true potential of GNU nano text editor

Turn GNU nano text editor into a fancy, good looking & powerful editor

<< First, < Previous, , Latest >>

Hosted by hakerdefo on 2021-12-13 is flagged as Explicit and is released under a CC-BY-SA license.
text-editor, terminal, linux, nano, pico, pine, nanorc. (Be the first).
The show is available on the Internet Archive at: https://archive.org/details/hpr3486

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:08:36

Lightweight Apps.

Reviews of light weight applications

Text editors are highly subjective and highly opinionated commodities. Everyone is aware of infamous rivalry between users of Emacs and Vi/Vim. Every single text editor has its own strengths and weaknesses. At the end of the day it's the question of your personal preferences and muscle memory when it comes to default key-bindings. Both Emacs and Vim have a learning curve. Steepness of that curve depends on the person's background and interests. Hey, but today I'm not here to talk about Emacs and Vim. I'm here to talk about a simple, easy to use and almost ever present text editor called GNU nano. So what exactly is this nano text editor? Well, according to documentation available on GNU nano's website,

GNU nano was designed to be a free replacement for the Pico text editor, part of the Pine email suite from The University of Washington. It aimed to "emulate Pico as closely as is reasonable and then include extra functionality".

Pico and Pine email suites are still around so what was the need to create nano in the first place? The answer is license. Pico and Pine email suites nowadays are available under Apache-2.0 license but that always wasn't the case and this ambiguity in the original licensing terms of the Pico editor led to the creation of nano. It was first created in 1999 with the name TIP (an acronym for TIP Isn't Pico), by Chris Allegretta. The name was changed to nano on January 10th, 2000 to avoid a naming conflict with the existing Unix utility tip. The name comes from the system of SI prefixes, in which nano is 1000 times larger than pico. In February 2001, nano became a part of the GNU Project. BTW if you want to know more about SI prefixes, I'd highly recommend you to listen to HPR episode 3453 - Engineering notation by Ken Fallon.

nano is really small in footprint and is relatively easy to use compared to Emacs and Vim and perhaps this is the reason why you'd invariably find it already installed on almost all GNU/Linux distributions. If you have ever used nano before you might have noticed that it looks kinda boring; there are no line-numbers nor there is any syntax highlighting and spell-checking also seems absent. But this is not true. nano has all of these features and even some more like regex searches, indentation, multiple buffers, available at its disposal. Then why does it come across as a plain Jane? The short answer is, I honestly don't know! For some unknown and obscure reasons many of nano's cool features are disabled by default. This results in nano coming across as a plain Jane little text editor that is uncool. And as I mentioned earlier, that is not true. But worry not! It is so darn easy to unleash the true potential of nano and make it shine. Are you ready? Great! Let's do it together then!

First thing we need to to do is create a file with the name .nanorc in the $HOME directory. Open your terminal emulator and run,

touch $HOME/.nanorc

We'd also need to create a directory called Nano_Backups in our Documents directory. To do so run the following command,

mkdir -p $HOME/Documents/Nano_Backups

Next open that .nanorc file and simply paste the following content in it,

set atblanks
set autoindent
set backup
set backupdir "/home/USERNAME/Documents/Nano_Backups"
set boldtext
set constantshow
set cutfromcursor
set indicator
set linenumbers
set magic
set minibar
set mouse
set showcursor
set softwrap
set speller "aspell -x -c"
set trimblanks
set whitespace "»·"
set zap
set multibuffer

set titlecolor bold,lightwhite,blue
set promptcolor lightwhite,lightblack
set statuscolor bold,lightwhite,green
set errorcolor bold,lightwhite,red
set spotlightcolor black,lime
set selectedcolor lightwhite,magenta
set stripecolor ,yellow
set scrollercolor cyan
set numbercolor cyan
set keycolor cyan
set functioncolor green

include "/usr/share/nano/*.nanorc"

bind ^Q exit all
bind ^S savefile main
bind ^W writeout main
bind ^O insert main
bind ^H help all
bind ^H exit help
bind ^F whereis all
bind ^G findnext all
bind ^B wherewas all
bind ^D findprevious all
bind ^R replace main
bind ^X cut main
bind ^C copy main
bind ^V paste all
bind ^P location main
bind ^E execute main
bind ^A mark main
unbind ^K main
unbind ^U all
unbind ^N main
unbind ^Y all
unbind M-J main
unbind M-T main
bind ^T gotoline main
bind ^T gotodir browser
bind ^T cutrestoffile execute
bind ^L linter execute
bind M-U undo main
bind M-R redo main
bind ^Z undo main
bind ^Y redo main

You'll have to replace USERNAME in the line number four, set backupdir "/home/USERNAME/Documents/Nano_Backups/" with your actual username and then save this file.

Wouldn't it be nice if the colors in nano were different for a normal user and a root user? Yes, for sure. To do so create an empty .nanorc file in the root's directory,

sudo touch /root/.nanorc

Next create the backup directory Nano_Backups in root's Documents directory. To do so run the following command,

sudo mkdir -p /root/Documents/Nano_Backups

Open that /root/.nanorcfile and paste this content in it and save the changes,

set atblanks
set autoindent
set backup
set backupdir "/root/Documents/Nano_Backups/"
set boldtext
set constantshow
set cutfromcursor
set indicator
set linenumbers
set magic
set minibar
set mouse
set showcursor
set softwrap
set speller "aspell -x -c"
set trimblanks
set whitespace "»·"
set zap
set multibuffer

set titlecolor bold,lightwhite,magenta
set promptcolor black,yellow
set statuscolor bold,lightwhite,magenta
set errorcolor bold,lightwhite,red
set spotlightcolor black,orange
set selectedcolor lightwhite,cyan
set stripecolor ,yellow
set scrollercolor magenta
set numbercolor magenta
set keycolor lightmagenta
set functioncolor magenta

include "/usr/share/nano/*.nanorc"

bind ^Q exit all
bind ^S savefile main
bind ^W writeout main
bind ^O insert main
bind ^H help all
bind ^H exit help
bind ^F whereis all
bind ^G findnext all
bind ^B wherewas all
bind ^D findprevious all
bind ^R replace main
bind ^X cut main
bind ^C copy main
bind ^V paste all
bind ^P location main
bind ^E execute main
bind ^A mark main
unbind ^K main
unbind ^U all
unbind ^N main
unbind ^Y all
unbind M-J main
unbind M-T main
bind ^T gotoline main
bind ^T gotodir browser
bind ^T cutrestoffile execute
bind ^L linter execute
bind M-U undo main
bind M-R redo main
bind ^Z undo main
bind ^Y redo main

What we have just done is, we have enabled some useful features of nano and changed the default keybindings to the more familiar ones like Ctrl+C for copying, Ctrl+X for cutting, Ctrl+V for pasting and a bunch of other key combinations. We've also enabled automatic backing-up of documents. Backups will get saved in the user's Documents/Nano_Backups directory.

Spell checker is enabled in nano via this configuration but to utilize it you'll have to install aspell and aspell-dictionary from your package manager.

Kudos! We have turned a timid GNU nano into a powerful wildebeest. Try this configuration and if possible leave your feedback.

A word of warning. Package maintainers often ship stripped down versions of nano so one of these features might not be present in your installation and in that case, nano will throw some errors and refuse to start. You have two choices in that scenario; first, disable that feature by deleting the corresponding line from .nanorc file. Your second option is to download the nano source code and compile it yourself with all the features intact. If I were you, I'd go with the second option as compiling nano is really simple and straightforward. Only extra packages that you will need are libncurses-dev and libmagic-dev.

I'll leave you guys with a quote from some wise man,

Good Things Come in Small Packages.


Comments

Subscribe to the comments RSS feed.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?