177

Is there a way to select multiple non-adjoining (totally separate) texts in VS? I can do it in MS Word by selecting the texts separately by holding the Ctrl button, like this:

enter image description here

My version is 11.

Edit: I'm not talking about Alt+Select block selection. Also I would love to see if there exist a technique in Notepad++.

mavis
  • 3,100
  • 3
  • 24
  • 32
nawfal
  • 70,104
  • 56
  • 326
  • 368

17 Answers17

285

Multi cursor edit is natively supported in Visual Studio starting from version 2017 Update 8. The following is an extract of the documentation:

  • Ctrl + Alt + click : Add a secondary caret
  • Ctrl + Alt + double-click : Add a secondary word selection
  • Ctrl + Alt + click + drag : Add a secondary selection
  • Shift + Alt + . : Add the next matching text as a selection
  • Shift + Alt + ; : Add all matching text as selections
  • Shift + Alt + , : Remove last selected occurrence
  • Shift + Alt + / : Skip next matching occurrence
  • Alt + click : Add a box selection
  • Esc or click : Clear all selections

Some of those commands are also available in the Edit menu:

Multiple Carets Menu

Gian Marco
  • 22,140
  • 8
  • 55
  • 44
  • 1
    I don't see these options using 2017 ver 15.9.3 – Urasquirrel Dec 19 '18 at 17:40
  • Seems that in 15.9.3 the commands in the menu are just the first two. – Gian Marco Dec 20 '18 at 07:22
  • 3
    I wonder if they are ever going to make *proper* multi-caret support like JetBrains already has for years. Try to make a couple of carets, select a word, and then copy-paste it. VS pastes double (i.e. it pastes the entire selection done with both carets per each caret. I can't imagine when this would ever be a desirable behavior. They should paste it just once. Also, JetBrains has the CTRL+CTRL shortcut, which enables adding carets when pressing the down or up arrows (indefinitely, while CTRL is pressed). It's just so much more productive than VS' implementation at this point. – obe Sep 29 '19 at 00:44
  • @obe or like sublime. The way it is currently supported is of no use to me. – shashwat Nov 16 '19 at 06:20
  • The default keyboard shortcut is `Ctrl+Alt+Select` – Malcolm Feb 26 '20 at 17:19
  • for mac users it's Cmd+D (https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf) – S Q Mar 04 '20 at 16:03
  • What's the difference between `Shift+Alt+Down` and `Shift+Alt+.` commands? Both seemingly create multiple carets, but the former disappears when I try to move them, and the latter persists. – rustyx Mar 18 '21 at 22:29
  • I think the combinations are too short, they should require us to press 5 keys simultaneously to do basic mundane tasks. – Max Yari Apr 24 '21 at 17:32
  • You might need to reset your keyboard shorts back to default btw in case this isn't working for you. – Anon May 04 '22 at 13:21
75

There is a new extension for Visual Studio 2017 called SelectNextOccurrence which is free and open-source.

This extension makes it possible to select next occurrences of a selected text for editing.

Aims to replicate the Ctrl+D command of Sublime Text for faster coding.

Features:

  • Select next occurrence of current selection.
  • Skip occurrence
  • Undo occurrence
  • Add caret above/below
  • Use multiple carets to edit (Alt-click to add caret)

Visual Studio commands:

  • SelectNextOccurrence.SelectNextOccurrence is bound to Ctrl+D by default.
  • SelectNextOccurrence.SkipOccurrence is not bound by default. (Recommended Ctrl+K, Ctrl+D)
  • SelectNextOccurrence.UndoOccurrence is not bound by default. (Recommended Ctrl+U)
  • SelectNextOccurrence.AddCaretAbove is not bound by default. (Recommended Ctrl+Alt+Up)
  • SelectNextOccurrence.AddCaretBelow is not bound by default. (Recommended Ctrl+Alt+Down)

SelectNextOccurrence options

https://marketplace.visualstudio.com/items?itemName=thomaswelen.SelectNextOccurrence

https://github.com/2mas/SelectNextOccurrence

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • 1
    Perfect! This is the one. Multi selection and caret work very well. Tested with VS Community 2017. – Dave Jan 30 '18 at 04:15
  • 1
    @Dave yes this extension is great. Consider giving it a good review and/or starring the GitHub project if you find it useful. – Drew Noakes Jan 30 '18 at 10:23
  • Thank you for finding this extension! MixEdit was working but it wasn't optimized for VS2017 and that trialware popup was anti-productive. – Bill N. Feb 14 '18 at 13:44
  • Didn't work for me. welp, I don't know what I was expecting from ms. – Bersan Nov 11 '18 at 21:45
  • Great solution, just to note I also had to remove the default key bindings from `Edit.Duplicate` as they were still being honored even when adding `Ctrl+D` to the keybinding for `SelectNextOccurrence`. VS 2019 Default Shortcuts: https://learn.microsoft.com/en-us/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio?view=vs-2019 – Brandon Franklin Aug 08 '19 at 14:31
54

In the Visual Studio Shift+Alt+. / Shift+Alt+,

  • Shift+Alt+. - match caret;
  • Shift+Alt+, - remove previous caret;

Same function as on VSCode Ctrl+D.

Much more setting Tool - Options - Environment - keyboard. Next in the Show commands containing enter Edit..

Also, can use keyboard schema Visual Studio Code. Available for Visual Studio 2017

For conclusion, nice link Visual Studio All keyboard shortcuts

orad
  • 15,272
  • 23
  • 77
  • 113
33

In Visual Studio 2019, you can put your caret on the right place and then press SHIFT ALT and . (dot). This will select the next occurrence.

Trausti Thor
  • 3,722
  • 31
  • 41
23

MixEdit extension for Visual Studio allows you to do multiediting in the way you are describing. It supports multiple carets and multiple selections.

James Skemp
  • 8,018
  • 9
  • 64
  • 107
robertojj89
  • 271
  • 2
  • 2
  • 8
    If you're seeking something like Sublime text, this is it! – Kenial Dec 13 '14 at 20:28
  • 2
    In case somebody is wondering, the way to achieve multi-selection in MixEdit is by double clicking on words after pressing `Alt`. The same as in MS Word, except it is `Alt` here instead of `Ctrl`. MixEdit also has a lot of other useful multi-select options. Bear in mind it's free only for evaluation! – nawfal Jun 05 '15 at 04:57
  • 2
    I can't purchase a MixEdit license anymore. Check the [website](http://www.codinglabs.net/BuyMixEdit.aspx). Any idea how I can license it somehow and get rid of the annoying popup? – vullnetyy Mar 02 '17 at 11:57
  • 3
    this extension is not free!! – Diogo Cid Mar 31 '17 at 13:57
  • 2
    it's great but not free and popping up annoying dialog every few times you use it. that dialog can't even be cancelled with escape so have to use mouse which is painful. paying for it is now "suspended" so can't really use it – Sonic Soul Apr 26 '17 at 17:48
  • 6
    are there any alternatives that are free or with ability to buy so you don't have to get that annoying alert ? or ability to remove it from MixEdit if there is no way to buy – Sonic Soul Apr 26 '17 at 18:06
  • 1
    Check out [this free alternative to MixEdit](https://stackoverflow.com/a/48185483/24874) that was released recently, and is open source. – Drew Noakes Jan 10 '18 at 10:40
  • Visual studio 2017 says: --------------------------- This extension is not compatible with Visual Studio 2017. Installation may cause Visual Studio to be unstable. Do you want to continue? --------------------------- – Myster Feb 15 '18 at 02:42
  • No longer available, author took down the page on the VS marketplace. – jValdron Apr 19 '18 at 15:45
  • 1
    [Select Next Occurrence works](https://marketplace.visualstudio.com/items?itemName=thomaswelen.SelectNextOccurrence) and is open source. – Nick M Jun 07 '18 at 03:08
20

From Visual Studio 2017 Version 15.8, Ctrl + Alt + Click is now supposed to be a built-in way to manage multiple carets.

https://blogs.msdn.microsoft.com/visualstudio/2018/08/30/improving-your-productivity-in-the-visual-studio-editor/

Éric Bergeron
  • 620
  • 6
  • 7
9

Just to note,

MixEdit is not completely free.

"This software is currently not licensed to any user and is running in evaluation mode. MIXEDIT may be downloaded and evaluated for free, however a license must be purchased for continued use."

Upon installation and use, a popup redirects to webpage - similar to SublimeText's unlicensed software pop-up message.

SM23
  • 419
  • 6
  • 12
7

For Visual Studio Code

Got to this question because I was looking for a way to select multiple words with mouse click on VS Code, which should be achieved by using alt+click, but this keybinding wasn't working (I think it is something related to my OS, Ubuntu).

For anyone looking for something similar, try changing the key to ctrl+click.

Go to Selection > Switch to Ctrl+Click for Multi Cursor

Community
  • 1
  • 1
jpenna
  • 8,426
  • 5
  • 28
  • 36
6

I couldn't find anything built in, which is sad. There is this functionality in CodeRush though.

With Notepad++, this feature comes in built in. Just turn on multi-editing from

Setting > Preferences > Editing > Multi-Editing Settings

But its not as intuitive as MS Word which lets you select two words by double clicking on them (after Ctrl of course).

nawfal
  • 70,104
  • 56
  • 326
  • 368
6

Update: MixEdit extension now provides this ability.

MultiEdit extension for VS allows for something similar (doesn't support multiple selections as of this writing, just multiple carets)

Head over to Hanselman's for a quick animated gif of this in action: Simultaneous Editing for Visual Studio with the free MultiEdit extension

James Skemp
  • 8,018
  • 9
  • 64
  • 107
Mrchief
  • 75,126
  • 20
  • 142
  • 189
  • 1
    This extension doesn't support multiple selections, as requested in the original question. The [MixEdit extension](http://stackoverflow.com/questions/16495727/multiple-select-in-visual-studio#answer-27234819) does. – mcw Apr 21 '15 at 20:28
  • 2
    MixEdit didn't exist when the OP posted his question. I answered to the best of my knowledge. – Mrchief Apr 21 '15 at 20:32
6

in visual 2019, Open Options to show all enter image description here

and multi select: keep Ctrl + Alt then click position you want or, keep Shift + Alt then click position to multi select multi line from start to end line clicked

Quan Tran Hai
  • 61
  • 1
  • 3
4

There is supposedly a way to do it now with Ctrl + Alt + Click but I use this extension because it has a bunch of other nice features that I use: https://marketplace.visualstudio.com/items?itemName=thomaswelen.SelectNextOccurrence

Ben Rauzi
  • 564
  • 4
  • 13
3

I'm not sure if this is a available for earlier versions, but using Visual Studio 2022 Community Edition, there is the option to convert the keyboard setup to match Visual Studio Code.

Head into Tools > Options > Environment > Keyboard, then drop down the Apply the following additional keyboard mapping scheme: list and select Visual Studio Code.

Keyboard settings - Visual Studio 2022 Community

Note that this initialises the basic keyboard setup for VS Code, so any changes that you've made in your personal VS Code editor won't be included; you'll need to set these up yourself.

While this doesn't directly answer the OP's question, it does give a commonality between editors, and I do much prefer the VS Code keyboard setup (with tweaks) to the Visual Studio's.

Paul
  • 4,160
  • 3
  • 30
  • 56
3

In Visual Studio 2022, it's the Edit.InsertNextMatchingCaret, as you can see in this sreenshot :

Click to see the sreenshot

I am familiar with Visual Studio Code, so I applied the Ctrl + D. You must choose Text Editor.

Soufian
  • 51
  • 3
2

For mac users using visual studio code CMD+D works like a charm

enter image description here

codeaprendiz
  • 2,703
  • 1
  • 25
  • 49
0

Now the plugin is Multi Line tricks. The end and start buttons broke the selection.

franca
  • 5
  • 1
-3

For multi-select, you can use CTRL-SHIFT-L. You can click over the word and then press key combinations(CTRL-SHIFT-L) this will select all same types of words from the file(vs-code).