در حال بارگذاری ...

Introducing Multiple Cursors0:00

All right, next up, we should have a look at multiple cursors. I'll show you how to use them. So, why don't we open any class here, how about User, and let's see, yeah, this isn't quite right, but it'll work for an example. Let's say that these two properties, here and here, need to have their visibility swapped out for public. Okay, well, of course, a number of episodes ago, you learned that I could press Option, Return, and then come down to public, like so. And then I could do the exact same thing here.

All right, let's try it again. Let's come up here. Oh, we missed one. All right, so let's select it, Control-G, G, G, and I can change it to public. And yeah, I think you'll find in plenty of situations this ends up being the faster approach, especially for small little tweaks. So once again, I will press Command-Z to undo that. And yeah, here's another example.

Renaming Variables Fast1:29

So once again, I will press Command-Z to undo that. And yeah, here's another example. How about right here? We'll have a function, fullName, returns a string. And yeah, right here, let's initialize a variable name. This will be John. And then I just want to have repeated references to this variable. So maybe I will concatenate his last name, and then we return it.

So maybe I will concatenate his last name, and then we return it. Okay, so imagine that as part of a refactor, you want to change this variable name to fullName. Well, once again, we could use the refactoring menu. Control-T, rename, fullName, and we're done. And yeah, this is an incredibly fast and safe and secure way to go about it. But also, if it better fits your workflow, you could just use multiple cursors.

But also, if it better fits your workflow, you could just use multiple cursors. So I will hit Command-Z to undo. And yeah, I will put the caret on top of the variableName. I will hold down Control, and then I will press G, G, G, and I can update it in this way. And yeah, that works too. So the only reason why I say the former approach with the refactoring menu is a little safer is because, well, when you go that route,

Multi-Cursors in HTML2:51

They're both great. Okay, cool. So here's another example. Let's go into a view. Hmm, how about, let's see, Posts, Index, what do we have here? Let's create something. I'm going to use Emmet to quickly scaffold some HTML. So how about we have a UL with a nested list item, and specifically, I want five of those.

and then press Ctrl G a handful of times, and now I have five cursors, at which point I can populate this. And yeah, you'll even reach for this in HTML when applying attribute values. For example, maybe we've decided that all of these list items need a class. Well, once again, exact same approach. Select them all, and then right here I can say class, text, read, or again, whatever is appropriate.

Finding Keymap Shortcuts4:13

Select them all, and then right here I can say class, text, read, or again, whatever is appropriate. It's a pretty quick way to go. All right, let's finish up by having a look at the key map. So again, Command comma to open up settings. I will choose key map. And yeah, if you don't know what the name of the menu action is, but you do know the keyboard shortcut, then select here and type it in. So if I press Ctrl G,

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟