Summary of most useful commands
Entering command mode
||Exit editing mode. Keyboard keys now interpreted as commands.
Moving the cursor
||(or left arrow key) move the cursor left.
||(or right arrow key) move the cursor right.
||(or down arrow key) move the cursor down.
||(or up arrow key) move the cursor up.
||move the cursor one page forward .
||move the cursor one page backward.
||move cursor to the first non-white character in the current line.
||move the cursor to the end of the current line.
||go to the last line in the file.
||go to line number n.
||display the name of the current file and the cursor position in it.
Entering editing mode
||insert new text before the cursor.
||append new text after the cursor.
||start to edit a new line after the current one.
||start to edit a new line before the current one.
Replacing characters, lines and words
||replace the current character (does not enter edit mode).
||enter edit mode and substitute the current character by several ones.
||enter edit mode and change the word after the cursor.
||enter edit mode and change the rest of the line after the cursor.
Copying and pasting
||copy (yank) the current line to the copy/paste buffer.
||paste the copy/paste buffer after the current line.
||Paste the copy/paste buffer before the current line.
Deleting characters, words and lines
All deleted characters, words and lines are copied to the copy/paste buffer.
||delete the character at the cursor location.
||delete the current word.
||delete the remainder of the line after the cursor.
||delete the current line.
||repeat the last insertion, replacement or delete command.
Looking for strings
||find the first occurrence of string after the cursor.
||find the first occurrence of string before the cursor.
||find the next occurrence in the last search.
Can also be done manually, searching and replacing once, and then using n (next occurrence) and . (repeat last edit).
||between line numbers n and p, substitute all (g: global) occurrences of str1 by str2.
||in the whole file ($: last line), substitute all occurrences of str1 by str2.
Applying a command several times – Examples
||move the cursor 5 lines down.
||delete 30 lines.
||change 4 words from the cursor.
||go to the first line in the file.
||redraw the screen.
||join the current line with the next one
Exiting and saving
||save current file and exit vi.
||write (save) to the current file.
||write (save) to the file file.
||quit vi without saving changes.
vi has much more flexibility and many
more commands for power users!
It can make you extremely productive
in editing and creating text.
Learn more by taking the quick tutorial:
just type vimtutor.