Some nice and helpful VIM shortcuts

As a new VIM user I struggle a lot with the shortcuts, these are nice ones which I want to remember!

Home / Posts / Some nice and helpful VIM shortcuts

For whatever reason I decided to give VIM a chance… crazy guy I am :)

On a bit more serious note, I’m sure that VIM is really powerful if you ever get hang of it.

In the past I worked for a long time with Sublime Text 3, which is really great! And in the last ~ year I switched to Visual Studio Code, which is great as well! Especially the multicursor mode is a nifty feature.

Anyway, I found a really nice VIM cheatsheet, this post will contain the shortcuts which I find the most useful (and probably forget the easiest).

Cursor movement

Key Function
fx jump to next occurrence of character x, e.G. fr jumps to the next r in the text
tx jump to before next occurrence of character x, same as tx but lands before the occurrence
Fx jump to previous occurence of character x, same as the two above, but in the other direction
Tx jump to after previous occurence of character x
; repeat previous f, t, F or T movement
, repeat previous f, t, F or T movement, backwards

Editing

Key Function
J join line below to the current one with one space in between
gwip reshuffle the paragraph you are currently in
gu change to lowercase up to motion, e.G. gue changes all chars to the end of the word to lower case
gU change to uppercase up to motion, e.G. gU$ changes the whole line to upper case
xp switches two letters (delete and paste)
. repeat last command

Marking text, or visual mode

Key Function
aw mark a word
a{ mark the respective parenthesis block
~ switch case
u change marked text to lowercase
U change marked text to uppercase

Marks and positioning

Key Function
:marks list of marks
ma set current position for mark A
`a jump to position of mark A
y`a yank text to position of mark A
Ctrl + i go to newer position in jump list
Ctrl + o go to older position in jump list

Macros

Key Function
qa record macro a
q stop recording macro
@a run macro a
@@ rerun last run macro

Cut and paste

Key Function
yy yank (copy) a line
2yy yank (copy) 2 lines
yw yank (copy) the characters of the word from the cursor position to the start of the next word
yiw yank (copy) word under the cursor
yaw yank (copy) word under the cursor and the space after or before it
y$ yank (copy) to end of line

Working with multiple files

Key Function
Ctrl + ws split window
Ctrl + wv split window vertically

Manipulating numbers

Key Function
Ctrl + a Increase the first digit or number on the current line
Ctrl + x Decrease the first digit or number on the current line
g Ctrl + a Visual Mode: Increase the first digit or number on the current line, but increasingly. e.g. first line +1, second line +2, and so on
g Ctrl + x Visual Mode: Decrease the first digit or number on the current line, but increasingly. e.g. first line +1, second line +2, and so on
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy