169

How to select the current word, that is where the caret is at.

Note: I am looking for the shortcut for Visual Studio Code(VS Code), the text editor, and not Visual Studio IDE.

1
  • Why not Ctrl + mouse click? Why not a feature which covers this? Really, I cannot understand from which part of this world VSCode owners come from... they deserve a trophy for not covering such a basic text editor feature. So many stackoverflow posts around trying to workaround this, and they simply can't react. Shame on them for their incompetence. Ctrl+D is not a solution. Commented Jul 30 at 13:37

8 Answers 8

269

On Mac OS: Cmd+D
On Windows & Linux: Ctrl+D

Above solved the purpose for me.

But ⌘D is defined as "editor.action.addSelectionToNextFindMatch", so if you press it more than once, it will try to search and select same word in the file which then can be used to do "multi word editing".

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you! Now together with drag and drop I feel whole again!
This has the unfortunate side-effect of also changing the current "find" criteria.
search Add Selection To Next Find Match in hotkey search bar
this also does not select a whole sentece or string
70

You are looking for Shrink/Expand Selection.

Trigger it with Shift+ Alt+Left and Shift + Alt+Right

Update:

This is now called Smart select API. This feature uses semantic knowledge to intelligently expand selections for expressions, types, statements, classes, and imports.

8 Comments

This has unfortunate side-effect of also selecting the spaces around the word.
And it often selects more than just the word
Simply misleading, selects more than one word as it extends to, e.g., the surrounding parentheses.
I agree with Ctrl+D altering the "find" criteria, but I haven't found any of the caveats regarding this answer to be true. Have things changed? If not give examples please (I've found it selects the word within parentheses just fine).
Coming from Jetbrains editors (IntelliJ and PHPStorm), I find this closest to the Ctrl+W "select word" behavior, and maybe even a little better. Thanks!
|
22

If you want to ctrl+w to behave the same as in Idea just go keyboard settings enter image description here

Search for Expand selection. Set new shortcut cmd+w or ctrl+w depending on your OS. enter image description here Also re-bind other commands that use ctrl+w to use another shortcut that you want, for example cmd+f4

You can edit keybindings.json to avoid using UI. enter image description here

Comments

22

It is Ctrl + D that works for me in latest Visual Studio Code on Windows.

Go to File -> Preferences -> Keyboard shortcuts, you will find this:

enter image description here

1 Comment

This has the unfortunate side-effect of also changing the current "find" criteria.
13

Shift + Alt+Right Arrow if the word is in camelCase then you will have to click Right Arrow again to select the whole camelCase. Every time you press Right Arrow again while still holding Shift + Alt down you will select a further part of the code. so:

  1. first the word.
  2. then if it's part of a camelCase then the camelCase.
  3. then if it is in a string the whole string.
  4. ... (many other posibilities)
  5. the whole line.
  6. everything inside the parentheses code block
  7. the whole file

at any given time you can go back to the last selection by clicking Left Arrow instead of Right Arrow

I don't know about CTRL + w in the old Visual Studio Code but in the JetBrains IDE's this is the equivalent to CTRL + w by holding down CTRL and clicking w to select more and holding down CTRL + Shift and clicking w to unselect.

Another possibility which helps to avoid selecting only one word in camelCase is CTRL + d this will just select the whole camelCase. This will however have the side-effect of also changing the current "find" criteria.

thanks Chandan Nayak for this extra shortcut.

Comments

5

An unpopular opinion: you can now have Resharper keybindings, if you come from Jetbrain's camp.

The Ctrl+W expansion grow and shrinks is different from expansion selection.

Comments

2

On "File/Preferences/Keyboard Shortcuts" I deleted the shortcut "Ctrl + W" to close the current tab action, because for this "Ctrl+F4" works for me.

Update (14 days later): Yesterday I installed VSCode 1.34.0 - I think since then the functionality is "Ctrl + D". I was very suprised.

Comments

2

For any editor, you can use the below shortcuts. These shortcuts work for every text area also.

Ctrl + Shift + LeftArrow/RightArrow - this will select text word by word

Shift + UpArrow/DownArrow - this will select text line by line

Ctrl + BackSpace - this will delete text word by word

Additional

in intellijIdea Ctrl + w - use for the select current word, after giving second Ctrl + W it will select the second word also. Like that you can select the whole line.

Ctrl + d - you can duplicate current line.

1 Comment

CTRL + W (CTRL + SHIFT + W) closes VSCode on Windows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.