Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code 'Select word at caret' shortcut like in WebStorm IDE

WebStorm IDE has a very useful shortcut for selecting text by combination Ctrl + W;

It easy to put cursor for example to one of the arguments in function and press combination twice for select all arguments, first press will select one argument, second - all. And then if you press again, IDE will select all function.

function foo(a, b, c) {}
  • first press: selected b (for example)
  • second: selected a, b, c
  • third: selected function foo(a, b, c) {}

Summarise, selection increases depending on number of presses shortcut.

VS Code has shortcut Ctrl+D which can select only one argument.

Does anyone know how to add smart selection like in WebStorm to VS Code?

like image 669
rossoneri Avatar asked Jan 25 '17 17:01

rossoneri


2 Answers

As a comment suggested I tried out https://marketplace.visualstudio.com/items?itemName=k--kato.intellij-idea-keybindings

However, the only real bind that I wanted was the grow and shrink selection commands. That extension will overwrite a lot of the default VScode keybinds. To get just the grow and shrink selections, edit your keybindings.json file adding the following lines:

{
  "key": "ctrl+w",                
  "command": "editor.action.smartSelect.grow",
  "when": "editorTextFocus" 
},
{
  "key": "ctrl+shift+w",
  "command": "editor.action.smartSelect.shrink",
  "when": "editorTextFocus"
}

*edit: Using version 1.26.1

like image 161
Watersdr Avatar answered Oct 17 '22 14:10

Watersdr


This is possible without an extension with the command "Expand select", editor.action.smartSelect.grow, which by default is "ctrl+shift+cmd+right"

like image 44
Rob Lourens Avatar answered Oct 17 '22 16:10

Rob Lourens