Some Useful GNU nano Settings

The GNU nano is a superb Linux text editor. And you absolutely should use it. It’s not a fully-featured IDE nor does it claim to be.

If you’re looking for a fast, lightweight editor that is usually installed by default (or available in the standard repos of every distro) then you should take a look at nano.

I use nano for all my processional Linux administration and content creation. With a few tweaks you can turn nano into a capable editor that will meet your everyday needs.

nano has been around and in active development for a very long time. This means that the common knowledge around nano that you will see on forms is now incorrect. The most common one is the save and exit key sequence as modern nano now uses CTRL+S for save and CTRL+x for exit. These, and many more key binding can be set in the nanorc file.

nano’s Features

Spell Checking - nano will spell check as long as you have the GNU Aspell package installed and enable it with the spelling options enabled. These are shown below. Invoke spell checking with F12.

Syntax Highlighting - nano is usually installed with some syntax highlighting files. You can find may more on user scopatz Github account here. Just copy the one you need and paste it into a new file under /usr/share/nano/.

Undo - nano has an undo history that you can access with ALT+u.

nanorc

nano’s system config file is located at /etc/.nanorc. You can override these settings with a user specific config file at ~/.nanorc.

Consult man nanorc for a complete list of options.

The following is my ~/.nanorc file with annotations. I have included one without annotation at the end of this file.

# Non-default settings
set atblanks        # wrap line at blanks.
set cutfromcursor   # CTRL+K cuts from cursor position to end of line.
set nohelp          # Disable the help information (CTRL+G to view the help screen).
set softwrap        # Enable softwrap of lines.
set suspend         # Enables CTRL+Z to suspend nano.
set tabsize 4       # Sets tab-to-spaces size to 4.
set tabstospaces    # Converts TAB key press to spaces.
include "/usr/share/nano/*.nanorc" # Enables the syntax highlighting.
set speller "aspell -x -c"         # Sets what spelling utility to use.
set constantshow    # Displays useful information e.g. line number and position in the bottom bar.
set linenumbers     # Lines are numbered.
set casesensitive   # Case insensitive search.
set historylog      # Save the last 100 history searches for later use.
set positionlog     # Saves the cursor position between editing sessions.
set zap             # Allows you to highlight text (CTRL+SHIFT+ARROW) and delete it with backspace.
set autoindent      # A new line will have the same number of leading spaces as the previous one.
set indicator       # Displays a scroll bar on the right that shows the position and size of the current view port.
set minibar         # Displays file name and other information in the bottom bar. Removes top bar.

# Enable and set a working backup directory
set backup                              # Creates backups of your current file.
set backupdir "~/.cache/nano/backups/"  # The location of the backups.

# Shortcut key bindings
bind ^C copy main       # CTRC+C - Copy
bind ^V paste all       # CTRL+V - Past
bind ^F whereis all     # CTRL+F - Find
bind ^S savefile main   # CTRL+S - Save 

The same nanorc file without annotation

set atblanks
set cutfromcursor
set nohelp
set softwrap
set suspend
set tabsize 4
set tabstospaces
include "/usr/share/nano/*.nanorc"
set speller "aspell -x -c"
set constantshow
set linenumbers
set casesensitive
set historylog
set positionlog
set zap
set autoindent
set indicator
set minibar

set backup
set backupdir "~/.cache/nano/backups/"

bind ^C copy main       # CTRC+C - Copy
bind ^V paste all       # CTRL+V - Past
bind ^F whereis all     # CTRL+F - Find
bind ^S savefile main   # CTRL+S - Save