This tutorial explains about nanorc file with examples.

.nanorc file is used to store the user-customized configuration and settings required for the nano editor. It contains customized behavior of nano such as indentation, line wrap, settings, and syntax formatting.

The location of .nanorc file is in the

  • /home/user/.nanorc or ~/.nanorc in Linux, Unix, and Mac
  • c:\users\user\.nanorc in Windows

This file loads by nano editor at startup and configure default settings.

Any feature can be enabled by adding a line with set or unset in .nanorc file.

nanorc file settings

Following are some settings configured

To disable line wrapping:

set nowrap

To disable syntax highlighting:

Syntax directive tells to enable or disable. color to define a single syntax color

set quiet
syntax "disabled" "." or syntax "" ""
color gree black "."

Disable confirm on save:

By default, modifying a file shows you to save the modified buffer prompt when closing the file,

For nano versions greater than 5.0

set saveonexit

For nano versions less than 5.0

set tempfile

It says don’t show prompts to save the file when closing. It can also be enabled with command line arguments -t. ie nano -t command

tab size change spaces

By default, the tab size is 8 white spaces. If you want to change the spaces permanently

set tabsize 8
set tabstospaces

It changes white spaces from 8 to 4 for tab space.

This makes the tab character 4 spaces instead of 8 spaces.

  • Mouse support To get mouse clicks to work in the nano editor, One way, change the below settings in the .nanorc file
set mouse

or open the editor with the nano -m option

Nano editor configuration examples

The following page shows a list of all settings required in the Nano Editor.

ShortcutDescription
set tabsize nchange tab size with n spaces
set autoindentAutomatic indentation
set smoothconfigure Smooth scrolling
set linenumbersShow line numbers
set tabstospaceschange tab to spaces
set mousechange to mouse
set nonewlinesNew lines are not added to the end of the file
set nowrapNo lines wrap
set nohelpNo Help option shown
set casesensitiveCase sensitive search