Skip to main content

VIM

Vim tutorial

 ** To move the cursor, press the h,j,k,l keys as indicated or directional keys **
            ^
            k              Hint:  The h key is at the left and moves left.
      < h       l >               The l key is at the right and moves right.
            j                     The j key looks like a down arrow.
            v

 

Exiting VIM

to Exit VIM without saving press <ESC> then :q! <Enter>

Useful commands in Normal mode (press <ESC>)

i
Insert mode
x
Delete the character under the cursor
A
To append text
wq
To save a file and exit
ESC
Will place you in normal mode or will cancel an unwanted and partially completed command
dw
To delete until the start of the next word, Exluding its first character
d$
To delete to the end of the line (depends on where the cursor is at) Including the last character
de
To the end of the current word Including the last character.
2w
To move two words forward (you can use any combination, 3w will move you 3 words forward.
3eTo move the cursor to the end of the third word forward (you can use any combination 2e will move you 2 words forward.
0
Zero - to move to the start of the line
u
to undo the last command
U
to fix a whole line
CTRL-Rto redo the commands


 

Operations and Motions

Multiple combinations can be achieved

d2w will begin the next 2 words beginning at the cursor, d4w will delete the next 4 words.

in the example below we will place our cursor at A (first capital A) and type d2w

--->  this ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up.

after typing d2w cursor at A

--->  this line FGHI JK LMN OP of words is Q RS TUV cleaned up.

now place cursor at F and type d4w

--->  this line of words is Q RS TUV cleaned up.

now with our cursor at of type 3w to move 3 words forwward with our cursor at Q type d3w

--->  this line of words is cleaned up.

 

DD to delete a whole line you can also use 2dd to delete 2 lines