vimsurround

Surround Several Words With Quotes At Once In vim


I was curious if there is a way to surround several words at once with quotes using vim. I am using tpope surround and repeat but I was wondering if there is a command like

3ysw"

so from

one two three 

to

"one" "two" "three"

Solution

  • You can visually select the range with v3e, and then run a substitution command on it: :s/\v(\w+)/"\1"/g (the range '<,'> should automatically be inserted).

    Personally though, I'd rather surround one word with ysw", and then do w.w. (repeat as often as needed).


    Alternatively, record a macro that does both steps (surrounding and moving on to the next word), then call it n times:

    qqysw"3wq
    

    After this is in your q register, you can then call 2@q to perform the surroundings on the remaining words.