I want to surround a word with quotes

Here is my set of commands:

  • ciw
  • ' (I use the Vim extension on Visual Code so I get two ' I do not know if it the case for "normal" Vim)
  • Esc
  • p

It works, but there may be a shorter version to achieve this. Could you help ?


2 Answers 2


You can give a try to vim-surround plugin. To put a word into quotes you will go ysiw'. The plugin gives you the power to:

  • add (ysiw")

    word -> "word"
  • change (csiw"')

  • delete (ds')


the surroundings not only of sigle words but of all kinds of text objects:

  • surround words inside parentheses (ysi)")

    def func(some sequence of words) -> def func("some sequence of words")
  • change parentheses to square brackets (cs)])

    list = (var1, var2, var3) -> list = [var1, var2, var3] 
  • 1
    I do mention vim-surround in my answer, FYI.
    – B Layer
    Commented Dec 22, 2020 at 14:01
  • Aaaand it gets accepted. Where did I put that darn bottle of Valium....
    – B Layer
    Commented Dec 22, 2020 at 15:29

If you're using the VS Code extension that I think you are then my understanding is that it supports at least some plugins and one of those is vim-surround. If that's the case and you're open to using plugins just jump to the last paragraph. Otherwise, read on.

From Normal mode with the cursor on the first character of the word you could do...


Ctrl-O, from Insert, let's you enter one Normal mode command before returning to Insert.

f<Space> goes to the next space character on the line (after the word).

Problem with this is if the word is not followed by a space (e.g you are at the end of the line or it's followed by a punctuation mark). You'd need to adjust the Normal mode command (e.g. to f. or $<Left>).

That's just one example of how to accomplish this but I think rather than try to optimize a manual command you should use something more robust (but complicated) and put it in a mapping. For instance this substitution command:


That says take the cursor position (\%#) and any word characters surrounding it (both \w*) and replace with itself surrounded by quotes.

A Normal mode mapping for this:

:nnoremap <leader>q :%s/\<\w*\%#\w*\>/"&"<CR>

Now you've optimized things down to a key press or two...whatever the length of the mapping you choose.

What I'd really suggest, though, is that you just get the vim-surround plugin. Then you can easily wrap words (and more) with anything that you'd usually wrap words with (e.g. parens).

  • It might be worth adding word boundaries to the pattern
    – D. Ben Knoble
    Commented Dec 22, 2020 at 13:49
  • Possibly over-cautious (personally I'd probably prefer \S over \w) but done.
    – B Layer
    Commented Dec 22, 2020 at 14:00
  • Thanks a lot for all the details and explanation !
    – Makoto
    Commented Dec 22, 2020 at 15:39
  • 1
    @Makoto You're welcome. I'm tempted to ask why you accepted the other answer (which repeats some of this answer and adds details that can be found in the docs) but it's your right to do whatever you want with that designation so I'll instead just say, welcome to Vi and Vim SE.
    – B Layer
    Commented Dec 22, 2020 at 15:49
  • @B Layer both answers are exactly what I need to know (and provided even more information, which is pretty cool), I just wanted to help a little a newcomer (I still upvoted your answer)
    – Makoto
    Commented Dec 22, 2020 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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