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

i

Switch to append mode

a

Switch to command mode

[ESC]

Save file

:w

Save and exit

:wq

Exit [if no changes were made]

:q

Exit, discarding changes

:q!

Moving through text

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

Undo last operation

u

Copy current line

yy

Cut current line

dd

Paste last copied line

p

Select text

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

Selecting multiple lines

[SHIFT] + v
j,k ;selecting lines

Search through text

:s/pattern

Search and replace

:s/pattern/replacementString

Working with multiple files

vim file1.c file2.c file2.c

Next file

:n

Previous file

:prev

Go to particular file

:b file3.c

Working with multiple files [tabs]

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

Move to next tab

gt

Move to previous tab

gT

List all open files [or buffers]

:ls

Commenting multiple lines

[CTRL] + v ;to enter visual mode


[ESC]

Uncommenting multiple lines

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

Auto-indenting

=

Move to the start of the file

gg

Move to the end of the file

G

Auto indent entire file

gg=G

Indenting a block [starting from a paranthesis]

=%

Indenting selected lines


jj ;move down through required lines
>

Starting a shell

:shell

Executing bash without shell

:command ;eg. :pwd