Editor's note (2026): We've corrected several commands in this 2014 tutorial (searching, deleting to the end of a line, and saving were described incorrectly).
The vi editor is installed on almost every Linux and Unix system, and vim ("Vi IMproved") is its more powerful successor. Many people prefer the simpler nano, but vi/vim has far more features once you learn the basics.
Opening a file
vim filename
This opens filename, or creates it if it doesn't exist. (vi filename works too.)
Two main modes
- Normal (command) mode: move the cursor, delete, copy, and run commands. Vim starts in this mode.
- Insert mode: type text like any other editor.
Press i to enter insert mode and type. Press Esc to return to normal mode.
Moving the cursor (normal mode)
Arrow keys work in vim, but the classic keys are:
h— leftj— downk— upl— right
Deleting and undoing (normal mode)
| Command | Action |
|---|---|
x |
Delete the character under the cursor |
X |
Delete the character before the cursor |
4x |
Delete 4 characters |
dw |
Delete a word |
3dw |
Delete three words |
dd |
Delete the whole line |
2dd |
Delete two lines |
D |
Delete from the cursor to the end of the line |
u |
Undo the last change |
Ctrl+r |
Redo |
U |
Undo all changes on the current line |
Searching
In normal mode, type / followed by your keyword and press Enter, for example /keyword. Press n to jump to the next match and N for the previous one.
Saving and quitting
From normal mode (press Esc first):
| Command | Action |
|---|---|
:w then Enter |
Save |
:wq then Enter (or ZZ) |
Save and quit |
:q then Enter |
Quit (only if there are no unsaved changes) |
:q! then Enter |
Quit without saving |
These aren't all of vim's commands, but they're enough to edit files comfortably. For a guided practice session, type vimtutor in your terminal.
Need help managing Linux servers or systems? I.T. For Less can help — contact us.