Wednesday, April 13, 2011

How to use tabs in Vim?

$ vim -p <filename1> <filename2> <filename3> = run a new vim instance with several files open as tabs 

:tabnew <filename> = open a new tab
:tabnext / :tabn = move to the next tab
:tabprevious / :tabp = move to the previous tab

In vimrc :tabnext and :tabprevious can be mapped to Ctrl+L and Ctrl+H...or to any other key combination.

map <C-L> :tabnext<CR>
map <C-H> :tabprevious<CR>

Saturday, April 2, 2011

How to replace all the occurences of a string in a file in Vim?

/%s/old_string/new_string/gc

g = replace all, not only the 1st occurrence
c = ask for confirmation

Ref:
http://www.linux.com/learn/tutorials/8255-vim-tips-the-basics-of-search-and-replace