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

I'm trying to use the vim submatch command to put quotes around all strings of characters in a line of text, and it doesnt work. Here's what I'm doing


All it does is replace all strings with the string (submatch(0)). How do I make vim do what I'm trying to do?

share|improve this question
up vote 6 down vote accepted

submatch is not the best solution to do this. I was doing some helpgrep on \\=

And I find this:

                *sub-replace-special* *:s\=*
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|.  You can use that for any special characters.
Otherwise these characters in {string} have a special meaning:

If you insist in using submatch you can use it in this way:


However a more readable solution is:

share|improve this answer

You have to capture each match by surrounding the pattern with a pair of braces \( and \). Having done this you can use the actual matched text in the replacement pattern with \1.

The following command does what you want:

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.