Sidharth Bajpai
Sidharth Bajpai

Reputation: 352

Is there any keyboard shortcut to select/copy the auto highlighted text in VS Code?

When I place my cursor at any position inside a text like the string in this photo, vs code automatically mildly highlights the entire string. Is there any shortcut key for selecting and copying this entire text highlighted by vs code? Example: String being mildly highlighted by vs code How to select/copy this with a keyboard shortcut?

Update: Added gif to show the highlighting - gif showing the highlighting

Upvotes: 0

Views: 2562

Answers (2)

jsejcksn
jsejcksn

Reputation: 33701

There's not a single, builtin keyboard shortcut for the behavior you described, but you can use a combination of two to achieve the result you want:

The first is called "Expand Selection" in the VS Code app, and the online keybindings documentation describes it as "Expand AST Selection" (editor.action.smartSelect.expand). The default platform keybindings for this are:

  • linux: shift + alt + right
  • mac: shift + ctrl + cmd + right
  • win: shift + alt + right

If the highlighted string is one word, it will require one use, and if the string is multi-word, it will require two uses.

After that, the selection will be complete, and you can simply copy (cmd/ctrl + c).

Demo:

enter image description here

Upvotes: 2

Mark
Mark

Reputation: 180765

If in a string, triggering the command editor.action.smartSelect.grow a couple of times should select that entire string. And then you can copy the normal way Ctrl+C.

That command is unbound by default. You can assign a keybinding to it in the Keyboard Shortcuts editor by searching for smartSelect and click on the little pencil icon next to the command.

Upvotes: 1

Related Questions