spinners
spinners

Reputation: 2689

Sublime text 2, ctrl+d not working as expected

It seems that 'quick add next' and 'expand selection to word' are both mapped to the same key binding.

I am not sure how to override/change the 'expand selection to word' because I cannot find the current key binding for both actions.

Does anyone know what the two actions are called?

Just to clarify, let's say I have the following block of code

this.GRID_TOP = 10;
this.GRID_SPACING = 10;
this.GRID_HEIGHT = 10;
this.GRID_WIDTH = 10;

I want to select the 'GRID' string on each line. I could use alt+F3 but that's overkill. I want to select 'GRID' then hit ctrl+D to select the subsequent matches. My problem is that it works once (selects first two) but then expands both cursors to the end of their words. Since the selections are now different, I cannot 'quick add next'.

Upvotes: 9

Views: 2445

Answers (2)

hsandt
hsandt

Reputation: 760

Bug conditions and effect

This seems to be a bug, or at least an unintuitive behaviour that only happens when the search bar is opened (after pressing ctrl+F, etc.) AND you selected a word part that is not already the string in the Find field (e.g. you searched for TOP before, and then you selected GRID).

The bug seems to be due to the specific behavior of find_under_expand while searching. In search mode, it will fill the Find field with the whole word under the caret on the first call, then starts finding and adding more occurrences to the selection. But it has some inconsistencies. For instance, if you click on different words one after the other, pressing ctrl+D after each click, and it will always fill the Find field with the word, but will alternatively not highlight the word and highlight it.

When you select a sub-word, it gets worse and only the next sub-word gets highlighted the first time you press ctrl+D. The following times, you get a mix of fill Find field, cursor goes to end of word and extend selection (a behavior that made sense on a single and complete word) which results in the selection of the first two words, with the second word (GRID_SPACING) filling the Find field.

Workaround

Solution 1

Close the search bar with esc and then use ctrl+D / Find > Quick Add Next repeatedly. Note that the selection won't be highlighted as searched strings (yellow in the default theme), but only as normal selection highlight (gray in the default theme).

Solution 2

If, after your first ctrl+D, you realized that your search bar was opened (and the Find field did not previously contain your target sub-word), it is not too late. Press ctrl+U / Edit > Undo Selection > Soft Undo to go back to the original sub-word selected. From here, use ctrl+D repeatedly. With the Find field containing the target sub-word, selection will behave as expected.

Upvotes: 10

roman
roman

Reputation: 61

Go to Preferences > Key Bindings - User

put following lines and save the file:

{ "keys": ["ctrl+d"], "command": "find_under_expand" },
{ "keys": ["ctrl+k"], "command": "find_under_expand_skip" },
{ "keys": ["ctrl+alt+d"], "command": "dpaste"}

It works for me. I've got installed DPaste package. That is why I had to overwrite its shortcut with the last line. Dpaste comes by default with ctrl+d

Hope it help

Upvotes: 5

Related Questions