Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select the whole variable name including $ in Visual Studio Code in PHP?

I am using the latest version of Visual Studio Code and I am using the PHP programming language. I am selecting a variable but it only selects the variable name, not the $ symbol.

By default it selects like this:

Selection of variable name without dollar sign

But I want it like this:

Selection of variable name with dollar sign

Is there any setting that enables this behavior?

Any information on this would be greatly appreciated. Thanks!

like image 936
Tejas Mehta Avatar asked May 01 '19 05:05

Tejas Mehta


People also ask

How do you select all names in VS Code?

Ctrl+D selects the word at the cursor, or the next occurrence of the current selection. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text.

How do you select multiple variable names in VS Code?

Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.

How do you select the whole string or code?

You can download Quick and Simple Text Selection, the use ctrl+k " shortcut. Show activity on this post. There is actually another way to expand selection which is called expand_region and undo_expand_region . Their default keybindings are ctrl+w / shift+ctrl+w .


Video Answer


2 Answers

The best way is to edit the VsCode settings.json and specify it for the PHP language. You can open it typing VsCode command:

Preferences: open settings (JSON)

And specify inside the "editor.wordSeparators" setting for your language removing the '$' symbol:

"[php]": {   "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?" } 
like image 183
David Folch Agulles Avatar answered Sep 19 '22 01:09

David Folch Agulles


You need to remove the $ symbol from the editor.wordSeparators directive. This is the default value:

// Characters that will be used as word separators when doing word related navigations or operations. "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?", 

You can make this language specific if you want, so it only applies to PHP.

like image 27
Álvaro González Avatar answered Sep 19 '22 01:09

Álvaro González