Follow is the vi/vim commands I most use:
Command | Mode | Description |
vi filename | default | start editing a file |
:wq | command | write to disk and quit ( equal to :x) |
:q! | command | quit without saving any changes |
:e! | command | recover to the original without any changes |
:!command | command | execute a command; :!sh fork a shell, Ctrl-d to exit |
h; l; k; j | default | one space to the left, right; one line up, down respectively |
^; $ | default | the beginning or end of current line |
w; e | default | the beginning or end of next word |
Ctrl-b; Ctrl-f | default | one page up (backward) or down (forward) |
:number | command | move line with the number |
Ctrl-L | command | clear and redraw the screen |
G | default | move to the end of file |
/string; n | default | search string and repeat search (next) |
a; A | default | append from next letter or the end of current line |
i; I | default | insert from current position or the beginning of current line |
o; O | default | open new line down or up of current line |
x | default | delete single character; 5x deletes 5 characters |
dw; dd | default | delete word or linde; 5dw deletes 5 words and 5dd deletes 5 lines |
yy | default | yank (copy) into buffer; 5yy copies 5 lines into buffer |
p; P | default | paste buffer to next or previous line |
u; U | default | undo last change or restore the current line |
:set num; :set nonum | command | turn on or off line numbering |
:set ic; set noic | command | ignore (or not ignore) case when searching |
ma; :'a; y'a; d'a | default command | set marker 'a' (could be 'a' to 'z') to the current position, go to marker 'a', copy text from current position to marker 'a' into buffer, delete text from current position to marker 'a' |
:%g/^#/d; :%s/^#//g | command | delete all comment lines or uncomment all the comment lines |
:[10-20]g/hello/d; :[10-20]v/hello/d | command | delete all lines containing (or not containing) text "hello" from line 10 to 20 |
:i,jd; :'a,'bd | command | delete text from line i to j or from marker 'a' to marker 'b' inclusively |
:i,js/old text/new text/g | command | substitute "new text" for "old text" from line i to j |
:'a,'bs/old text/new text/g | command | substitute texts from marker 'a' to marker 'b' |
:25,30m50; 'a,'bm50; 25,30co50 | command | move lines 25-30 to a new position after line 50; move the text between markers to line after 50; copy lines 25-30 to line after 50 |