Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use Multiple Cursors with VSCode

    Kent C. DoddsKent C. Dodds
    vscodeVS Code

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.