VIM Tips

Navigation keys

Left: h
Down: j
Up: k
Right: l
Goto beginning of file ":0"
Goto line n ":n"  Eg.":15"
Goto end of file "G"

Close

Exit VIM ":quit" or "ZZ"
Close Window: ":close"
Close all Windows except current one: ":only"

Save

Save As ":w file_name.extension"
Save ":w"

Search String

Search down "/string"
Search down "?string"
Repeat last search "n"

Cut Copy Paste

1) Enter Visual Mode "v"
2) Select text using navigation keys
3) Cut "x"   or Copy "y"
4) Paste "p"

Block Insert a column

Step 1: CTRL-v
Step 2: Select the lines using arrow keys
Step 3: SHIFT-i
Step 4: Type text to be added to every row of that column
Step 5: ESC ESC

Split Window

Horizontal ":split new"
Virtical ":vsplit new"
New Tab ":tabnew"

Navigating Windows

CTRL-W
CTRL-TAB

Resize Windows

Change height to 3 lines ":res 3"

Delete

Character "x"
Line "dd"
Line break "J"

Insert mode: use keyboard backspace
:set backspace=indent,eol,start

Undo Redo

Undo "u"
Redo CTRL-R

Shell Interface

Enter Shell Command ":shell"
Execute Shell Command "!ls -l"
Read Output of Shell Command ":read !shell_command"

Run VIM Script

From VIM ":source script_name.vim"
From Terminal "vim -S script_name.vim"
Comment in vim script
"text after double quotes are comments

Navigate source code

ctags *.c*

vi tags

:tag tag_name

:ta tag_name

Syntax Highlight

See this example

Create VIM start-up script

See this example