Text editors in Linux: nano and vim

Updated November 1, 2026

nano and vim are text editors right in the terminal; nano is easier to start with, vim is on almost every machine.

Common cases

nano file.txt        # open a file in nano
# in nano:  Ctrl+O save, Ctrl+X quit
vim file.txt         # open a file in vim
# in vim:   i insert, Esc back, :w save, :q quit, :wq both
vim -R file.txt      # read-only

Sample output

$ vim site.conf
server {
  listen 80;
  root /var/www/html;
}
~
~
~
~
~
"site.conf" 4L, 46B                                         1,1           All

How it works: vim's modes and how to quit

nano works like a familiar editor: open it, type, and the hints at the bottom use Ctrl. vim is built around modes, and that trips people up. When it opens you are in normal mode: letters are commands, not text. Press i to start typing, and Esc to go back. The most common question is how to quit: press Esc, then type :q and Enter (or :q! to quit without saving, :wq to save and quit). If the editor is unfamiliar, use nano.

Common mistakes

In vim you start in normal mode, and letters there are commands. Type the word hello out of habit: h, e, l, l move the cursor, and o opens a new empty line and switches to insert. The file now has a line you never asked for. u in normal mode undoes the last change.

You may have no write permission, and the editor does not say so right away. vim /etc/hosts opens, the bottom line reads "/etc/hosts" [readonly] 7L, 175B, the first edit brings W10: Warning: Changing a readonly file, :w answers E45: 'readonly' option is set (add ! to override), and :w! answers E212: Can't open file for writing. On the same file nano says [ File '/etc/hosts' is unwritable ] on open and [ Error writing /etc/hosts: Permission denied ] on save. Edit such files through sudo.

Neither editor lets unsaved edits vanish quietly, but they ask about it differently. nano shows Save modified buffer? on Ctrl+X and waits for Y or N. vim refuses to leave on :q and prints E37: No write since last change (add ! to override). That exclamation mark at the end of a vim command means 'yes, I know the edits go away'.

In the book

This topic is covered in full in the chapter Reading and editing text.

See also

cat, head, tail, The less pager.