'Selecting block of code in Visual Studio Code
Is there a keyboard shortcut or an extension that would allow me to select a block of code?
I'd like to select everything between curly braces, between HTML tags, etc.
Solution 1:[1]
On Mac Ctrl + Shift + ? to expand the selection. Press multiple times to expand to the block.
Solution 2:[2]
Use Alt + Shift + ? to expand the selection between braces or tags.
Use Alt + Shift + ? to shrink the selection between braces or tags.
Here is the Microsoft Visual C++ shortcuts cheatsheet that might help you.
Update 2019/3: this inner functionality of Visual Studio is not working very well after some updates. Alt + Shift + ? now selects things including braces (which annoys me).
It is not like its behavior before. It selected things between curly braces, when I first posted this answer. I'm using Mark's answer now.
If anyone has a better solution (without an extension) now, please leave a comment.
Solution 3:[3]
Try the expand-region extension. It currently works for JavaScript and HTML. To select ever-increasing or decreasing scope.
Solution 4:[4]
A quicker way is selecting a line then expanding the selection like this:
- Select line
Ctrl + L - Expand selection
Alt + Shift + ?
Doing this inside a block (HTML element, JavaScript curly braces) will select the inner block (HTML element content, inside curly braces). Do step 2 again to select block including the container (HTML element, whole function, class, etc.)
Solution 5:[5]
In VS Code, there is a new option called Balance. First you can place the cursor suitable block. After that, you can press ctrl+shift+P
and type balance
and it list like below.
Now press Enter
, It will select the related code block like below.
For simple use, you can add a shortcut key binding.
Solution 6:[6]
If you are using Java in Vscode and you don't want your block selection to include the brackets (Or any other peripheral char) than do the following:
• Go to vscode settings by pressing ctrl + ,
.
• Search for "Java selection range" and deselect it.
Solution 7:[7]
For anyone looking for a real working solution!
Search for Select to Bracket
and bind it to whatever keys you like.
It is like magic.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Anh Tran |
Solution 2 | |
Solution 3 | Peter Mortensen |
Solution 4 | |
Solution 5 | Supun Sandaruwan |
Solution 6 | Julian Dave |
Solution 7 | Kevin Kreps |