VIM editor shortcuts

At Sanoma I learned to use VIM. It's an editor for power-users.

 

The basics

To edit a file named test.txt type the following in the shell:

$ vim test.txt

If you want the same file and start appending text on the end of it, open it like so:

$ vim + test.txt

To start editing; get into insert mode at the cursor, type:

i

To save the file type:

[Esc] :w [enter]

To save the file and exit type:

[Esc] :wq [enter]

To leave the editor without saving type:

[Esc] :q! [enter] 

 

Copy and Paste

To get into visual mode, mark lines, then do a command type:

v

Then to copy (yank) what you've selected type:

y

Or to cut what you've selected type:

d

To paste type:

p

 

Undo and Redo

To undo a command type:

u

To redo a command type:

[ctrl] + r

 

Move around

To go to the end of the line type:

$

To go the the first non-blank character of line type:

^

To go to the end of the file type:

G

 

Search and replace

To search for a pattern type:

 /pattern

To repeat search in the same direction type:

n

To repeat search in the opposite direction type:

N

To replace old with new throughout the file:

:%s/old/new/g

To replace old with new throughout the file with confirmations:

:%s/old/new/gc

 

Splitting the window

To split windows vertically type:

[ctrl] + wv

To switch between windows type:

[ctrl] + ww

To close a window type:

[ctrl] + wq

Open browser in current path to open new file:

:e.

More

To cut a whole row type:

dd

To cut until the next word type:

dw

To repeat the last command type:

.

To copy until the next word type:

yw

To copy an entire row type:

yy

To switch the case after you made a selection type:

~