Vi Command Cheat Sheet

ADVERTISEMENT

Quittin
:x
Exit, saving changes
:q
Exit as long as there have been no changes
ZZ Exit and save changes if any have been made
:q! Exit and ignore any changes
Insertino Text
Insert before cursor
Insert before line
a
Append after cursor
A
Append after line
o
Open a new line after current line
o
Open a new line before current line
Replace one character
R IReplace many characters
Deleting Text
Almost all deletion commands are performed by
t
ing d followed by a motion,
dw Delete word
x
Delete character to the right of cursor
X
Delete character to the left of cursor
D
Delete to the end of the line
dd Delete current line
:d
Delete current line
Yanking Text
Almost all yank commands are performed by typing
followed bv a motion.
y$IYank to the end of the line
yy Yank the current line
:y Yank the current line
Changing text
The change command is a deletion command that
leaves the editor in insert mode,
It
is performed by
Ping c followed by a motion.
cw Change word
C
Change to the end of the line
cc Change the whole line
m
PuUi no text
p
I
Put after the position or after the line
P
Put before the position or before the line
h
j
k
I
w
W
b
B
e
E
(
)
{
}
o
$
G
G
nG
:n
fc
Fc
H
M
L
Ctrl+u
Ctrl+d
%
fstring
Vi Command Cheat Sheet
Motion
Move left
Move down
Move up
Move right
Move to next word
Move to next blank delim ited word
Move to the beginning of the word
Move to the beginning of blank delimited word
Move to the end of the word
Move to the end of blank delimited word
Move a sentence back
Move a sentence forward
Move a paragraph back
Move a paragraph forward
Move to the beginning of the line
Move to the end of the line
Move to the first line of the file
Move to the last line of the file
Move to nth line of the file
Move to nth line of the file
Move forward to c
Move back to c
Move to top of screen
Move to middle of screen
Move to button of screen
Page up
Page down
Move to associated ( ), { }, [
1
Search for strinas
Search forward for string
?string Search back for string
n
Search for next instance of string
N
Search for previous instance of string
Other
TOggle capital and lower-case
J
Join lines
.
Repeat last text-changing command
u
Undo last change
U
Undo all changes to line
n
Based on
Buffers
Named buffers may be specified before any deletion, change, yank or put
command, The general prefix has the form "c where c is any lowercase
character. for example, "adw deletes a word into buffer a, It may
thereafter be put back into text with an appropriate "ap.
Markers
Named markers may be set on any line in a file. Any lower case leiter
ma
mc
'c
'c
be a marker name. Markers ma also be used as limits for ran
Set marker c on this line
Go to beginning of marker cline.
Go to first non-blank character of marker clin
es.
e.
Replace
The search and replace function is accomplished with the :s command. It
is commonl used in combination with ran es or the: command below.
:sfpatternfstring/flags Replace pattern with string according to flags.
g
Flag - Replace all occurrences of pattern
c
Flag - Confirm replaces.
&
Repeat last :s command
Counts
Nearly every command may be preceded by a number that specifies how
many times it is to be performed. For example, 5dw will delete
5
words
Ranges
Ranges may precede most "colon" commands and cause them to be
executed on a line or IinesJ'or example :3,7d would delete lines 3-7.
:n,m
:$
:'c
:%
:g/pattern/
:wfile
:r file
:n
:p
:e
file
!!program
I
Range Lines n-m
Range - Current line
Range - Last line
Range - Marker c
Range - All lines in file
Range - All lines that contain pattern
Files
Write to file
Read file in after line
Go to next file
Go to previous file
Edit file
Replace line with output from program

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go