This is an old revision of the document!
Table of Contents
Vi / Vim
Open Files, save and exit
$ vi file # open file :w # save (write) :wq # save and quit :x # abbreviation of wq :q! # quit without save
Grammar
Navigation
h # cursor left
j # cursor down
k # cursor up
l # cursor right
0 # (zero) move to beginning of the line
$ # move to the end of the line
w # move to the beginning of the next word
} # skip to next section
H # Jump to the beginning of the displayed screen
M # Jump to the center of the displayed screen
L # Jump to the bottommost line shown
CTRL-f # Jump down one Page
CTRL-b # Jump up one Page
CTRL-d # Jump down halve a page
CTRL-u # Jump up halve a page
gj # For very long lines that wrap at the screen edge, jump up one line.
gk # For very long lines that wrap at the screen edge, jump down one line.
% # Jump to the next bracket character (){}[]
Edit
i # insert at cursor position a # add after cursor position o # insert a line below O # insert a line above 12i <character> # write the same character 12 times ( type eight zero i dash <ESC> results in ------------) y # yank text (copy) d # delete dt' # delete everything to the character ' df' # delete everything including character ' c # copy line y$ # copy to the end of the line (yank) y5l # yank five Characters from the cursor position to the right yt( # copy everything to the round bracket d2w # delete two words c2j # change the next two lines :undo or u :redo or CTRL-R
complex editing
commenting 1
CTRL-q Cursor turns gray as soon you move the cursor keys (or hjkl). Mark everything you want comment SHIFT-i press Shift Key and i # type '#' ESC Press ESC
commenting 2
Add '# ' in the beginning of line 5 to 12
:5,12s/^/# /
uncomment 1
CTRL-q Mark everything you want to remove q press q
uncomment 2
remove '# ' from the beginning of line 5 to 12
:5,12s/^# //