how do you select only the entire string in vscode?

Viewed 1810

I tried looking up this questions but they were for the entire line.

My question is for example let url = "https://robohash.org/hello.png?set=set4";

here, is there any shortcut to select only the url or basically anything enclosed between "". Is it possible?

3 Answers

AFAIK this is not possible without an extension. You can download Quick and Simple Text Selection, the use ctrl+k " shortcut.

If you're familiar with Vim, you can use the vim extension, and then click v i " to enter visual mode, and choose everything between double quotes


For the sake of completeness, vscode also includes a smart select option, which has the keyboard shortcuts ctrl+shift+right_arrow and ctrl+shift+left_arrow. The problem with it is it doesn't specifically select everything between double quotes, and in the case of a URL, it doesn't simply work as intended. If it's only a simple string, it would also select the double quotes in addition to the string between them

I just found a magical shortcut :)

For expand selection we can use shift + alt + ->

I had installed a stupid plugin before!

There is actually another expansion called expand_region with the ability to expand_region and undo_expand_region. The default keybindings are ctrl+w / shift+ctrl+w .

I find this one to be more convenient. It stops before and after " and it will work for the url-fetch scenario. What it doesn't do is to stop at a complete line (with and without indentation) which smart select seems to do. There are probably more differences that I don't know about.

Update: You have to press multiple times to expand further. For the example line in the original post this means 3 times. ctrl+w, ctrl+w, ctrl+w

let url = "https://robo[cursor-here]hash.org/hello.png?set=set4";
1. https://robohash.org/hello.png?set
2. https://robohash.org/hello.png?set=set4
3. "https://robohash.org/hello.png?set=set4"
Related