VIM - VI Improved Guide

External Resources

Table of Contents

The following is compiled from the above entries, primarily the "Command Sheet from"

Keyword Completion

Vim can do keyword completion, by looking in your file. Just start typing, and then Ctrl + n


:e myfile.txtEdit myfile.txt
:e! myfile.txtEdit myfile.txt discarding current buffer
gfGo to file whose name is under the cursor

Save, Suspend, and Exit

:st or Ctrl + zSuspend to Command line, bring back with fg
:q!quit without writing
:wawrite all
:wqwrite and quit
:wq myfile.txtwrite buffer to myfile.txt and quit
Ctrl + gDisplay Information about the file

Insert and Append

aappend text after the cursor [count] times
Aappend text at the end of the line [count] times
iinsert text before the cursor [count] times
Iinsert text at the beginning of the line (after indenting) [count] times
obegin a new line below the cursor and insert text [count] times
Obegin a new line above the cursor and insert text [count] times
r myfile.txtread myfile.txt and insert its content below the cursor
r !lsread the output from commandline command ls and insert its standard output below the cursor


xdelete at the cursor [count] chars
Xdelete before the cursor [count] chars
d[motion]delete the chars that the motion moves over
dddelete the current line
Ddelete from the cursor to the end of the line
:[range]ddelete range lines
:[range]d [count]delete count lines from range


Rlike insert mode, but replace chars instead of inserting
~change case - can add count or motion
JJoin (append) the following line to the end of this one

Copy and Paste

:regdisplay the contents of all named registers
:reg [x]display the contents of register with name x. Reg names reserved for the user are one lowercase letter
"[reg name]y[motion]yank count chars covered by motion into register with name "reg name"
"[reg name]yyyank count lines
"[reg name][count]pPaste from register "reg name" count times
"[reg name][count]pPaste from the register "reg name" before the cursor count times

Visual Mode

vselect characters
Vselect lines
~, d, c, y, <, >, !After selecting lines with above, run these commands: case, delete, change, yank, shift right, shift left, filter through external command

Undo and Redo

Ctrl + rredo


hMove left
jMove down
kMove up
lMove right
0Move to the begining of the line
^Move to the first not blank on the line
$Move to the end of the line
wMove to next word
WMove to next blank delimited word
bMove to the beginning of the word
BMove to the beginning of blank delimted word
eMove to the end of the word
EMove to the end of Blank delimited word
(Move a sentence back
)Move a sentence forward
{Move a paragraph back
}Move a paragraph forward
1GMove to the first line of the file
GMove to the last line of the file
nGMove to nth line of the file
:nMove to nth line of the file
fcMove forward to c
FcMove back to c
HMove to top of screen
MMove to middle of screen
LMove to bottom of screen
%Move to associated ( ), { }, [ ]
;repeat last f/F count times forward
,repeat last f/F count times backward
-count lines upward
+count lines downward
HGo to top of the Screen
MGo to the middle of the Screen
LGo to the bottom of the Screen
ztput this line on the top of the screen
zzput this line in the middle of the screen
zbput this line at the bottom of the screen
gdGo to the definition of the var or function under the cursor
Ctrl+fScroll forward one screen
Ctrl+bScroll back one screen
Ctrl+dScroll down one half screen
Ctrl+uScroll up one half screen


*Search for the word under the cursor
/[pattern]Search for pattern
/[pattern]/[offset]Search for pattern and go x lines up or down
?[pattern]Search backward
nrepeat search
Nrepeat search in opposite direction
[range]s/[pattern]/[replaceWString]/optionsReplace pattern with string with sub options:
  • c - confirm each sub
  • e - continue on error
  • g - replace all occurences
  • i - ignore case
  • I - case sensitive
  • p - print the line for the last substitute


:buffers or :lslist buffers
:buffer 2Edit buffer 2
:buffer snippetEdit buffer which has snippet in its name
:sbuffer 3Open buffer 3 in a new window
:bnextnext buffer
:bpreviousprevious buffer
:bfirstfirst buffer
:blastlast buffer

Split Screen (Window)

Ctrl + w, vsplit vertically
Ctrl + w, ssplit horizontally
Ctrl + w, cclose this window
Ctrl + w, [h, j, k, l]move to the window in the given direction
Ctrl + w, wmove to next window counter-clockwise (W for clockwise)
Ctrl + w, pgoto previous window
Ctrl + w, tgoto top left window
Ctrl + w, bgoto bottom right window
Ctrl + w, rrotate the windows
Ctrl + w, TMove the window to a new tab
Ctrl + w, oMake this window the only window
:lcdchange the directory for this window only.


:tabnewnew tab
:tabe [file]edit file in a new tab
:tabcclose tab
:taboclose the other tabs
:tabslist the tabs and their windows
:tabnnext tab
:tabpprevious tab
:tabfirfirst tab
:tabllast tab
:tabm 3move the current tab after tab num


:scriptnameslist all plugins