Nano Text Editor and nanorc Tips and Tricks

Nano is easy to use and lightweight command line text editor for Linux and UNIX systems. Nano text editor can use either the default settings or improve settings with customized nanorc-file. Here are some tips that can improve the usability of Nano. Changes can be made to nanorc file, either locally or to all users or options can be used as command line options.

First is good to check Nano compiled options, with command:

nano -V

Nano should be compiled with –enable-nanorc option.

Example configuration file can be copied from /usr/share/doc/nano-[version]/nanorc.sample. If you want to add the settings to all users, then copy nanorc to the /etc/nanorc and if you want to add the settings locally to one user then copy nanorc to the $HOME/.nanorc.

You can also do your own syntax highlighting files easily. For example, the following code change the comment lines to blue:

syntax "comments" ".*"
color blue "^#.*"

And you can also use syntax highlighting files from the Internet. Here you can find example php.nanorc (PHP) and js.nanorc (JavaScript) file:php.nanorcjs.nanorc
And then just copy files example to “/usr/share/nano/php.nanorc” and “/usr/share/nano/js.nanorc”
And enable PHP and JavaScript syntax highlighting files with:

12. Read Only Mode / View Only Mode

13. Enable Mouse

Enable the use of the mouse. Good if you move the mouse to point to another on text file, and not so useful if you need to cut or copy text. You can of course cut and paste with Ctrl+k and Ctrl+u.
nanorc row:

set mouse

command line option:

-m or --mouse

14. Other Options

Here is only my favourit options and you might need some other options, so then it’s better check Nano help or manual pages.
command line: