I use the Nano text editor for command line work. The version installed by Apple (2.0.6) is well behind the curve; use Brew to supersede it with the latest version (5.x at the time of editing).
If you don’t have Homebrew installed, get the install string from brew.sh. Then run
brew install nano. I also set up an alias in my
.zshrc file to ensure the correct version gets used:
Update If you’re using Nano on an Apple Silicon Mac, your alias should read:
Even then, Nano doesn’t quite sing, but by tweaking its startup file,
.nanorc, which you’ll find in your home directory, you can make it much more tuneful.
set tabsize 4 set tabstospaces set autoindent set trimblanks set linenumbers set constantshow set titlecolor white,red set keycolor cyan set functioncolor cyan set numbercolor yellow set mouse include /usr/local/share/nano/*.nanorc
The first three lines are self-explanatory; I have them to force the use of spaces instead of tabs, and four spaces per tab. The fourth option,
trimblanks, removes unecessary end-of-line whitespace when you save a file. These are vital for coding.
constantshow keeps the line count panel on screen. The four
…color settings — formatted
<foreground colour>,<background colour> — refer respectively to the title bar at the top of the editor screen; the list of key combinations and their meanings, at the bottom of the editing screen; and the colour of the line numbers. These are nice-to-have settings, but not essential.
Available names for the foreground and background colour include
normal — the latter is the default foreground or background colour. The name of the foreground colour may be prefixed with
The last two lines are important.
mouse allows you to position the cursor with the mouse — handy if you have a long file to get through. It can save a lot of scrolling or paging.
include line makes use of 44 files installed in
.nanorc files themselves. Each file contains a list of regular expressions which Nano uses to colour key words when it opens files of the type(s) indicated by the file, so they can be readily used to create new files for new languages.
You can omit the final line on a Raspberry Pi as Nano is already set up for you, but otherwise you’re good to add or update your own
~/.nanorc file with the suggestions above. I have versions for each platform in my dotfiles repo and scripts to copy the correct version to my Mac or Pi home directory.
You can look up more
.nanorc settings in the Nano documentation.