Effective Neovim: Instant IDE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up YouTube It's TJ DeVries I'm one of the core maintainers of neovim I've worked on the LSP integration the Lua integration Lua Auto commands and of M9 script to Lua transpiler in addition I'm the author of telescope anviv plenary anvim and a wide variety of other contributions and plugins in the neovim ecosystem and today what I want to show you is how to take neovim from not configured to an instant IDE in 30 seconds or less so before getting started with actually configuring the ovm you need to install it it's actually pretty simple to install if you go to github.com neovim click on the wiki click on installing neovim there's a bunch of different ways to do it in general I prefer building it from Source but you can also download from the releases or as mentioned here install the updates build from source and install for yourself that's step number one in the process after you've installed you should have some way to start any of them on your system that's probably something like typing nvim now when you do that you're going to have just this screen right here not a lot to go on you don't know how to navigate or do other things inside here I really recommend starting with Vim tutor or heading over to the primogens videos learning how to use them if you're interested in more ideas about that let me know what you'd like to know we can make some videos for it but so what does editing files look like right now if we just added something inside of neovim source tree like this you'll see that it's not the prettiest color scheme in the world it doesn't have a lot of things and if you start typing you're not going to get any help from things right even though we see right here clearly we're trying to access this variable we're not going to have that happen now so how do we go from here to having language smarts LSPs nice highlighting all of that it's just one simple script and you'll be all set up the rest of the video after that I'm going to explain how that script works so that you can start extending and moving from neovim as an IDE to neovim2a pde what's a p d e well it's a personalized development environment in short it's a way for you to configure your editor in a way that you like for a longer description and more information check in the description below I'll link to my previous video where I introduced the concept anyways let's get on to the IDE section in 15 seconds shall we so the first thing you'll need to do to move from zero configuration to an easy IDE in neovim is to create an nvim config folder now on Linux and on Mac this is simply doing something like makerp dot config slash Advent once you've made that folder you can CD there and you'll see right now that I don't have anything inside of this folder so no we've opened up neovim nothing's there and we don't have anything in our config we're going to just copy one script and get started this is where Kickstart nvim comes into Play Kickstart nvim is not a neovim distribution not that there's anything wrong with that but Kickstart is a simple place for you to kick start your nvim journey it contains a very sane and sensible default setup that you can use to get started and then that you can iterate and build on top of you don't have to keep up to date with anything in here you don't have to copy it you don't have to learn a new framework it's simply copy paste and let's go all this information is documented in the readme but what you need to do to move from no config to IDE is simply take the kickstart init.lua in general I like to open this raw I just copy you know you can use the mouse you're about to drop the mouse forever right so it's kind of like giving one last kiss goodbye before you break up with the mouse once you have that go back to wherever you have config nvim and open up init.lua simply paste the file in right quit so that's WQ to save and now the next time that you open up neovim it'll start installing your package manager your plugins and the associated configurations so let's just see that in action you type anvim it just says hey I'm installing things it gives you a nice little message to let you know what's up and then it's installing all your plugins they've all finished installing you quit and now we open it up again and you'll see hey I'm installing language servers we're ready to go now you've got a much nicer looking Neo of him already with some real colors a real status line and some information going on let's compare the experience opening the file that we had from neovim Source tree before to what we have now so now I moved back to the neovim source tree just as an example of a fun project for us to navigate you'll notice now when we open up in the oven we get some nicer colors as we just mentioned but we come with a lot more goodies now let's say we'd like to find that auto command file again I type space SF to say search files and I say hmm I want to look for something that has Auto command in it and sure enough there's the name I press enter to go inside I jump down to line 180 because that's where we were before and I can simply start typing AP notice now I get completion for each of the variables that are available to me now I start completing and I get the different fields for each of these items if I press GD to go to definition I jump to the definition which is in a different file that uses LSP to calculate that definition if I was wondering where is this field used I could press gr to look for references and I can fuzzy find over these references so if I wanted to find one just with kerpat I can do that I can move up and down with control n and control p i can press enter and I immediately go to that reference I can in fact do this and I can move them to the Quick Fix list and I can scroll through and work through these at my leisure if I needed to refactor them all of those instantly come with any LSP we can do even more than that to explore more you could look at telescope key maps and you can look and see hmm I'd like to do things like search four symbols do I have anything with symbols I do space WS for workspace symbols and space DS for document symbols why don't we try out space DS this shows me all of the symbols defined in the current file so if I knew I was looking for something with nested in the name I could press enter and I immediately go to the definition of that in the file all of these things come basically out of the box and if you open up a new file or a new language that isn't currently installed by default you can simply type Mason and pick from any of the available language servers supported by Mason anvim if all of a sudden you're like I want to do ocamel because that's what I'm doing for Advent of code you can press Ctrl F you could search through these and you could look through them or you could simply go for ocamel look at this you can press I to accept it you can see now that it's installing ocamel for me and I'll have the LSP next time I open up in okmul file it's as simple and easy as that to add support for another language that you're working with now now how does this happen how does the magic work that's what we're going to talk about for the rest of the video I want to make sure that you understand what's happening inside of this file but I just wanted to show how easy and how powerful neovium can be with almost no work and no setup just a few things inspecting the key maps and you're ready rip roaring to go we can open up the knit.lua that we copy and pasted in before and let's work through what's going on here so that we can really understand this and that you can begin that Journey for yourself of customizing neovim exactly the way that you'd like effectively what we have here at the top with this installation section is we're just making sure that Packer the package manager that we're using is available on your system after that we use a startup function this function declares what packages you want to install each of the following sections are just different plugins that we're using to do different tasks with any of them if you want to add another one it's as simple as doing use and then path to thing wherever that website is we currently have Packer which is the plugin that we're using and it can manage itself we have nvim LSP config that helps us set up and run language servers we have Mason that gives us that beautiful installation one click automagic the thing they said neovim couldn't do we're doing that and then we have fidget anvim that gave us the little spinner in the bottom corner earlier beyond that we have nvim comp this is what we use to get that beautiful autocomplete menu that integrates flawlessly with LSP We have envym tree sitter which I want to show a few things later in this video so we'll just have to hold your horses on explanation for that beyond that there's sort of a slew of a few different plugins that are primarily related to how things look and some basic defaults and then finally we have one of my favorites nvim telescope which is used to do all the fuzzy finding that you saw in the previous section once we have those we tell Packer that we're all done adding new plugins please sync those and install them and then lastly for the section about Packer if we change anything about our configuration this Auto command sets up basically an auto compile thing so you don't have to worry about anything difficult going on with Packer it just automatically updates and makes sure we're at the right stage following the Packer setup we set a variety of different defaults just to make neovin behave a bit more the way that you would expect for more information about these you can use telescope help tags to search over all the help in the oven and find out what they do so if you're interested in what is relative number notice that you don't have to type it exactly correct it does fuzzy finding you could press enter here and you can read The Help about that particular option this is useful for all of the things listed in the rest of the plugin and do not forget to read that friendly manual let me do that again and this time with some claps read that friendly manual okay hopefully that gets the picture across neovim's help is amazing and lots of plugins authors also write great and amazing help docs this will really help you level up your abilities within neovim take your time answer your questions and find out what you didn't know by reading the help next up what you'll see is a very common pattern many plugins that need some configuration provide a setup function that can be used to configure the plugin and customize to your tastes and liking in each of the following sections we just basically Define some really simple defaults and get those running within our init.lua so here's where we turn on our status line and once again I've left the help inside of here as a note so that if you're wondering what else is available to you you can type helpblueonline.txt and read through this help doc to find out more information we set up the status line we set up commenting we set up indent Blake lines which some people really like and if you didn't all you'd have to do is just take this and delete it that's how your configuration should go don't just leave it the way that it is but customize the way that you you like we set up get signs which helps us do some really nice things in terms of giving us diffs and hunks you know like me that are from your current edits within some sort of git directory and here's where we set up telescope it's going to look really intimidating at first but let's walk through an example and then you'll see how the pattern I think applies in the following calls the first thing that we use is vim.keymap.set this is the way that you can set new key maps believe it or not the first parameter is the mode that we're doing which is normal mode then you say the keys that you would like to use in this case leader means space so space question mark shows me the recently opened files that I have whereas space space shows me the currently open buffers space slash searches within this file so if we wanted to look for leader we could find all the places and so on and so forth the next argument is the function that we're going to call and these are various different telescope functions there's a lot of them you can actually do telescope built in to find out what else is built in and then we pass a description so that when we do things like telescope key maps and you press enter and you did something like leader s or we did something like SF here you'd actually see this search files here to remind you why you called it SF so what I provided is a list of defaults of some of the common things that I often do things like searching files searching help searching this word search via grep search the Diagnostics all of those are common things you might like a different mnemonic you might like different patterns go ahead and switch it it's very easy to do the next time you open up neovim those will all be set for you now let's move on to tree sitter tree sitter is a parsing library that can be used to do just an incredible amount of things the most obvious and the most common one that people know about is highlighting so all the highlights in this file are actually provided via tree sitter but tree sitter does so many more than things than that for example in this section here for incremental selection we've mapped a knit selection and adding the nodes to control space this means every time I press control space we're actually grabbing a bigger syntactic region not only can we do incremental selection but we can do things like moving to the next function or selecting function or doing many other things like that if I press bracket M bracket M that's going to move me to the next function if I press the other bracket M it's going to move me to the previous function and the last really exciting thing that we have as part of our setup is our LSP configuration LSP configuration is primarily around the idea now we have LSP servers over here and we have a client over here the client is neovim when an LSP server attaches to a particular buffer we call this function to configure the behavior and once again this is a very similar idea to before but I I wrote it this way in this case to remind you the user that Lua is a real programming language so you can compose functions you can pass function values around you can create closures all of those things work exactly the way that you would expect so we had this vim.keymap set before and I noticed that we were typing a lot of the same things so in this section we just call nmap and we bind it to this local value that just does some really simple things which is basically hey we've got a key we've got a function and we've got a description and so now when we're in a buffer that is attached to an LSP we have things like GD for go to definition or gr for go to references right we press gr we see all these references we press GD we can go to either of these two definitions here press GI to go to implementations so on and so forth any other additional LSP commands that you'd want to add you could just add in this function this function automatically gets attached to all of the servers that we configure down here which is intermingled with just some very basic Mason setup Mason is the plug-in that man manages installing those servers for you and then we just tell the LSB hey please attach to these servers and that's it if you wanted to change the behavior you simply modify this function and that's basically everything I know that maybe that might feel overwhelming but the nice thing is you should be able to read this file top to bottom understand the basic key maps that you have and start being productive almost immediately inside of neovim particularly if you've already practiced the Motions before the reason that I've worked on and helped to maintain Kickstart nvim is just to show that it doesn't have to be a hundred thousand lines of neovim and months of struggling to start working and start having fun inside the editor I think you can do it in 30 seconds and start being really productive if there's anything in this video that you'd like me to cover in more detail leave a comment below smash the like button subscribe or just tell me that you like the video I'm really excited to hear what all of you think about the video about the Kickstart project and I hope that it helps you kick start your neovim journey I've been having so much fun it makes programming a joy and a delight for me and I hope you can join us in the ranks with the most loved editor two years running in stack Overflow thanks everybody and uh share this with your friends I guess if you liked it too if you really like my work or really like what I'm doing feel free to head over to my GitHub sponsors page to leave me a sponsor that's the best way you can support me today thanks so much for your time I really hope you enjoyed the video
Info
Channel: TJ DeVries
Views: 783,027
Rating: undefined out of 5
Keywords:
Id: stqUbv-5u2s
Channel Id: undefined
Length: 16min 15sec (975 seconds)
Published: Sat Dec 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.