Started using vi, although the only reason is it being light weight [I am taking a leap of faith, hoping that it will increase my speed after some practice, as most vi gurus say]. Let me first admit it. Vi feels awful in the beginning. It is really intimidating, and I am having a hard time to remember the commands and stuff. Hence I started writing the commands I learn from google and stackoverflow in a file. Thought to post it here, for everyone.

I will keep the list updated as I learn more and more commands and tricks. It serves me as a reference, and hopefully will do the same for some of you.

Open file

vim file.js

Swtich to insert mode


Switch to append mode


Switch to command mode


Save file


Save and exit


Exit [if no changes were made]


Exit, discarding changes


Moving through text

h - left
j - down
k - up
l - right

Undo last operation


Copy current line


Cut current line


Paste last copied line


Select text

[CTRL] + v
h,j,k,l ;for moving and selecting

Selecting multiple lines

[SHIFT] + v
j,k ;selecting lines

Search through text


Search and replace


Working with multiple files

vim file1.c file2.c file2.c

Next file


Previous file


Go to particular file

:b file3.c

Working with multiple files [tabs]

vim file1.c file2.c file3.c -p

Move to next tab


Move to previous tab


List all open files [or buffers]


Commenting multiple lines

[CTRL] + v ;to enter visual mode


Uncommenting multiple lines

[CTRL] + v ;to enter visual mode
jjjl ;selecting multiple rows and columns



Move to the start of the file


Move to the end of the file


Auto indent entire file


Indenting a block [starting from a paranthesis]


Indenting selected lines

jj ;move down through required lines

Starting a shell


Executing bash without shell

:command ;eg. :pwd