Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which regex do I have to use in VIM to replace all words 'to' from a text with the word 'foo'? (I don't want to replace 'to' when it happens in a word like 'together').

share|improve this question
up vote 7 down vote accepted

this should work:


Using \< and \> ensure that "to" will only be replaced if it is an entire word. \< matches the start of a word and \> the end. This way it won't turn your "tod" into "food" :)

share|improve this answer
Much nicer than my solution for sure :-) – ℝaphink Dec 28 '09 at 16:16

I'm sure there's a simpler way, but:


would do the trick

EDIT: John T has posted the simpler way :D

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.