Visual Studio Code

Multi-Cursor & Line Manipulation

Visual Studio Code

Check out a free preview of the full Visual Studio Code course

The "Multi-Cursor & Line Manipulation" Lesson is part of the full, Visual Studio Code course featured in this preview video. Here's what you'd learn in this lesson:

After reviewing multi-cursor selection techniques including box select to add or edit the same code in multiple places, Mike demonstrates how to move individual lines of code up and down into the desired position.

Preview
Close

Transcript from the "Multi-Cursor & Line Manipulation" Lesson

[00:00:00]
>> Mike: So we talked about multi cursor. Option and click is how we got those little cursors and without the Cmd+D thing. It was just placing cursors, right? If we alt click, it's just those individual positions. There is something called box select. The way I remember this is, it's multi cursor with Shift.

[00:00:19]
Multi-Cursor with shift. And that let's us do something like this. Alt+Shift, oops.
>> Mike: Sorry it is fooling me by highlighting in kind items. Alt+Shift and then you can drag up and over like this. Really nice for Like if you wanted to grab a bunch of HTML elements and like embed them, or you have a list of items.

[00:00:48]
Say we had something like this.
>> Mike: Like one, two, three, it looks I already did example last night. So I could just drag a line of cursors here. Select them, one of the cool things about multi-cursor support and this works as it does in other browsers. It's almost like each cursor get to do in a little slot and a clip board.

[00:01:13]
So while I would go back here and type like li and everyone gets the same thing, I can actually grab all of this, cut it move my cursor into the middle and paste. It’s not going to be one, one, one. It kind of remembers that each cursor gets to hold onto it’s own value, and then when you paste it out it goes.

[00:01:38]
The values are preserved on a per cursor basis. So, command U. And I will update this that option click also remove a cursor if you click on that exact cursor. And it appears to also work with like if we have that multi selection going on here. And I alt click on this, it'll actually get rid of the selection as well not just the cursor which is exactly what we would want in this case.

[00:02:06]
So you could select everything, like we could do this what was it, I haven't internalized this one yet. Control command g, so I could say get everything but remove just that one there. It looks like it got everything. Ctrl+Cmd+g.
>> Mike: Select everything and then we on click.
>> Mike: Yeah, so now,

[00:02:36]
>> Mike: Well, sorry I messed it up there, but effectively we were able to grab everything and then get rid of this one and that one there. And in this case that particular term is probably used 30 times in this file. It 'd be really nice to bring it all at once.

[00:02:53]
All right, so line manipulation and this is a subset but I feel like it's the attainable subset for line manipulation. There are hot keys for everything. Most of it is not stuff that I would end up using. Like there are people who you could steal their mouse for a day and they wouldn't even notice, I am not one of those people.

[00:03:16]
So here is how I like to remember it, if I hold down option, I can use the up and down arrows to move this line wherever I wanna move it. Right I'm moving this around. If I add shift to that and hit down I'm copying this line. So I would say the moving around thing I have internalized and I'm trying to remember that adding shift gives, it is stamping that all over the place.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now