Multiple select in Visual Studio?
Asked Answered
L

17

188

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++.

Lindblad answered 11/5, 2013 at 9:36 Comment(5)
Are you asking about Visual Studio 2012 or Notepad++?Scheldt
@Scheldt I thought it was obvious the question is about VS (included in the title as well). The thing about Notepad++ was a bonus question.Lindblad
As far as I know, this is not possible in either.Scheldt
For Notepad++: https://mcmap.net/q/137080/-notepad-multi-editingMenke
Depending on what you want to do with the selection, you may be able to achieve the end result with a regex/string search.Dysgenics
B
313

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

Businesswoman answered 25/8, 2018 at 7:47 Comment(9)
I don't see these options using 2017 ver 15.9.3Portsalut
Seems that in 15.9.3 the commands in the menu are just the first two.Businesswoman
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.Albino
@Albino or like sublime. The way it is currently supported is of no use to me.Tenorio
The default keyboard shortcut is Ctrl+Alt+SelectMenke
for mac users it's Cmd+D (code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf)Quiteris
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.Ha
I think the combinations are too short, they should require us to press 5 keys simultaneously to do basic mundane tasks.Sclerotic
You might need to reset your keyboard shorts back to default btw in case this isn't working for you.Urien
C
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

Contentious answered 10/1, 2018 at 10:38 Comment(5)
Perfect! This is the one. Multi selection and caret work very well. Tested with VS Community 2017.Gamache
@Gamache yes this extension is great. Consider giving it a good review and/or starring the GitHub project if you find it useful.Contentious
Thank you for finding this extension! MixEdit was working but it wasn't optimized for VS2017 and that trialware popup was anti-productive.Nathan
Didn't work for me. welp, I don't know what I was expecting from ms.Apraxia
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: learn.microsoft.com/en-us/visualstudio/ide/…Claybourne
S
58

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

Stalinsk answered 30/11, 2018 at 7:17 Comment(3)
Thank you for your answer kind internet user.Portsalut
great answer. We just needed the commands. I dn why everyone gave such long answers, lol. thanksAmnesty
Thanks for the hint to just switch to the VS Code mappings.... CTRL+D is one of my most used shortcuts in VS Code, happy to use it in VSImminence
C
34

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.

Control answered 12/10, 2019 at 13:51 Comment(2)
Shift + Alt + .Durham
The name of the command is Edit.InsertNextMatchingCaret. In case anyone want to find and bind it to a different key combExpeditionary
C
23

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

Cyanic answered 1/12, 2014 at 18:28 Comment(10)
If you're seeking something like Sublime text, this is it!Pentahedron
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!Lindblad
I can't purchase a MixEdit license anymore. Check the website. Any idea how I can license it somehow and get rid of the annoying popup?Adowa
this extension is not free!!Semiaquatic
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 itEadmund
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 buyEadmund
Check out this free alternative to MixEdit that was released recently, and is open source.Contentious
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? ---------------------------Whey
No longer available, author took down the page on the VS marketplace.Dania
Select Next Occurrence works and is open source.Bricklaying
Z
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/

Zoophobia answered 5/9, 2018 at 15:41 Comment(0)
M
8

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.

Mic answered 3/3, 2016 at 4:5 Comment(1)
and now you can't even buy it. it just pops up the alert box asking for licenseEadmund
S
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

Sanorasans answered 12/10, 2017 at 18:26 Comment(3)
You sure you are not talking about VS Code?Lindblad
Yes, I am... Should I delete it or just title as "for vs code"? I was looking for code when I got hereSanorasans
no need to delete, will be useful for others. Just mention it in answer.Lindblad
L
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).

Lindblad answered 11/5, 2013 at 10:41 Comment(0)
M
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

Matter answered 23/10, 2013 at 4:36 Comment(2)
This extension doesn't support multiple selections, as requested in the original question. The MixEdit extension does.Excommunication
MixEdit didn't exist when the OP posted his question. I answered to the best of my knowledge.Matter
C
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

Chinchin answered 23/2, 2020 at 7:54 Comment(0)
S
6

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.

Savitt answered 28/3, 2022 at 10:57 Comment(0)
A
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

Ant answered 27/7, 2019 at 22:41 Comment(0)
N
4

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.

Nereen answered 4/1, 2023 at 8:59 Comment(0)
D
1

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

enter image description here

Denby answered 31/7, 2022 at 9:36 Comment(0)
G
0

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

Gereron answered 29/10, 2016 at 8:37 Comment(1)
how to install in visual studio 2015?Semiaquatic
N
-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).

Ninepins answered 29/5, 2021 at 23:19 Comment(1)
the question is for visual studioUnstable

© 2022 - 2024 — McMap. All rights reserved.