Just_Mad
Just_Mad

Reputation: 4075

How do I skip a match when using Ctrl+D for multiple selections in Sublime Text 2?

I have some code like:

testVar = { a: 1 };
testVariable1 = 2;
var c = testVar.a + testVariable2;
var d = testVar;

I want to rename "testVar" variable. When I set multiple cursors with Ctrl+D and edit variable, "testVariable" is also selected and edited.

Is there a way to skip some selections while setting multiple cursors with Ctrl+D?

Upvotes: 228

Views: 55656

Answers (7)

dayanbeni
dayanbeni

Reputation: 11

what worked for me was using ctrl+D to add a new selection and ctrl+U to remove the last selection Hope it helped

Upvotes: 0

Artur Carvalho
Artur Carvalho

Reputation: 7167

I think I get why it was confusing to me: This is not skipping, it's unselecting.

You hit Ctrl+D as usual and if you select one by mistake you do Ctrl+K, D where you first press the K and then the D without letting go the Ctrl. This unselects the selection.

Upvotes: 3

bevo009
bevo009

Reputation: 523

Updated answer for vscode in 2020 on windows, in keybindings.json add this line to skip the next selected occurrence easily:

  {
    "key": "ctrl+alt+d",
    "command": "editor.action.moveSelectionToNextFindMatch",
    "when": "editorFocus"
  },

*yes I know the question is for sublime text, but I found it by googling the same question + vscode, so it might help someone since the mappings are identical.

Upvotes: 11

n1nj4
n1nj4

Reputation: 526

Place curser before the variable, do not select the variable, hit Ctrl+D to select every occurence of the variable, not pattern.

Upvotes: 13

SUB0DH
SUB0DH

Reputation: 5240

You can press Ctrl+K and Ctrl+D at the same time to skip a selection. If you went too far with your selection, you can use Ctrl+U to return to a previous selection.

Note: Replace Ctrl with Cmd for Mac OS X.

The default configuration for this can be viewed by going to Preferences > Key Bindings-Default in the application menubar, where you will see something like this:

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

If you want, you can configure the keys as per your needs, by going to Preferences > Key Bindings-User and copy the above code and then change the keys.

Upvotes: 100

Romain
Romain

Reputation: 6430

Just use Ctrl+K, Ctrl+D.

(for OS X: Cmd+K, Cmd+D)

Needs a bit of practice, but gets the job done!

Upvotes: 316

Atomicflare
Atomicflare

Reputation: 773

If you have the cursor over the word and use Ctrl + D to select the word. The next time you hit Ctrl + D it should select the next highlighted word.

If you double click to select word, Ctrl + D will select the exact string not just the highlighted ones.

In other words, Ctrl + D with nothing highlighted does whole-word search. If you have something highlighted already, Ctrl + D will do substring searching.

I have tested and it works in Sublime Text 2 Version 2.0.1, Build 2217.

Upvotes: 66

Related Questions