Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# ASP.NET MVC Basics Modeling and Presenting Data Using the Visual Studio Debugger

Daniel Breen
Daniel Breen
14,943 Points

Set Multiple Cursors in Visual Studio 2015

James,

These videos are awesome. I noticed that you're really good about using shortcuts/quick ways to accomplish things.

One of my frustrations with Visual Studio is that it doesn't seem like there's a built-in way to set multiple cursors/select multiple words.

For example, let's say forgot to add a method to the end of an object in 3 places. In VS Code, I would just hold ALT, click the three locations, then type my method and it would type in all three places.

I've found an extension called MixEdit that will do this for me, but it's asking me to buy a license. That's a little ridiculous to me, but it is what it is.

Can you recommend an extension or method of implementing this feature? Or maybe a more efficient, built in approach?

James Churchill Are you aware of anything for multi-cursor support similar to what sublime text offers?

James Churchill
James Churchill
Treehouse Teacher

Daniel,

Great question!

Shift+Alt+ArrowUp or ArrowDown will extend your cursor to the consecutive lines above or below your current line, though the cursors have to be aligned :(

I would check out the free Multi Edit Mode VS Extension from Mads Kristensen: https://visualstudiogallery.msdn.microsoft.com/2beb9705-b568-45d1-8550-751e181e3aef

Mads works for Microsoft on the Visual Studio team and is responsible for an incredible number of VS extensions.

https://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=User&f%5B0%5D.Value=Mads%20Kristensen

Thanks ~James

1 Answer

Steven Parker
Steven Parker
229,744 Points

:point_right: Why not just copy and paste?

You could add the code to the first location, then highlight and copy. Then, as you click on each of the remaining locations, just type control-V to paste it in.

Daniel Breen
Daniel Breen
14,943 Points

That's not a bad solution. However, let's say you used the wrong word. "Oh shoot! I typed 'ulong' instead of 'long'". Now you have to do it again, or do a find and replace all while hoping there aren't any ulongs that were pre-existing.

All in all, it's a trivial thing and I appreciate all suggestions.

Steven Parker
Steven Parker
229,744 Points

It sounds like the multi-cursor approach would make you vulnerable to the same situation. Any of these shortcuts would turn one mistake into three.

Hi Steven,

Making a mistake in 3 different locations isn't really any different that making a mistake in one location.

If I was typing a variable name with one cursor and realized I made a mistake I would hit the backspace key and fix it.

If I had 3 cursors going I could still hit the backspace key and fix all 3 of them at the same time.

I don't know if you've had a chance to use multiple cursors/ multiple selections but several of the popular editors have this feature.

The sublime homepage has some slides showing a few different features. Slides 1 and 2 show some examples of what you can do with multiple selections. In particular, slide 2 shows you how quickly you can turn the days of the week, each on their own line into an array of strings.

http://www.sublimetext.com/

It looks like brackets and atom also have this feature.

The cloud 9 online editor has it to, https://docs.c9.io/docs/multiple-cursors but I'm not sure if they have to be in the same column or not. The example only shows the same column.