Vim Cheat Sheet

A Software › Vim cheat sheet in English by nwilde

Vim

41,190 views 6,502 downloads 1 Nov 2018 History
3.7 avg · 0 ratings

Moving

k
j
h
l
Move Forward One "Word"
Forward to Whitespace
w
W
Move Forward to End of "­Wor­d"
Same but to Whitespace
e
E
Move Backward one word (start)
Move Backward to whitespace
b
B
Page Down One Page
<Ct­rl-­f>
Page Up One Page
<Ct­rl-­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 <nu­m>
<nu­m>G 6G
Find next occurrence of <char>
Find previous occurrence of <ch­ar>
f<char>
F<char>
'Till the next occurence of <char>
'Till the previous occurrence of <ch­ar>
t<c­har>
T<c­har>
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<m­oti­on>
Change text to motion
c<m­oti­on>
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<c­har>
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<m­oti­on/­cha­r>
Inner word (inside something)
i<m­oti­on/­cha­r>
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
<Sh­ift­-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
\<t­ext­\>
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 filena­me.copy
Save copy and edit copy of file
:saveas filena­me.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
<Ct­rl-­W>T

Badges

Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 2

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.