Labels

APPLE (1) astro (1) IDL (4) life (2) linux (5) LSD (2) Mac (2) teaching (1) volleyball (2) work (1)

Wednesday, July 22, 2009

[VI] find and replace

Find the 'txt': /txt (forward searching)
?txt (backward searching)
/\ (searching for the whole word 'txt')

Get rid of the highlighting after search:
:set nohlsearch
Enable highlighting searching:
:set hlsearch

Find the replace:
:s/word/replacement/ ( once )
:s/word/replacement/g ( all at once on a single line )
:.,.+Ns/word/replacement/g ( all at once on the current line and
the next N lines )
:%s/word/replacement/g ( all at once the whole text )
:s/word/replacement/cg ( you need confirm whether or not to
replace )
:s/word/replacement/gi ( case insensitive )
:set ic ( case insensitive )
:set noic ( case sensitive )
:%//g ( remove all tab characters )

ref: http://www.linux.ie/articles/tutorials/vi2.php