Wednesday, February 14, 2007

Oh, I like those highlights!

When you are searching for a pattern in vim, it helps to enforce "search as you type " with highlighting. For this include the following in your .vimrc:
set incsearch
set hlsearch

It also helps while using s//, if you are trying to replace (especiallyto check for mistakes in the pattern matching), to have the search pattern highlighted. Assuming the above two lines are added in your .vimrc,

First, search for the pattern you want to replace , e.g. XXX

/XXX

This will have highlighting and incsearch on for you to see whether there are any matches, etc.

Now, type in the pattern you want to replace XXX with (e.g. YYY)

:%s//YYY

This will remember the "XXX" search, and replace instances of XXX with "YYY"

No comments: