Show Menu
Cheatography

Vim

Moving

k
j
h
l
Move Forward One "Word"
Forward to Whitespace
w
W
Move Forward to End of "Word"
Same but to Whitespace
e
E
Move Backward one word (start)
Move Backward to whitespace
b
B
Page Down One Page
<Ctrl-f>
Page Up One Page
<Ctrl-b>
These can be used with text objects and repeat modifiers ie 2j will move down 2 lines instead of one, 3w will move 3 "­wor­ds" forward, etc.

Moving Advanced

Move to End of Line
$
Move to beginning of Line (first character)
^
Move to beginning of line
0
Move to top of file
gg
Move to bottom of file
G
Move to line <num>
<num>G 6G
Find next occurrence of <char>
Find previous occurrence of <char>
f<char>
F<char>
'Till the next occurence of <char>
'Till the previous occurrence of <char>
t<char>
T<char>
Move cursor to matching pair () {} []
%
Move cursor to top of screen
H (Home)
Move cursor to middle of screen
M
Move cursor to bottom of screen
L (Last)
Re-pos­ition cursor to the top
zt
Re-pos­ition cursor to the middle
zz
Re-pos­ition cursor to bottom
zb
You can repeat the commands with f and t using ; for forward repeat and , for backwards repeat

Marks

Make mark
m[a-­zA-Z]
Go to line with mark
'[a-­zA-Z]
Go to actual column mark
`[a-zA-Z]
:marks
Show marks
The marks A-Z are stored between files. the marks a-z are only in that single file. So two files can have different marks a but there can only be one A mark.
 

Inserting Text

Insert before current position
Insert at beginning of line (first char)
i
I
Insert after current position
Insert at the end of line
a
A
Insert new line below current line
Insert new line above current line
o
O
Read Text from <so­urc­e> (source can be a file or command)
:r file.txt

Modifying Text

Delete one char
Delete one char to left
x
X
Delete text to motion
d<mo­tio­n>
Change text to motion
c<mo­tio­n>
Delete single line
dd
Change entire line
cc | S
Delete to end of line
D
Change to the end of line
C
Replace single character at cursor
r<ch­ar>
Enter insert mode but replace text
R
Copy text to motion
y<m­oti­on>
Copy line
yy
Paste text after cursor
Paste text before cursor
p
P
If you copy an entire line, p will paste the whole line below the current line and P will do the same above.

Text Objects

A word (arround something)
a<motion/char>
Inner word (inside something)
i<motion/char>
The text objects can be used with text modifying commands, like d, c, y, and p. ciw will change the inner word (keep whites­pace) and wait for text in insert mode.
For more inform­ation see :help text-o­bjects

Visual Mode

Enter Visual Mode
v
Enter Visual Block Mode
<Ct­rl-­v>
Enter Visual Line Mode
<­Shi­ft-­v>
Visual mode accepts commands like d, c, y, and p after text has been selected.
 

Searching

Search forward
/
Search backward
?
Move to next search result
Move to previous search
n
N
Match whole word
\<text\>
Regex searching
^$.
Search forward the word under the cursor
*
Search backward the word under the cursor
#
Escape regex chars with \

Registers

Access register
"­[a-z]
Append to register
"­[A-Z]

Macros

Start recording macro
q[a-z]
Execute recorded macro
@[a-z]
Execute last used macro
@@

Files

Save file
:w
Save and Quit
:wq
Edit a new file
:e filename
Save copy of file
:w filename.copy
Save copy and edit copy of file
:saveas filename.copy
Change name of the current file
:file filename
Use ! to override warnings about saving files. Like if you type :q without saving changes Vim will warn you about this. But if you really want to discard your changes use :q!

Files Advanced

Open file in a split window
:split filename
Open file in a vertically split window
:vsplit filename
Open file in a new tab
:tabedit filename
Move to window
<Ct­rl-­w><­mot­ion>
Move to next tab
gt
Move to previous tab
gT
Move current window to tab
<Ctrl-W>T
   

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          VI Editor Cheat Sheet
          Vim Cheat Sheet
          Intermediate Vim Cheat Sheet