2

I'd like to construct a mapping that would replace a b with c where the gap between a and b could be zero or more spaces or zero or more tabs, but not zero of both. There have been several related postings: This is the most promising of several postings, which addresses the problem in terms of regexp, but I can't get their syntax to work in vim. Thanks for any suggestions.

8

If you're looking for a substitute command:

:s/a[ \t]\+b/c/

The default regex mode doesn't see + as an operator. You have to escape it to make it special.

You can also use:

:s/a\s\+b/c/

\s is Vim's shortcut for space and tabs in regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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