Getting started with Nano Editor

If you are new to Linux you may have seen mention of the nano editor. Linux amateurs are often put off by other terminal based advanced text editors such as Vim and Emacs so they turn to Nano while not as powerful, it is a much easier and simpler to use for the casual user.

What is Nano Text Editor?

Nano is a text editor for Unix-like systems or any other environments using a command line interface. It emulates the Pico text editor, a part of the Pine email client, which also provides additional functionality. In contrast to Pico, Nano is licensed under the GNU General Public License (GPL). Long time computer users may find it's interface similar to the old DOS Wordstar Word processor.

Starting Nano

Nano follows the path and opens the file if it exists. However, If it does not exist, it’ll start a new buffer with that filename in a directory. To run Nano Text editor, use the following command:

$ nano
nano testfile

Once started, the terminal window should look like this if opened with no file:

Nano screen

Keyboard Shortcuts of Nano Editor

Nano editor “commands” are commonly referred to as “shortcuts” such as read file, save file, close file etc. The most common commands are placed at the bottom of the screen, but there are many more. All shortcuts use lowercase letters and unmodified number keys and use the [Ctrl] key plus a letter or a Function key.

To see a list of valid shortcuts press [Ctrl+G] on your Keyboard, the output should be like this:

Nano help screen

When you are finished looking at shortcuts, hit the [Ctrl+X] to exit the help window.

Common Commands

Suppose, you are working on a new text file and you want to save it, this is called “writing out” [Ctrl+O]. The output window should be similar to this:

Nano save screen

Note the line above the commands. At this point you just press [Enter] to save the file.

If you want to mark any text hit [Ctrl+^] shortcut key and use the arrow keys to mark text like this:

Nano marking text screen

At this point you can cut the text [Ctril+K] and then paste [Ctrl+U] somewhere else:

Nano cutting and pasting text screen

Additional Productive Shortcuts

The below are a list of shortcuts which can ease your work and make you more productive with Nano:

[CTRL + A] - Move to beginning of line
[CTRL + E] - Move to end of line
[CTRL + Y] - Move down a page
[CTRL + V] - Move up a page
[CTRL + _] - Move to a specific line
[CTRL + C] - Find out what line the cursor is currently on
[CTRL + V] - Move up a page
[CTRL + W] - Search for some text
[CTRL + D] - Delete the character currently under the cursor
[CTRL + K] - Delete entire line
[CTRL + ] - Replace a string of character
[CTRL + O] - Save the content without exiting
[CTRL + T] - When saving a file opens a browser that allows you to select a file name from a list of files and directories

To exit Nano use the [Ctrl + X] shortcut to return to the command prompt.

Congratulations! Hope you perfect these basics of Nano text editor.

Go Back To Blog.