Skip to content

Instantly share code, notes, and snippets.

@jonlabelle
Last active December 17, 2020 07:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonlabelle/11053123 to your computer and use it in GitHub Desktop.
Save jonlabelle/11053123 to your computer and use it in GitHub Desktop.
Vim Cheatsheet

Vim Cheatsheet

To open a file in Vim:

vim <filename>
Navigation
h move one character left
j move one row down
k move one row up
l move one character right
w move to beginning of next word
b move to beginning of previous word
e move to end of word
W move to beginning of next word after a whitespace
B move to beginning of previous word before a whitespace
E move to end of word before a whitespace

All the above movements can be preceded by a count; e.g. 4j will move down 4 lines.

Navigation
0 move to beginning of line
$ move to end of line
^ move to first non-blank char of the line
_ same as above, but can take a count to go to a different line
g_ move to last non-blank char of the line (can also take a count as above)
gg move to first line
G move to last line
nG move to n'th line of file (where n is a number)
H move to top of screen
M move to middle of screen
L move to bottom of screen
z. put the line with the cursor at the center
zt put the line with the cursor at the top
zb put the line with the cursor at the bottom of the screen
Ctrl-D move half-page down
Ctrl-U move half-page up
Ctrl-B page up
Ctrl-F page down
Ctrl-o jump to last cursor position
Ctrl-i jump to next cursor position
n next matching search pattern
N previous matching search pattern
* next word under cursor
# previous word under cursor
g* next matching search pattern under cursor
g# previous matching search pattern under cursor
% jump to matching bracket { } [ ] ( )
Search
/ search for a pattern which will take you to the next occurrence.
? search for a pattern which will take you to the previous occurrence.
n for next match in forward
N for previous match in backward
Insert / Delete
I Insert at start
A Append at end
D Delete to end of line
; Clear current line, to insert mode: S
o Insert new line below
O Insert new line above
x Delete
X Backspace X
r Replace under cursor
d Delete word (like d2w for deleting 2 words)
Copy / Paste
yy Copy current line
p Paste copied text after cursor
Comments
CTRL+V (select lines) I# Comment
CTRL+V (select lines) X Uncomment
Misc
. repeat command
u undo
CTRL+R redo
CTRL+P autocomplete word
:e [file] open file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment