Categories
Uncategorized

Ultimate Vim Keyboard Shortcuts

A well thought out printable PDF collection of Vim keyboard shortcuts that will enhance your workflow. I hope you find some cool ones you didn’t know about yet, and also find it a useful reference to the essentials.

These are all available out of the box in Vim and Neovim. If you want a full set of additional custom mappings for Neovim that integrate with the very best plugins then have a look at https://github.com/David-Else/developer-workstation-setup-script

# Navigate

h/j/k/l  - left/down/up/right 
gg or G  - top or bottom of file

ctrl u|d - scroll up/down
ctrl i|o - go forward and back in cursor positions
ctrl ^   - toggle current and previous file

( or )   - jumps to the previous/next sentence
{ or }   - jumps to the previous/next paragraph

# Insert

i - insert before character
I - insert before line
a - insert after character
A - insert after line
o - insert a new line below the cursor
O - insert a new line above the cursor

# Delete

x  - delete character under cursor
X  - delete character left of cursor
dd - delete current line
D  - delete to end of line
d0 - delete to beginning of line

# Delete and insert

s - delete character and insert
S - delete line and insert
C - delete until end of line and insert
r - replace character under cursor
R - replace characters under cursor

# Paste

p - paste text after cursor
P - paste text before cursor

# Operators

operator -> count -> motion
count -> operator -> motion

c    - change
d    - delete
y    - yank
gu|U - change case
g~   - toggle case
<>   - remove/add indentation

# Text objects

operator -> a|i -> text-object

a  - select "a"n object including white space
i  - select an "i"nner object without white space

w  - word - punctuation considered words
W  - WORD - non-blank characters, separated with space
s  - sentence
b  - block ()
B  - block {}
p  - paragraph
t  - tag
'" - quoted text
# Search line

f or F - search forward/backwards on line
t or T - search forward/backwards to preceding char
; or , - goto next or previous selection

# Search document

/ or ? - search forward or backwards in document
n or N - goto next or previous selection

* - search word under cursor forward 
# - search backwards (cgn replaces word, . to repeat)

# Substitute in document

:%s/foo/bar/g - substitute 'foo' for 'bar'
s/foo/bar     - substitute within visual selection

# Search project

:grep foo     - search for 'foo' in all files in cwd
:grep foo src - search for 'foo' in all files in ./src

# Marks

m [upper case letter] - create global mark (all files)
m [lower case letter] - create local mark

' [letter]        - jumps to beginning of marked line
backtick [letter] - jumps to line/column of the mark 

:marks     - show marks
:delmarks! - delete lowercase marks current buffer

# Folds

zf{motion}  - create fold
v{motion}zf - create fold
za          - toggle fold
zM          - close all folds
zR          - open all folds
zE - eliminate all folds (if foldmethod=manual|marker)

# Windows

ctrl ws        - split window
ctrl wv        - split window vertically
ctrl wn        - create new window with empty file
ctrl w h|j|k|l - move to window in direction 

# Various
 
ZZ         - save and quit
ZQ         - quit
J          - join line below
gf         - open file
gx         - open link
gt         - cycle tabs
gT         - reverse cycle tabs
gv         - reselect last visual mode selection
I[text]esc - insert multiple lines in visual block mode
.          - repeat command
:!wc %     - run external command, % is current file
:sort u    - sort and remove duplicates
ctrl w     - delete word before cursor in insert mode

Here is a specially formatted PDF for printing on one sheet of A4:

2 replies on “Ultimate Vim Keyboard Shortcuts”

Neat post, learned some new commands, even after using vim for over a year already. Thanks!

I remember the ‘a’ as “around” and really think it helps to memorize it. Need to delete a word? Just use ‘daw’ (delete around word), and surrounding spaces are just as they should.

Leave a Reply

Your email address will not be published. Required fields are marked *