Networking | Programming | Security | Linux | Computer Science | About

Linux Editor Comparison

Various Linux programs will run an editor when necessary, and usually the default editor is nano or vim. For example, your email program may invoke an editor to compose a new mes‐sage, and less invokes an editor if you type “v”. But what if you want a different default editor?

Setting your default editor

Set the environment variables VISUAL and EDITOR to your choice, for example:


Both variables are necessary because different programs check one variable or the other. Set EDITOR and VISUAL in your ~/.bash_profile startup file if you want your choices made permanent. Any program can be made your default editor as long as it accepts a filename as an argument.

Regardless of how you set these variables, all users should know at least basic commands for each editor in case another program suddenly runs an editor on a critical file.


nano [options] [files]

Nano is a text editor with basic features. It’s included by default in many Linux distros, whereas more powerful editors like emacs and vim might not be. To invoke nano, type


Nano commands generally involve holding down the control key and typing a letter, such as o to save and x to quit. Nano helpfully displays common commands at the bottom of its edit window, though some of the vocabulary is a little obscure. (For example, nano uses the term “WriteOut” to mean “save file.”) Other commands involve the meta key, which is usually the Escape key or the Alt key. Nano’s own documentation notates the meta key as M- (as in M-F to mean “use the meta key and type F”), so we will too.

For basic keystrokes, see the table below. For more documentation, visit .


emacs [options] [files]

emacs is an extremely powerful editing environment with thousands of commands, plus a complete programming language to define your own editing features. To invoke emacs in a new X window, run:


To run in a existing shell window:

emacs -nw

Now to invoke the built-in emacs tutorial, type h t. Most emacs keystroke commands involve the control key (like F) or the meta key, which is usually the Escape key or the Alt key. emacs’s own documentation notates the meta key as M- (as in M-F to mean “use the meta key and type F”), so we will too. For basic keystrokes, see the table below.


vim [options] [files]

vim is an enhanced version of the old standard Unix editor vi. To invoke the editor in a new X window, run: →


To run in a existing shell window:


To run the vim tutorial, run:


vim is a mode-based editor. It operates usually in two modes, insert and command, and you must switch between them while editing. Insert mode is for entering text in the usual manner, while command mode is for deleting text, copy/paste, and other operations. For basic keystrokes in normal mode, see the table below.

Basic keystrokes for nano, vi and emacs

Task emacs nano vim
Type text Just type Just type Switch to insert mode if necessary, by typing i, then type any text
Save and quit x s then x c o then x :wq
Quit without saving x c Respond “no” when asked to save buffers ^x Respond “no” when asked to when asked to save :q!
Save x s ^o :w
Save As x w ^o, then type a filename :w filename
Undo / or x u M-u u
Suspend editor (not in X) ^z ^z ^z
Switch to insert mode (N/A) (N/A) i
Switch to command mode (N/A) (N/A) ESC
Switch to command-line mode M-x (N/A) :
Abort command in progress ^g ^c ESC
Move forward ^f or right arrow ^f or right arrow l or right arrow
Move backward ^b or left arrow ^b or left arrow h or left arrow
Move up ^p or up arrow ^p or up arrow k or up arrow
Move down ^n or down arrow ^n or down arrow j or down arrow
Move to next word M-f ^SPACEBAR w
Move to previous word M-b M-SPACEBAR b
Move to beginning of line ^a ^a 0
Move to end of line ^e ^e $
Move down one screen ^v ^v ^f
Move up one screen M-v ^y ^b
Move to beginning of document M-< M-/ G
Move to end of document M-> M-\ G
Delete next character ^d ^d x
Delete previous character BACKSPACE BACKSPACE X
Delete next word M-d (N/A) de
Delete previous word M-BACKSPACE (N/A) db
Delete current line a k ^k dd
Delete to end of line ^k D
Define region (type this keystroke to mark the beginning of the region, then move the cursor to the end of the desired region) ^SPACEBAR (control caret) v
Cut region ^w ^k d
Copy region M-w M-^ y
Paste region ^y ^u p
Get help ^h ^g :help
View the manual ^h i ^g :help

Published on Thu 24 December 2009 by Harry Paignton in Linux with tag(s): linux nano emacs vim