How to select variables (not text) with the same n

2019-02-13 20:45发布

问题:

When selecting variable f, the editor highlights other occurrences of the variable. So far so good, but when trying to add them to the selection list with Ctrl+D, it also adds f as it occurs in the code as regular text. I can skip this with Ctrl+K, but if the editor already identifies f as a variable, then it can surely also just select variables? This option is not in the menu.

Take this JavaScript snippet.

f=function(){};
f();

When selecting the first f, it also highlights f in f(), but not f in function.
When multi-selecting with Ctrl+D it does select it though.

回答1:

It's a bug. The post also has the workaround.

Rather than selecting the variable, just put the cursor left to it, and press Ctrl+D. This will also select it, but only other variables (or what the editor recognises as variables, based on word boundaries) on subsequent Ctrl+D presses.



回答2:

You can modify the word_separators option to not include your variable prefix (i.e. $ for PHP) so when you double-click a variable name, it will select $ as well.

This option is located in the file Preferences.sublime-settings in your Default folder. I recommend adding the modified setting to Preferences.sublime-settings in your User folder rather than changing the defaults.

"word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?"


Edit:

Unfortunately, currently there's no way to do a Find & Replace within a certain scope. The issue has been raised here, and you can vote for it as a feature request on Sublime's UserEcho forum.