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

Motions and Wrapped Lines0:00

For our final fundamentals lesson, let's learn about motions, commands, and text objects, which are key to becoming fast and proficient with NeoVim. Let's jump back into our terminal, and back into NeoVim, and let's open this file I've created called laravel.txt, which just contains some text from the Laravel documentation. We've already mentioned how we can use hjkl to move around through one letter at a time. But if I push the J key while I'm on this line, you'll see my cursor comes down to the third line, not the second line like we might expect. If I turn on line numbers using :set number, we'll see that this first line is wrapped, and by default, the J and K keys will only move up and down between complete lines, ignoring any wrapped text.

Combining Commands and Motions7:17

Let's undo that one, and let's try the other way. Let's say we want to delete everything up until the end of the line. So we can say D$. Now that one's pretty common, so there's actually another way we can do this, which is Shift-D, and that will delete from our cursor position to the end of the line. Additionally, we can also use other motions. So let's say, let's come back to this word framework, and let's say we want to delete everything up until that comma. We can say DT ,, and that will delete up until the comma. So you can see how we can combine motions and commands to do more advanced edits.

Yanking and Putting8:49

change to the end of the line. Let's talk about copying and pasting. In Vim, this is called yanking and putting. I think the reason it's called yanking is because C for copy was already used by the change command. So to copy this word laravel, we can say YW for yank word, and let's say we want to paste it straight afterwards. We can use P for put. And you'll notice that when we yanked the word, it also yanked a space afterwards, so when we pasted it, we already had that extra space.

And you'll notice that when we yanked the word, it also yanked a space afterwards, so when we pasted it, we already had that extra space. Let's undo that one with U, and let's say we want to copy this entire line. We can use YY, and then we can do P, and that'll paste that whole line. Let's say we want to paste it five times, we can go 5P, and we'll get a whole bunch of extra lines. Let's undo those ones. Let's say we want to paste that line above the current line. For that, we can use Shift-P, and that will paste that line above the current line. Let's delete that line using DD, and let's do one more thing.

Introducing Text Objects9:45

For that, we can use Shift-P, and that will paste that line above the current line. Let's delete that line using dd, and let's do one more thing. Let's talk about how we can add new lines to the file. If we come down to line three here, if we want to add a new line below this line, anywhere in this line, we can just push o, and that'll place a new line straight onto the current line, and pop us into insert mode. Let's undo that, and let's say we want to put a new line above the current line. For that, we can use Shift-O. Let's undo that, and come back up to the top again. Let's now talk about text objects, which are a little bit different from motions.

MotionsCommandsText ObjectsJump List

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