gabogabans
gabogabans

Reputation: 3553

Select all text between quotes in VS Code?

I had to reinstall VS Code recently, I rember using Ctrl+W to kind of smart select everything between quotes but now what that command does is move me to another file/tab instead? Is there a way to do this in VS Code, Ctrl+W was just so easy to me, really helped with deleting or copying strings of text.

Upvotes: 30

Views: 40441

Answers (6)

colinD
colinD

Reputation: 2039

As @Mark says in the comment, you can use the "Expand Selection" shortcut. The first press will select the word to the right of the cursor. The second press selects everything between the quotes.

The shortcut on Windows by default:
Shift + Alt +

And OS X:
Ctrl + Shift + +

Upvotes: 32

Fullchee Zhang
Fullchee Zhang

Reputation: 691

Try using the Quick and Simple Text Selection extension.

On a Mac, the extension's default shortcut is k, ". This is a chord, so:

  1. Press and k then let go
  2. Press "

This will select everything in double quotes.

If you want to select everything in single quotes use k, '

It also works for brackets and back ticks

  • k, [
  • k, {
  • k, (
  • k, <
  • k, `

On Windows, replace with Ctrl

Upvotes: 23

Fullchee Zhang
Fullchee Zhang

Reputation: 691

After re-reading your question, I noticed that you want to press Ctrl + W to press multiple times to expand your selection

To see and set the shortcut, you can

  1. Press Ctrl/Cmd + Shift + P

  2. Go to Keyboard Shortcuts by typing Preferences: Open Keyboard Shortcuts

    enter image description here

  3. Search for the command: editor.action.smartSelect.expand

  4. Double click the keybinding to set a new keybinding

    enter image description here

Summary of answers

  • Most use cases: use @colinD's answer (Alt + Shift + or ) which expands the selection word by word
  • Press Ctrl + Shift + multiple times to expand the selection's scope
    • it might be different on Windows
  • If you want to select all of the text in quotes and there's a lot of spaces and your cursor is in the middle of the quotes

Upvotes: 5

Vess Bakalov
Vess Bakalov

Reputation: 29

The quick and simple text selection does not account for escaped quotes. So if you have "Hello "World"" and your cursor is on Hello, it will only select to the quote preceding World.

Upvotes: -1

Benji
Benji

Reputation: 310

The best / simplest way to do it I've found on Mac is to click the text anywhere in the quote marks, then hold down Control + Shift and tap the right arrow twice.

Upvotes: 13

some_random_guy
some_random_guy

Reputation: 79

Shift + Alt + (Right Arrow) for the word next to cursor Shift + Alt + (Right Arrow)x2 for entire sentence between quotes

Upvotes: 7

Related Questions