Show Menu
Cheatography

Vi Chear Sheet Cheat Sheet (DRAFT) by

vi or vim cheat sheet for the linux command line

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Modes Of Operation

Input Mode:
i
Insert before cursor
I
Insert at the begining of line
a
Insert after cursor
A
Insert End of line
o
Insert line below
O
Open line
C
Cut text to the end of line
[ESC]
Switch back to comman mode
Command Mode:
:
Enters last line mode
:w
Save
:wq,:x, ZZ
Save & Exit
:q
Quit
:q!, ZQ
Quit without saving

Search and Replace Commands

Searching:
/string
Search forward for string
?string
Search backwards for string
n, (,)
Go to next match
N, (;)
Go to previous match
*
Search for next instance of current word
#
Search for last instance of current word
:set ic
ignore case while searching
:set noic
Case-s­enitive searchng
:set nu
Turn on line numbers
:x, yg/str
Search for str from line x to y
:g/str/cmd
Run cmd on lines containing str
Replacing:
:s/pt/­str­/flag
Replace all occurr­ences of pattern
g
Replace all occurr­ences of pattern (Flag)
c
Confirm replaces (Flag)
&
Rrepeat last :s command
 

Modify Text Commands

Deleting Text:
D
Delete to the end of the line
dd, :d
Delete current line
x
Delete character to the right of cursor
X
Delete character to the left of cursor
.5dd
Delete 5 lines downwards from current
Edit Commands:
.
Repeat last command
U
Undo all commands for current line
u
undo last command
p
Paste (below)
P
Paste (above)
r
Overwrite one character
R
Overwrite many charaters
^r
Redo
Yanking:
yy, :y
Copy current

Splitting Screen Commands

:split, ^ws
Split screen horizontal
:vsplit, ^wv
Split screen vertical
^ww
Switch to next
:on
Close all windows except current window
^w hjkl
Move curso to window left, below, above or to the right of the current window
^w HJKL
Move current to window left, below, above or to the right of screen
^w r
Rotate windows clockwise
^w +-<>
Increase/ decrease current windows height­/width
^w T
Move current windows to new tab
:bufdo
Execute a monnad in each open file
 

Movements

h, <Ba­cks­pac­e>, [left-­arrow]
Previous character
b
Previous word
B
Previous WORD
^
First non-blank character
0
beginning of line
l, <Sp­ace­>, [right­-arrow]
next character
e
End of word
w
beginning of nxt word
E
End of WORD
W
Beginning of next WORD
$
End of line
gg
First line
^b
Up 1 page
^u
Up 1/2 page
k, [up-arrow]
Up 1 line
j, <Re­tur­n>, [down-­arrow]
Down 1 line
^d
Down 1/2 page
^f
Down 1 page
G
Last line
^i
Jump forward
^o
Jump back
zz
Center screen on cursor
zt
Align top of screen with cursor
zb
Align bottom of screen with cursor
==
Auto-i­ndent current line
<<
Shift current line left by shiftwidth
>>
Shift current line right by shiftwidth
 

Multiple Files Commands

In Command Mode:
:n, :bn
Go to next file
:p, :bp
Go to previous file
:n!
Discard changes to file and edit next file
:e#
Closes current file and opens last edited file
:rew
rewinds sequence of files back to the first file you are editing
:c#
Copies blocks of text from a file to another
:ls
List all open files
:e
Open a file for editing
:ene
Open a blank new file for editing
:bd
Remove file from the buffer list

Visual Mode

v
Enter visual mode
V
Enter visual line mode
^v
Enter visual block mode
o
Switch cursor to start/end
gv
Re-select previous area
I
prepend to each visual block line
'<
Jump to of prior area