General Edit
Vi begins in command mode, where the cursor movement and Prefix commands below with single lowercase letter to use
text deletion and pasting occur. Insertion mode begins upon specific buffer instead of general clipboard.
entering an insertion or change command. [ESC] returns to
command mode. Change “c”+<Move> commands delete and enter insert mode.
Most commands execute as soon as you type them, c<Move> delete text specified by Move, enter insert mode
"colon" commands execute when you press the return key. C change to end of line (same as c$)
cc change the whole line
Prefix most commands with a number to repeat it. S change the whole line (same as cc)
s delete character at cursor and subsitute text
Quit Delete “d”+<Move> commands delete text specified by Move.
:q quit (fails if anything has changed)
:q! quit and throw away changes d<Move> delete text specified by Move
:w write (save) the file x delete character at cursor (Del)
:w <file> save as X delete character before cursor (Backspace)
:wq write (save) and quit D delete to end of line
ZZ write (save) and quit dd delete the whole line
:d delete the whole line
Scroll J join line below to this (change LF to space)
C-d scroll down half screen Yank “y”+<Move> commands copy text specified by Move
C-u scroll up half screen
C-f page forward (down) y<Move> yank text specified by Move
C-b page backward (up) yy yank the whole line
z. scroll window, cursor in the middle :y yank the whole line
% associated () [] {} Replace
General form :[range]s/pattern/string/[flags]
Windows
:e <file> Edit a file in a new buffer :%s/old/new/ replace first in each line of file
:sp <file> Open a file in a new buffer and split window :%s/old/new/gc replace all with confirmations
:bn go to next buffer in same window :.,$s/foo/bar/gi replace all downwards, ignore case
:bp go to previous buffer in same window :.-10,.+10s/foo/bar/g replace all within 10 lines distance
:bd delete a buffer (close a file) & repeat last replace command without flags
C-w s Split windows :&& repeat last replace command with flags
C-w v Split windows vertically
C-w w switch between windows Regexp
C-w<Move> switch to window in direction of Move * zero or more
C-w q Quit a window \? zero or one
\+ one or more
Insert
vi will remain in insert- or replace mode until pressing ESC. Other
i start insert mode at cursor u undo
I insert at the beginning of the line . redo
a append after the cursor ~ toggle case
A append at the end of the line g~<Move> toggle case of characters specified by Move
o open (append) blank line below (no LF needed)
O open blank line above current line > indent
< unindent
r replace single character, stay in command mode :[range]>[n] indent n lines in range
R start replacing many characters at cursor :[range]<[n] unindent n lines in range