Which is the best command line text editor?
Seriously, i don't know!


In my opinion, the best choice depends by the context: undoubtedly EMACS is the most complex and comprehensive, and VIM is the right balance between features and simplicity.

But, also a simple editor such as nano could be a great tool for developers!
So, in this post i try to list the main commands for this editor, but first a little bit of story...

source: https://xkcd.com/378/[/caption]


What is GNU nano?

GNU nano is a command line text editor for *nix systems that emulates the Pico text editor, part of the Pine email client but, unlike Pico, is licensed under the GNU General Public License (GPL).

GNU nano was first created in 1999 by Chris Allegretta, with the name TIP (TIP Isn't Pico) and implements several features that Pico lacks, including syntax highlighting, line numbers, regular expression search and replace, line-by-line scrolling, multiple buffers, indenting groups of lines, rebindable key support, and the undoing and redoing of edit changes.

The name was changed to nano on 10 January 2000 to avoid a naming conflict with the existing Unix utility tip and, in February 2001, nano became a part of the GNU Project.


The cheatsheet

File Control

Open or create the file “app.py”:

nano app.py

Save changes:

Ctrl-o Y Enter

Open a new file with a new buffer:

Ctrl-r Alt-f

Switch to the next file buffer:

Alt->

Switch to the previous file buffer:

Alt-<

Quit nano:

Ctrl-x
Content navigation

Move to the beginning of the current line:

Ctrl-a

Move to the end of the current line:

Ctrl-e

Move down one page:

Ctrl-v

Move up one page:

Ctrl-y

Go to the beginning of the file:

Alt-\

Go to the end of the file:

Alt-/

Go to a line number:

Alt-g

Jump to matching open/close symbol:

Alt-]

Select a block and indent the block:

Alt-a Alt-}

Select a block and unindent the block:

Alt-a Alt-{
Cut, Copy and Paste

To select a block for copy or cut operation, do Alt-a again to unselect:

Alt-a

Copy a highlighted block to the clipboard:

Alt-a Alt-^

Cut a highlighted block to the clipboard:

Alt-a Ctrl-k

Cut from the current cursor position to the end of the current line:

Ctrl-k

Paste the contents from the clipboard at the current cursor position:

Ctrl-u
Search and Replace

Search for a string:

Ctrl-w

Repeat the last search:

Alt-w

Search and replace:

Alt-r

 


References and further reading