Vim Commands
+*Must be in Command Mode to perform the following commands.
General
#
Command
Description
Comments
i
Enter insert mode
Press ESC to exit Insert Mode
[Insert Key]
Enter insert mode
Press ESC to exit Insert Mode
r
Enter replace mode
Press ESC to exit Replace Mode
*NOTE: Pressing Insert twice also
enters replace mode
v
Enter visual mode
Press ESC to exit Visual Mode
[Escape Key]
Enter command mode
If the are in another mode, ESC will
take you into Command Mode
#
dd
Delete line
Ex) 2dd - Deletes 2 lines
#
dl
Delete letter
#
x
Delete letter
[Delete Key]
Delete letter
#
dw
Delete word
dG
Delete everything until
end of file
Press gg or 1G before you do this
command to delete everything from
beginning to end
#
yy
Yank (copy) line
Ex) 3yy - Copies 3 lines
p
Paste
Always pastes below the green cursor
%
Jumps to matching
bracket
To access the % symbol, press Shift +
5
#
u
Undo
Ex) 4u - undoes the last 4 changes
Ctrl-r
Redo
/[word]
Searches for a [word]
Press n to increment search
:%s/[search]/[replace]/g
Searches all instances
of [search] and
replaces them with
[replace]
Ex) :%s/Hello/World/g - Searches
for all instances of “Hello” and replaces
it with “World”
:[x],[y]s/[search]/[replace]/g
Change each
[search] to
[replace] from line
[x] to line [y]
Ex) :5,12s/Hello/World/g - Same
as above, but only replaces from line 5
to line 12 (inclusive)
1G=G
Formats/Indents code
The “Gmust
be capitalized
gg=G
Same as “1G=G
# = (Optional) Any number can precede the command
This workforce product was funded by a grant awarded by the U.S. Department of Labor’s
Employment and Training Administration. The product was created by the grantee and
does not necessarily reflect the official position of the U.S. Department of Labor. The U.S.
Department of Labor makes no guarantees, warranties, or assurances of any kind, express
or implied, with respect to such information, including any information on linked sites and
including, but not limited to accuracy of the information or its completeness, timeliness,
usefulness, adequacy, continued availability, or ownership.
Vim Commands
Moving Around in Vim
Command
Description
Comments
Home
Jumps to beginning of line
Windows only
End
Jumps to end of line
Windows only
0
Jumps to beginning of line
Windows and Mac
$
Jumps to end of line
Windows and Mac
^
Jumps to the first non-blank character of a
line
Windows and Mac
Page Up/Page Down
Jumps a page up/down
Windows only
Ctrl-F
Jumps a page down (forward)
Windows and Mac
Ctrl-B
Jumps a page up (backward)
Windows and Mac
gg
Jumps to top of file
1G
Jumps to top of file
23G jumps to 23rd line in file
G
Jumps to bottom of file
Saving and Quitting
Command
Comments
:w
:q
Will not let you quit if you’ve made
changes to the file
:q!
:wq
:x
Other Vim Commands
Command
Comments
:set nu
:set nu!
:set mouse=a
To copy/paste text, hold down SHIFT
while selecting text and to paste.
:set paste
Only use this when you need it. Disable it
when you are done pasting the text you
want into vim.
:set nopaste
:[line_number]
Ex) :23 - jumps to line 23
This workforce product was funded by a grant awarded by the U.S. Department of Labor’s
Employment and Training Administration. The product was created by the grantee and
does not necessarily reflect the official position of the U.S. Department of Labor. The U.S.
Department of Labor makes no guarantees, warranties, or assurances of any kind, express
or implied, with respect to such information, including any information on linked sites and
including, but not limited to accuracy of the information or its completeness, timeliness,
usefulness, adequacy, continued availability, or ownership.