Vim search and replace query

regex, vim

Solution

If you're after conserving keystrokes, you can initialize a named register with the replacement text:

:let @a = repeat(' ', 8)

Then, when building your substitution command, you insert the register contents via CTRL-R + {register-name}:

:%s/pattern/<C-R>a&/gc

For further simplification, I have referred to the search pattern in the replacement string via `&`.

Problem

I have a regular expression like this: ``` :%s/pattern/ pattern/gc ``` As you can see in the replacement text I want eight whitespace characters initially. I don't want to type eight white spaces every time. Is there a more elegant way of doing this?

Original source