Autocomplete and Snippets in Neovim | FREE COURSE // EP 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to show you how to get the most amazing experience in neovim with auto completions and Snippets with only a few plugins after this you'll be able to tab your way through amazing vs code Snippets in any file C documentation and LSP completion sources pop up like magic and more and to start things off I have a bit of a surprise for you a little something extra to make our neovim config really pop so stick around subscribe and let's get into it [Music] welcome to episode 5 of neovim for noobs and everyone else really in this series we're creating a modern and modular configuration that supercharges neovim and makes it even better than most idees and text editors if you missed the first few episodes I suggest you go back and watch those videos first so you can understand where we are with our config but either way let's recap what we've done so far so far what we have here here is an amazing modern and modular configuration for neovim we have all the goodies like we have a great LSP configuration here and in the last episode we used nun LS to actually wrap our CLI tools like form matters diagnostic tools things like that into their own sort of generalized LSPs and we are able to format our files with null LS rather n LS but null LS is a thing underneath it so I don't know it's a whole thing check out the other video if you want to know what's going on there but either way I'm excited for our configuration we have a really great setup a really great foundation and I'm ready to finish this thing off with some amazing functionality with auto completion and Snippets so let's get into it but first I have a little goodie for you a little surprise a little treat if you will if we open up our neovim you may notice that we have this amazing looking dashboard this is alpha. Lua I got this from someone on Twitter actually G M beir Sharma he shared it with me and this is amazing it blew my mind it looks so pretty I love it typically I'm not big on dashboards but I really loved how this looked and I'm enjoying it so far so in this dashboard the default for what we have right now it just shows like our latest files and some other things I'm going to open up the dashboard configuration and just show you really quick I'm not going to spend too much time on this you can check out the repository where everything exists I'm going to put it in the description of this video so you can check that out whenever you want but essentially we use alpha. envm which requires web Dev icons a lot of things do so we already have it and we're using the Starfy theme for our dashboard that's what gives us the latest files we've used amongst a couple other things and this is where the real magic happens this header is so cool this is I don't know how this is generated I've gone I've looked at a few different tools like figlet and some other things couldn't figure it out thank you gambir for showing this to me um it's amazing and that's all you need with that setup you have this amazing splash screen anytime you open neovim I just thought it was cool and I wanted to share it with you guys so there you go Merry Christmas anyway let's get back into some real stuff here Auto completions okay so we're ready to get into autoc completion and Snippets in our neovim config but I got to come clean here this is a really complicated Topic in neovim there isn't a set standard for Snippets and completion like how there is for LSP functionality nor is there a simple plugin that makes things easy to understand like how null LS wraps CLI Tools in an LSP and makes things easy with built-in tooling Auto completion and Snippets require a hodg podge of plugins to get the functionality we need for our config I'll try and go over each plugin in more detail but for now let me just lay out the list of plugins we're looking at for this functionality number one is envm CMP this is the completion engine for neovim this is the plug-in that will show the completion list as you type but this is only for completions it still requires third party plugins for sources like Snippets for example next up is Lis snip Lis snip is a snippet engine for neovim written in Lua we're going to use Lua snip as both a source of Snippets for envm CMP and as the snippet expansion tool for envm CMP you'll see how this works in a second next up is CMP Lewis nnip this is leip's completion source for envm CMP for my understanding and I could be wrong here this plugin is responsible for supplying envm CMP with a list of possible Snippets while you type then L snip will expand them then we're going to install friendly Snippets which is a collection of VSS code likee Snippets that can be loaded by Lewis niip essentially adding awesome vs codes Snippets to Lewis niip we will demonstrate this later and finally CMP envm LSP a completion source for envm CMP that displays the built-in LSP completions offered by whatever LSP is attached to the buffer I believe this adds an additional layer to LSP sources giving them the ability to report completions to envm CMP okay that is a crazy amount of mixed functionality amongst many different plugins let's let's check out envm CMP and see if we can make some sense of this there's a great config in this repository that I'm essentially going to copy and paste into our own so let's get into it and I'll try to explain along the way okay so here we are with envm CMP it is a completion engine for neovim written in Lua and the sources for these completions are installed from external repositories and sourced now you could look through the documentation try and get a better idea of what's Happening under the hood but essentially the way I see it is this is the thing that powers the window you see while you're typing where you can select Snippets and completions and there's an amazing recommended configuration here so let's try and copy some of this into our configuration we can open up our config look at our awesome dashboard and just think man this is really cool and then let's navigate to Lua plugins and create a new file called completions DOA we can open that up make sure we are returning a table and the first thing we want in here is the the envm CMP short URL here and that's this one so let's copy and paste this right here and then essentially let's just copy and paste this configuration in our config setup so we do config equals function and we can do essentially all this stuff right here okay got it good I'm just kidding let's go over it first let's format our file thank you none LS and then now let's go over each piece of this setup and try and explain what's going on here first thing we have is the snippet argument and in this argument there's an expand argument which is a function essentially what this is I think is the piece that when you click on a snippet that you want to expand it runs this function now for us because we talked about using lisis nnip let's just uncomment this line here that is LS nnip and we're going to use LS snip as the snippet expansion function for this setup if that makes sense cool so L snip is our snippet engine and that's what we're going to use to expand our Snippets great next is the window section this is just how the window looks for the autoc completions I like this bordered window look so I'm going to uncomment these lines as well next up is the mapping this is the most straightforward part of this configuration it's basically the key binds for scrolling through docks uh completing a snippet and confirming the snippet thus um expanding it pretty straightforward I'm leave it the way it is because it's pretty straightforward and I like it and then next up is something that's also a little bit confusing we have our config sources now I'm going to believe it or not comment out this first section because we are not going to handle the LSP stuff yet we're going to do that in a second because there's a little bit more to explained there dash dash jeez forget how to type and this section right here is for vs snip we do not use vs snip we are using LS nnip so let's uncomment the ls snip line and get rid of the other two commented Out Lines there we go okay so now this is our initial configuration but we are missing something which is if you've caught on L snip we don't have that yet so now let's go back to our configuration the example configuration and install Lewis niip so for lwis niip users they say you want to install Lewis niip and completion LS niip okay let's do that so this should be another table here and then above that let's create another table for LS nnip and then another table here for actually you know what I'm going to add that as a dependency that's what I'm going to do so let's delete to start delete to open quote and this is going to be lsip and within lsip I want my dependencies block to include CMP Lewis niip CMP Le niip is the completion engine for Lewis niip so whenever you select a leis snip snippet completion leis snip is the thing that will then ex complete that snip it if that makes sense so it seems like there's multi-layers here right um if we look at the configuration it seems like envm CMP is deferring to Lewis niip to expand Snippets and then Lewis niip itself is is deferring to CMP Lewis niip to expand Snippets it's very confusing the way this is set up unless I'm getting this wrong which I could be that's possible so now we have Lewis nnip and completion Le snip installed we need one more thing which is the actual Snippets that the Lewis snip snippet engine will use what we want to use here from LS Snips own documentation if we want to load the cool vs code Snippets we can use friendly Snippets so this is the package we want to use with L snip to be able to load all these Snippets these are the ones that come from VSS code or at least are similar to the ones in VSS code so this is a community-driven repository for all kinds of Snippets in all programming languages cool seems pretty good so now we have many different pieces we have Lewis nnip completion Lewis nnip and friendly Snippets now we only have one more thing to do we have to add this line which adds the vs code Snippets from friendly Snippets to L snip so let's do that here now if we quit neovin and reload um my friendly Snippets package is already installed so lazy isn't going to open but we can see here that friendly Snippets is installed so otherwise you would have seen it install here but it's already installed in my system right now so now if we go to completions and we type function we can see that we have Snippets a snippet window opened so what's happening here the way I see it what's happening is we have enm CMP opening up a window and all the data within this window is driven by LS snip and friendly Snippets and then when we go down to Lewis snip and hit enter it is completed by CMP Lewis snip interesting that's really cool so now we have snippet expansion and snippet support and auto completion for all the major languages within neovim awesome okay so now that we have the main Foundation of our snippet functionality in neovim right now we can add more sources to our snippet completion configuration the main one that I want to add in this video is envm LSP now envm LSP is an envm CMP source for Neo's built-in language server client now this plugin is really interesting because essentially what it does is it reaches out to any LSPs attached in your current buffer and we ask it for completion recommendations that LSP will give it completions and then CM LSP will also expand those completions if we look at the code we look at the source and we actually check text document we can see that right here what's happening is on completion this plug-in is reaching out to the LSP using the text document completion function on the LSP so this is a thing that's actually running running the completions with envm CMP LSP or sorry I said that wrong CMP envm LSP it's a lot of plugins it's really hard to remember so let's get this installed there's a couple of steps for this one do you guys hear the sirens in the background I think they're after me this Lua config is too hot right now so the first thing we have to do is make sure that this package is installed on our system now we do that by going to our completions file and making sure we have just one more entry here and that entry is the short URL for CMP envm LSP we quit envm we reload it lazy installs it yada yada yada and we see that we have completion envm LSP installed okay the next step we actually have to broadcast these capabilities now to the language servers so that the language servers are set up on each buffer with all the configuration they have including the completion configuration that this new plugin offers now what we do here is we want to set a local variable in our LSP config because this is where all of our LSP stuff lives so it makes sense inside of envm LSP config we have our config set up we want to set capabilities to acquire CMP and Vim LSPs default capabilities now inside of every language server that we set up we want to add the capabilities look at this completion already working that's pretty sick to every language server that gets attached to a buffer cool okay so now if we quit neovim reopen it if we open up LSP config and type Fu again now we see we have a couple of different Snippets this one right here is leis snip and this one right here is the LSP snippet that was given to us from CMP enm LSP so this is actually reaching out to the language server and grabbing the completion information when we hit enter it hits that text document complete function on the LSP and this is what the LSP is giving us so I think this is great just in case you don't have a snippet for something in Lew snip but there is that functionality in whatever LSP and language you're working within in neovim so now let's test this out with another project this is a JavaScript project so let's see what we get for JavaScript if I start typing function look at all of this this is some amazing autoc completion and there's all this documentation and everything this is great these are all Snippets I believe from LW snip some of these I'm sure that are mixed in are also from the LSP server from TS server and if we try to expand one of these Snippets let's see what we get boom function name something that is freaking awesome now let's go to a different one let's just see let's just see what we got here so we can go to a ruby project I know that I do not have an LSP installed for Ruby apparently there is one one I've been getting told on the internet I was not aware of that but I don't have it installed in my system so let's go to a ruby project get brown Tre typ craft this is a ruby project so if we go into a controller and we start typing def for a function these Lua Snippets are popping up with documentation at least for the Snippets for Ruby on Rails and then I could expand this awesome this is amazing so with a few plugins now we have autoc completion Snippets and LSP Snippets and autoc completion we have essentially all the functionality that you would get from vs code pretty much out of the box for every major language in neovim this essentially is the perfect setup I think we've done it fellas this is the Holy Grail now this part of the setup is actually very confusing and I had a tough time figuring out how to explain this because to be honest there's so many moving pieces it's hard to explain but essentially we install 4ish plugins and we get all this amazing functionality we start typing and we see auto completions we see stuff from LSPs we see stuff from LS nnip this is awesome it really is amazing and this is everything that we need here to be completely honest this is all you need and this is all I'm going to use for my professional development as a day job I am a developer believe it or not and this is what I'm going to use now as my daily driver configuration so if you followed along with this series and you set up your configuration just like me in this series then guess what you you and I are using the same series it's like we're looking at the same Moon together it's so romantic we're doing this together and I love it next episode's going to be on debuggers if you're a debugger kind of guy come and check that one out either way subscribe also I currently have covid so I'm hope you're happy with this episode because it was hard to make [Music]
Info
Channel: typecraft
Views: 42,756
Rating: undefined out of 5
Keywords: vim editor, neovim, vim, neovim setup, neovim from scratch, neovim from scratch lua, neovim setup from scratch, neovim configuration, neovim tutorial for beginners, neovim tutorial, neovim tutorial mac, neovim course, neovim free, free neovim course, how to install neovim, neovim lua, neovim config tutorial, how to config neovim, neovim installation guide, how to setup neovim, neovim plugin tutorial, vim plugins tutorial, neovim autocomplete, neovim snippets, snippets, vscode
Id: iXIwm4mCpuc
Channel Id: undefined
Length: 17min 7sec (1027 seconds)
Published: Sat Dec 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.