Visual Studio Code Surround With

Ronan Lamour picture Ronan Lamour · Feb 21, 2017 · Viewed 48.2k times · Source

I can't find any way to surround a selection with something in VS Code.

For example doing something like that : text => "text" just by selecting the word text and typing key "

Another example with the following text : mon tue wed thu fri sat sun

By selecting all of theses words :

mon| tue| wed| thu| fri| sat| sun|

and typing " I would like to perform something like this :

"mon" "tue" "wed" "thu" "fri" "sat" "sun"

If someone have any idea.

Thanks.

Answer

MartinSGill picture MartinSGill · Feb 21, 2017

Selecting some text and pressing " already works in VSCode to surround a single item, and works for multi-line selections as well.

NOTE: this is language dependent. The language syntax must define opening and closing braces, e.g. quotes, braces, etc. So this will not work in a "plaintext" file, for example. Change your language mode with CTRL+SHIFT+P and type Change Language Mode ENTER and select something like JavaScript where this is supported.

What you are after though is not really that efficient like that. Your best bet is to use multi-cursors.

Place the cursor at the start of the first line, press CTRL+ALT+DOWN to add another cursor below on the next line. Keep doing that until you have a cursor in front of all your words.

Then just type " then END then " and all your lines are surrounded by quotes.

NB: To check if you have a key bound, and what it is, you can always press CTRL+SHIFT+P and type Add Cursor Below and if there's a keybinding it will show to the right of that text.