How to use nano

Here is the second of my next guides, this time on how to use nano,

nano is another text editor contained in ESX and is easier to use than VI as it uses some recognisable keyboard shortcuts,  this is a very concise overview and if you want fuller documentation head on over to:

Opening and creating files

Opening and creating files is simple in nano, simply type:

nano filename

Nano is a modeless editor so unlike vi where you have to enter insert mode, you can start typing immediately to insert text. If you are editing a configuration file like /etc/fstab use the -w switch, for example:

nano -w /etc/fstab

Warning: It is very, very important that you use the -w switch when opening a config file. Failure to do so may keep your system from booting or cause other bad things.

Saving and exiting

When you want to save the changes you’ve made, press Ctrl+O.(hold down Ctrl and then press O, this seems easier to remember already 😀 )

To exit nano, type Ctrl+X.

When you ask nano to exit from a modified file you have not saved, it will attempt to save your from your self,  don’t shout at it, be nice and either press N, if you don’t want to save it, or Y in case you do.

It will then ask you for a filename. Just type it in and press Enter.

If you cocked up and “accidentally” confirmed that you want to save the file but, you suddenly remembered you don’t, don’t worry, you can always cancel, thus saving your embarrassment by pressing Ctrl+C when you’re prompted for a filename.

Cutting and pasting

To cut a single line, you use Ctrl+K. The line disappears.

To paste a line, you simply move the cursor to where you want to paste it and punch Ctrl+U. The line reappears.

To move multiple lines, simply cut them with several consecutive Ctrl+Ks in a row, then paste them with a single Ctrl+U. The whole paragraph appears wherever you want it.  What could be simpler, well quite a lot, but I am comparing this to vi.

If you need to be a little more fine-grained with your control, then you have to mark the text. Move the cursor to the beginning of the text you want to cut. Press Ctrl+6 (or bizarrely Alt+A haven’t got a clue where that one came from).

Now move your cursor to the end of the text you want to cut, the marked text gets highlighted.

If you make a mistake on your highlighting and need to cancel your text marking, simply hit Ctrl+6 or if you really want to Alt + A again. Press, yep you remembered Ctrl+K to cut the marked text and Ctrl+U to paste it in the desired location.

Searching for text

Searching for a string is easy as long as you think Where Is instead of Search . Simply hit Ctrl+W, type in your search string, and press Enter . To search for the same string again, hit Alt+W .
Note: In nano’s help texts the Ctrl-key is represented by a caret (this is the little tophat key ^), so Ctrl+W is shown as ^W, and so on. The Alt-key is represented by an M (from the Latin Meta in case you are wondering), therefore Alt+W will be shown as M-W.

More options

If you’re interested in getting deep down and personal with nano, be sure to read /etc/nanorc.

%d bloggers like this: