تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Adding Essential Plugins0:00

In the previous lesson, we installed the Packer Plugin Manager and installed our first plugin. Now let's install some of my favorite essential plugins and walk through what each of them does. I'll save a few of the bigger ones, like IntelliSense, for their own dedicated video. Let's jump back into the plugins.lua file we created in the previous lesson and we'll scroll down to where we're defining our plugins. We've already installed Vim Commentary, which if you remember, lets us use GCC to comment and uncomment lines of text. Let's go ahead and paste in the other plugins I want to talk about. We'll save this file, which will trigger it to be automatically resourced using the auto

Syncing with Packer0:33

Let's go ahead and paste in the other plugins I want to talk about. We'll save this file, which will trigger it to be automatically resourced using the auto command we created in the previous lesson. So now we can just call Packer Sync to install our plugins. And this will download and install them and it'll automatically run Packer Compile afterwards to create the optimized version of our plugin definition. Once it's installed, we can press Q to come back to where we were. So first up, we have another plugin by Teepope, and you'll notice we have a few from him because he's a prolific plugin developer. This one, called Vim Surround, lets us do something like this.

File Search and Heritage4:33

So this one's really helpful if we want to search for something a bit more complicated than a word we already have on the page. We then have one that I created called Vim Heritage, and this one's pretty simple. If we were to edit a file in a directory that doesn't exist, so let's say sum/directory/file.txt, by default, if I was to try and save this file, Vim would give us an error because the parent directories don't exist. So what Heritage does is automatically create those parent directories when we save the file if they don't exist. We then have an example of a more complex use statement. So in this case, this plugin requires another plugin to work.

We then have an example of a more complex use statement. So in this case, this plugin requires another plugin to work. And we can define that relationship using the requires key. So this XML AtaText object requires this TextObjectUserPlugin to work properly. And what this plugin does is gives us two extra TextObjects. So if I was to come in and I write div id="test" class="test", I can now say vix to visually select inside the XML attribute, or I could say vax to select around it, including the space. And of course, you can use commands like change and delete, not just visually select. Get rid of that one.

Auto-Detect Project Root5:38

And of course, you can use commands like change and delete, not just visually select. Get rid of that one. We then have one called VimRouter. And this one's really handy if you imagine a typical Laravel project where maybe you've changed directory into the database directory, and then you've gone into the migrations directory. If you open Vim inside that directory, the working directory of NeoVim will be that directory you're in. So if you want to create a file or open another file, NeoVim's kind of locked into that directory. It's not going to look in the parent directories of that defined your project. So what VimRouter does is automatically change directory into your project root.

It's not going to look in the parent directories of that defined your project. So what Vim Router does is automatically change directory into your project root. And it detects your project root by looking up the file tree until it finds something that tells it that it's the project root. So one of the most common examples is looking for the .git directory. But it also looks for things like package.json and all that sort of stuff. Now by default, this runs every time we open a new file. But I can find that a bit annoying if I browse, say, to a file inside my vendor directory, Vim Router will automatically change my working directory now inside my vendor directories in some plugin, and generally I want to keep it back in the project that I'm in.

Autopairs Lua Setup7:09

And then once the plugin is loaded, I manually call the router command a single time so that I can ensure that it only happens when I first start up Vim and not every time I open a file. We then have one called nvim-autopairs, and this is something most editors have out of the box. If I come up here and I write, say, an if statement and I do an opening bracket, autopairs automatically adds the closing one in there for me. Similarly, if I was to say echo and then do an opening single quote, it'll automatically create the closing single quote for me. That one's really handy. Now this plugin is written in Lua, and most Lua plugins require you to manually call their

Better Buffer Closing8:26

So to show why this one's important, let's open up a visual split and then inside here, let's open up nvim in a .lua. If I'm finished with this buffer, I can close the buffer using :bdelete, and it doesn't delete the file, it just deletes the buffer, which is kind of like the pointer to the file. So if I run :bdelete, you'll notice that it also closed the split that that buffer was in. So let's open that one up again and we'll browse back to that file. If I run :bdelete with a capital B, and you'll notice that any commands defined by a plugin always start with a capital because that's something that Vim imposes. So if I run :Bdelete, you'll notice that it closes the buffer but

by a plugin always start with a capital because that's something that Vim imposes. So if I run B delete the capital version, you'll notice that it closes the buffer but it leaves the split open, and that's just what I prefer. And in the config function for this plugin, I'm setting up a key map to bind leader q to run that command and then press the enter key afterwards. So I can very quickly just type space q to close the buffer. Next up we have one called splitJoin, which I demoed earlier. But to remind you, if I create an array, so I'll create a Lua array in here. So we'll say 1, 2, 3. I can say G capital S to split that array onto multiple lines, and you'll see it even

sure I have the trailing comma. And an option here for when we're doing php method chaining and splitting those onto one line and multiple lines. So that one's pretty cool. We then have one called vim pasta. And this one just fixes the indentation when we paste something. So let's say I copy this line here that we're on here. If I copy that, if I paste that inside this function, you'll notice it automatically indented it to match the indentation of the function we're in. So that one's pretty handy.

Change Surrounding TextSmart IndentationExtra Text Objects

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