Basic Vim Commands for Beginners

Since you are here, am assuming you want to learn basic commands of Vim editor. First of all it’s awesome that you have chosen vim as an editor. Vim is a cross platform editor where you can find it in any OS like window, mac, Linux etc. learning the commands makes you independent of any other editor for any language.

Lets see an example of how well it increases productivity.

Let say you have below line and the cursor in ‘b’ of better and you seen a typo “well” instead of “will” in the line.

“Look deep into the nature, and then you well understand everything better “

Other editors = move using mouse (need hand movement) or using motion key(need multiple press 24 or 5)  and then delete key and add a char.

Vim editor = F -> w -> l -> r -> e

When we compare the keystroke needed for both kind of editors. Vim does it quickly with 5 keystroke. Initially it’s hard to get the right command for vim but once you master it no one can stop you.

Below list contain basic commands to help you to start with Vim. This list cover basic movement  and editing for regular activity. Once you master it explore the advanced commands as on when needed.


Commands to move around the content.

h/j/k/l = move left/down/up/right

0 = move the cursor to start of line.

$ = move the cursor to end of line.

w = move to next word beginning.

e = move to next word ending.

b = move to previous word beginning.

f <char> = move the cursor to next occurrence of char and use “;” to move next and next.

F <char> = move the cursor to prev occurrence of char and use”;” to move prev and prev.

<< = shifts the line left

>> = shifts the line right

To scroll

Ctrl + d = scroll window downwards.

Ctrl + e = scroll line downwards.

Ctrl + u = scroll window upwards.

Ctrl + y = scroll line upwards.

Jumps

Ctrl + o = Go to previous cursor position in jump list.

Ctrl + I = Go to next cursor position in jump list

:ju =  To view positions in jump list

Marks

ma = creates marks ‘a’ with the cursor.

‘ a = jumps to the line of mark a.

`a = jumps to the position of mark a.

d’a = deletes from the present line to the line of marker.

d`a = deletes from the present line to the position of marker.

:marks = list all marks in the file.

:delmarks a = delete mark a

Quick Edits

To delete (It copies the deleted content into register. So we can yank it later if needed)

x = deletes the char under the cursor.

X = deletes the char before the cursor.

d {motion} = delete char/line from the cursor. For example “dh” deletes the char before                     cursor

dd  = deletes the current line.

D = delete char from the char to end of the line.

To replace

R = Enable replace mode and It replace every char with typed char from the cursor.

c {motion} = Deletes {motion} character and enables insert mode.

cc = deletes the current line and enables insert mode.

C = deletes the char from the cursor to end of the line and enables insert mode.

s = substitute, delete the char under the cursor and enable insert mode.

Enabling insert mode

A = moves the cursor to end of the line and enable insert mode.

a = cursor moves to next character and enable insert mode.

o = creates a new line below the cursor and enable insert mode.

O = creates a new line above the cursor and enable insert mode.

Reference:

http://vimdoc.sourceforge.net/htmldoc

So, whats your Favourite command on Vim ?

Leave a Reply

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