find and replace exact word in vim

I have spent the weekend updating some old code, and as usual it’s a bit of a mess … One of the problems I have had is that there is lots of stuff that have similar names, but do different things, so I have to be careful about bulk search-replace commands.

Happily, vim has a neat search and replace command that narrows the case to exact word / string matches: it’s


Say we have the following (i have lots just like it):

rbaCash.test <- …

rbaCash.test.irf <- …

rbaCash.test2 <- …

rbaCash.test2.irf <- …

And I wish to change `rbaCash.test` to `rbaCash.testOld`.

Using `%s/\<rbaCash.test\>/rbaCash.testOld/g` changes only the `rbaCash.test` strings and not the `rbaCash.test2` strings — which is what i want.

This is a big improvement on the standard search-replace command:


erroneously changes the `rbaCash.test2` strings to `rbaCash.testOld2` …

This entry was posted in coding, tech, vim and tagged . Bookmark the permalink.

please comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.