Visual Studio Surround Code with

I cannot find any way to surround the selection with something in VS code.

For example, by doing something like this: text => "text" simply by selecting the word text and the enter key "

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

Having selected all these words:

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

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

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

If anyone has an idea.

Thanks.

+34
source share
6 answers

Selecting text and pressing " already works in VSCode to surround a single element and also works for multi-line selections.

NOTE : language dependent . The language syntax should define opening and closing curly braces, for example. quotes, braces, etc. Thus, this will not work in a β€œplaintext” file, for example. Change your language mode to CTRL + SHIFT + P and type Change Language Mode ENTER and select something like JavaScript where it is supported.

What you need is actually not that effective. It is best to use multicursors.

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

Then just type " , then END , then " and all your lines are surrounded by quotation marks.

Note. To check if you have a key restriction and what it is, you can always press CTRL + SHIFT + P and type Add Cursor Below , and if there is a binding to it, it will be displayed on the right of this text.

+32
source

Maybe you can try this extension, you can write your own wrappers:

https://marketplace.visualstudio.com/items?itemName=yatki.vscode-surround

A simple but powerful extension for adding wrapper patterns around blocks of code.

Features

  • Supports multi selection
  • Fully customizable
  • Custom wrapper functions
  • You can assign shortcuts to each wrapper function separately
  • Nicely formatted

Demo 1: Selecting a Shell Function from the Quick Selection Menu

Demo 1

Demo 2: Packing Multiple Items

Demo 2

+8
source

In VS Code, hold Ctrl + Shift + P then write: "> Settings: Open keyboard shortcuts"

Select keybindings.json to edit. In the area that you are allowed to change, paste this in brackets:

 { "key": "cmd+p", "command": "editor.action.insertSnippet", "when": "editorTextFocus", "args": { "snippet": "\"${TM_SELECTED_TEXT}\"" } } 

** note that in this example the "key" is set to "cmd + p", you can change the "key" to whatever you prefer

+5
source

This extension also exists if you want a custom volumetric volume with text.

https://marketplace.visualstudio.com/items?itemName=sifue.surrounding .

I just installed it and worked great on it

+3
source

Using the suggestion of Yuri Aps, I added the following JSON file to keybindings.json. This provides the functionality requested by Ronan Lamour for any type of file and does not require an extension. It works for single or multiple selections when using single or double quotes. This is useful from Sublime, as it reproduces the functionality that Sublime provides natively.

 { "key": "'", "command": "editor.action.insertSnippet", "when": "editorHasSelection || editorHasMultipleSelections", "args": { "snippet": "'${TM_SELECTED_TEXT}'" } }, { "key": "shift+'", "command": "editor.action.insertSnippet", "when": "editorHasSelection || editorHasMultipleSelections", "args": { "snippet": "\"${TM_SELECTED_TEXT}\"" } }, 
+3
source

I came from (neo) vim, switching to VS Code, and used Tim Pap a wonderful vim-surround plugin for vim. I found the port of this plugin for VS Code. This is very useful and incredibly effective when you recognize the shortcuts, in my opinion!

References:

If you use vim or vim bindings in VS Code, please enjoy!

Edit: The VSCodeVim plugin enables the surround function automatically, so if you have this plugin installed, you really don't need vscode-surround .

+2
source

Source: https://habr.com/ru/post/1015136/


All Articles