Vim has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC]
returns the editor to command mode (where you can quit, for example by typing :q!
). Most commands execute as soon as you type them except for "colon" commands which execute when you press the ruturn key.
:x
Exit, saving changes:q
Exit as long as there have been no changesZZ
Exit and save changes if any have been made:q!
Exit and ignore any changes
i
Insert before cursorI
Insert before linea
Append after cursorA
Append after lineo
Open a new line after current lineO
Open a new line before current liner
Replace one characterR
Replace many characters
h
Move leftj
Move downk
Move upl
Move rightw
Move to next wordW
Move to next blank delimited wordb
Move to the beginning of the wordB
Move to the beginning of blank delimted worde
Move to the end of the wordE
Move to the end of Blank delimited word(
Move a sentence back)
Move a sentence forward{
Move a paragraph back}
Move a paragraph forward0
Move to the begining of the lineH
Move to top of screenM
Move to middle of screenL
Move to botton of screen%
Move to associated ( ), { }, [ ]
/str
Search forward for string?str
Search back for stringn
Search for next instance of stringN
Search for previous instance of string
Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:
x
Delete character to the right of cursorX
Delete character to the left of cursorD
Delete to the end of the linedd
Delete current line:d
Delete current line
The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).
:s/pattern/string/flags
Replace pattern with string according to flags. (Example::%s/foo/bar/
. Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.)g
Flag - Replace all occurrences of patternc
Flag - Confirm replaces.&
Repeat last :s command
:w file
Write to file:r file
Read file in after line:n
Go to next file:p
Go to previos file:e file
Edit file!!program
Replace line with output from program
~
Toggle upp and lower caseJ
Join lines.
Repeat last text-changing commandu
Undo last changeU
Undo all changes to line
Here's some key shortcut I use a lot with:
<C-^>
switch current buffer with an alternative onezi
toggle fold/unfold of current buffergd
jump to definitionzz
make current line center of the screen