Use Multiple Cursors with VSCode

Kent C. Dodds
InstructorKent C. Dodds
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

Using multiple cursors is a fantastic way to speed up your productivity when working with and refactoring code in VSCode. Learn four different ways to use multiple cursors with VSCode.

Instructor: [0:00] Sometimes, you have a list of things and you want to do the same thing to every single one of these lines. For example, if I wanted to change this from an array of strings to an array of objects where the string was the name property of the object, then I might say OK, open brace, name, colon, poodle, and then closing brace, and do the same thing for each one of these, but that would be taxing and not very fun at all.

[0:23] Instead, what I am going to do is I'm going to select those two spaces and hit command D to grab the next two spaces that VS Code can find and follow along through all of those. Now, I have multiple cursors where I can say name, colon, and then go all the way to the end, and add that closing brace.

[0:44] Yet, another way that I could do this is with option command and down arrow. That will give me multiple cursors there as well. This works in both directions, so I can do option command up, and then down. That gets my multiple cursors where they need to be.

[1:00] Another option we have here is I could select all of this and then do command Shift L, and that's going to select all of the text in this file that matches this exact selection.

[1:12] I prefer to use the command D option here though because it allows me to be more specific about how many of these matching selections I want to add, and I can actually use command U to go backwards. I can go D and U to go backwards on my selection.

[1:28] In review, there are a couple of ways to this. We can do command Shift L to get all of the selections that match. There's command D and command U to go back and forth. There's also selecting and then using command and click, or even selecting and command shift and drag to get that multiple cursor selections.

[1:48] Each one of these allows me to perform multiple cursor selection to make things like this much easier. With all these, when you're finished with multiple cursor selection, you hit the Esc key to return to a single cursor.

~ 5 years ago

Cheers Kent!

Any idea whether you can skip an occurrence like you used to be able to in Sublime? Recall it used to be cmd+d then cmd+k (which skipped the next one) and allowed you to continue with cmd+d thereafter.

Was surprisingly useful. Often find theres a match that you don’t want in the multiselect. Have looked previously but seemed to be missing or I couldn’t find it.

Markdown supported.
Become a member to join the discussionEnroll Today