Linux Vi Editor Operators and Commands

Numeric arguments may prefix any operator; the command is repeated the given number of times or until it fails. Numeric arguments prefixing an operand execute the operand the given number of times, effectively just moving the cursor. (Some versions of vi, such as that provided with AIX 5L, don't respond properly to numeric prefixes in front of some operands such as the / string search operand.)
Operators Description
d operand delete the operand into the (delete) buffer
p paste the contents of the (delete) buffer after the cursor
y operand yank the operand into the (delete) buffer
i operand inserts the operand (before current character)
a operand appends the operand (insert after current character)
r operand replaces current character with operand
s operand substitute the operand with typed-in text
c operand change the operand to typed-in text
! operand pass the operand to a (Unix) shell as standard input;
standard output replaces the operand.
Common Macros Description
I insert at beginning of line (same as ^i)
A append at end of line (same as $a)
D delete to end of line (same as d$)
C change to end of line (same as c$)
x delete one character (same as dl)
ZZ save and exit
:w filename save as filename without exiting
:q! quit immediately (without save)
Miscellaneous
R enter replace (overstrike) mode
o open line below current line
O open line above current line
" n n is 0-9: delete buffers
" x x is lowercase a-z: replace user buffer
" x x is uppercase A-Z: append to user buffer
. perform last change again
u undo last change
U undo all changes to current line
Operands Description
h j k l left, down, up, right; one character/line at a time
w b e next word, back word, end of word
W B E (same as above, but ignores punctuation)
/string search for string (use ? for reverse search)
n search for string again (see /, above)
% find matching ( ), { }, or [ ]
( ) beginning of current/previous sentence and beginning of next sentence
{ } beginning of current/previous paragraph (two adjacent newlines) and beginning of next paragraph (see also set paragraphs)
[[ ]] beginning of current/previous section and beginning of next section (mostly user-defined; see also set sections)
line G goto particular line number (defaults to end-of-file)
0 ^ $ move to column 0, move to first non-whitespace, move to end of line
f x forward to character x on same line (inclusive)
t x to character x on same line (not inclusive)
; last f or t again in the same direction
, last f or t again in the opposite direction
m x set mark x at current position
' x move to line containing mark x
` x move to exact position of mark x
'' move to line of last jump point
`` move to exact position of last jump point

 

Interesting examples of numeric prefixes would be 36i-*<ESC>, 8i123456789-<ESC>, and 20r_.