Nano text editor with syntax colouring and more

Apple Silicon macs

Install the latest version of nano via homebrew and set up an alias in my .zshrc file to ensure the correct version gets used

brew install nano
alias nano='/opt/homebrew/bin/nano'

Create a .nanorc file in ~ and add some variables. This is my file below.

set autoindent
set constantshow
set functioncolor green
set keycolor green
set linenumbers
set mouse
set numbercolor green
set tabsize 4
set tabstospaces
set titlecolor white,green
set trimblanks

# Apple Silicon macs
include /opt/homebrew/share/nano/*.nanorc

# Linux
# include /usr/share/nano/*.nanorc

Most of the lines are self-explanatory, trimblanks, removes unnecessary 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 , — 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 white, black, blue, green, red, cyan, yellow, magenta and normal — the latter is the default foreground or background colour. The name of the foreground colour may be prefixed with bright.

Set mouse allows you to position the cursor with the mouse, this is handy if you have a long file to get through. It can save a lot of scrolling or paging.

The include line makes use of 44 files installed in /usr/local/share/nano that provide syntax highlighting for a range of languages, including CSS, HTML, JavaScript, JSON, C, Objective-C, PHP, Python, Rust, Ruby, Shell and even .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 look up more .nanorc settings in the Nano documentation.