226

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?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Just_Mad
  • 4,029
  • 3
  • 22
  • 30
  • This applies to VS Code as well, which purposely tried to mimic Sublime behavior for multiple cursors. – John Y Aug 12 '22 at 17:38

6 Answers6

308

Just use Ctrl+K, Ctrl+D.

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

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

skywinder
  • 21,291
  • 15
  • 93
  • 123
Romain
  • 6,322
  • 3
  • 35
  • 40
  • 6
    @Qwerty: Alt+F3 Selects all occurrences. – Emil Stenström May 17 '14 at 15:16
  • 24
    @Romain wrote "Needs a bit of practice". I think what that means is that it could be more intuitive. Don't press the key combo until what you want to skip is highlighted. E.g. if you have 3 matches, and you want to skip the 2nd, first highlight the 1st, press CTRL+D to highlight the 2nd, THEN press the key combo to skip the 2nd match and highlight the 3rd. Help? – Tyler Collier Oct 09 '14 at 23:02
  • 1
    Add this to user keymap and shorten the practice time to nearly 0! `{ "keys": ["ctrl+alt+d"], "command": "find_under_expand_skip" }` – Mrchief Oct 07 '15 at 17:51
  • 2
    Updated answer, in keybindings,json add this line: { "key": "ctrl+alt+d", "command": "editor.action.moveSelectionToNextFindMatch", "when": "editorFocus" }, – bevo009 Jan 26 '20 at 00:41
99

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.

SUB0DH
  • 5,130
  • 4
  • 29
  • 46
65

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.

Benjamin Hodgson
  • 42,952
  • 15
  • 108
  • 157
Atomicflare
  • 763
  • 6
  • 5
  • 13
    This is actually the only true solution to this problem. People are upvoting brainlessly. – Qwerty May 05 '14 at 10:27
  • `ctrl`+`D` **with nothing selected** is **Case sensitive** too. – venkatvb Jun 04 '15 at 09:18
  • 2
    @vankatvb I'm not finding that to be true... `Ctrl`+`D` with nothing selected is still case-insensitive to me. It'll outline only case-sensitive matches, but actually using the shortcut or `Alt`+`F3` will select those that don't match case. – Schism Aug 17 '15 at 15:00
  • Btw here's the same answer in another question: http://stackoverflow.com/a/18422707/782045 – interestinglythere Sep 29 '16 at 18:44
  • 1
    @Qwerty it is not the "only true solution", it is as much of a solution as `ctrl-k ctrl-d`. Both have their use case. This answer, for example, is not useful when the search string is not surrounded by whitespace. Randomly calling people brainless is not very helpful either. – phil294 Apr 17 '21 at 21:14
  • 1
    @phil294 Back in the day I was a different person. I wish I could change the comment now. – Qwerty Apr 19 '21 at 09:53
13

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

AlessioX
  • 3,167
  • 6
  • 24
  • 40
n1nj4
  • 511
  • 5
  • 13
11

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.

bevo009
  • 463
  • 5
  • 9
2

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.

Artur Carvalho
  • 6,901
  • 10
  • 76
  • 105