The Only Video You Need to Get Started with Neovim

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
nope [Music] wow hey YouTube I'm TJ De and I'm one of the core maintainers of neovim what you just saw was we took a completely fresh installation of neovim and with one command we were able to pull down a get repo that sets up neovim for you that installs a package manager an LSP a way to configure and install your LSPs treesitter and fuzzy finder along with a lot more but my favorite part about the kickstar project is not just this one step step getting started but as you're going to see in this video we explain every single aspect of your config so that you can actually start your own journey in neovim instead of just copy pasting something blindly and fumbling about in pain and Agony hopefully Kickstart can get you started on your own neovim Journey quickly effectively and most importantly have a lot of fun so let's go ahead and do it guys and most vital piece of configuration inside of Kickstart is this wonderful and beautiful ASI art for you this reminds you not only to use a computer when you're using neovim but also that you should start with tutor and navigate with hjkl and also of course you can just throw that Mouse away we're going to get to some keyboard driven development right now you're probably wondering what makes Kickstart different from other projects in the ecosystem the primary difference is that Kickstart is not a distribution and when I say distribution I mean sort of a big bundle of plugins that adds things on top of that to help you either manage those or sort of abstract away some of the configuration Kickstart is instead a starting point or effectively a template for the kind of things that you're going to do once you're making your configuration your own the primary goal of Kickstart is that we have one file and currently it has less than 300 lines of code and about 400 lines of documentation that tells you each and every step along the way from basic configuration to installing plugins to Advanced script in and even starting to make some of the plugins your own we're going to work through that together today but before we do I do want to mention that if you don't know anything about Lua you should probably pause the video right now and check out something like learn X and Y minutes and learn a little bit about Lua once you've done that you might also want to peruse the help Lua guide which has a lot of really useful information about where Lua and neovim meet but after that let's go ahead and get started if you didn't know what I meant when I said something like help Lua guide then you definitely want to do do the next step which is you want to run tutor inside neovim when I say run inside neovim what I mean is you first press escape to make sure you're normal mode you press colon notice now we're in command mode we type out tutor and press enter when you do this you will enter the neovim tutorial if you've never opened neovim or you don't know anything about it this is a really really good place to start and the most important piece of information that you learn from here is how you can finally quit once you've completed tutor or if you already knew the neovin Bas then the next thing that you need to do even if you're a bit more experienced in neovim is just run help by itself this is a really important document that can tell you a lot of information about navigating exploring and understanding what is in the help throughout the rest of this init Lua I've left various comments telling you where to look in the help and if you're exploring something new and you don't quite know where to go we have included a nice shortcut which is space sh for searching through the help so in this case we could look for something like lazy install and we could press enter and go to find out more information about the installation of lazy or whatever it is the topic you're looking for but this is a key and very very important aspect of your neovim journey is you need to learn how to grock the help we always love telling people read the friendly manual and if you don't want to read you can listen right here to me reading the entire manual the last thing I want to point out before we start looking at the code is that throughout the init Lua five left little notes like this with bright green text each time you see one it's going to introduce a new concept or idea that's very important to your configuration so make sure that you understand them and are paying attention when you see them especially when you are reading through this config after you're done watching the video the first thing that we configure is the leader key which is effectively a nam space for all of your custom key maps in our case we already went over how space sh searches the help and you can see that if I press space I get this pop up that tells me something about the keymas we already have set up if I press s we get to search and then now you can see that the H right here is for help so space sh gets us to here and once again if you wanted to read more about leader you could just type leader in and press enter as you know neovim is a very configurable editor which means we have a lot of different ways to control the functionality inside neovim one of the primary ways that that happens is through options I'm not going to go over each of the options you can go ahead and read through the descriptions if you want but we try and set some good defaults for you for the experience that you might expect normally when you open up a random text editor the important things for you to know are that you can use vm. op to set those options from inside of Lua and you can even test that by running things like Lua vm. op. number and instead of setting it to true we could set it to false and you'll see that that removes our number column keymaps are an essential part of the neovim experience you might be more famili familiar with them conceptually is something like keyboard shortcuts but the difference is keymaps don't always have to have all of the buttons pressed down at once they can be a sequence of keys for example DD deletes a line and you can undo that deletion which you should have learned about in tutor here we're going to create a few of our own key maps to start extending neovim to work in the way that we want it to work so a very simple one would be something like let's say we have an error in our code I don't have a function called ASDF what I can do is in normal mode I can press right bracket D and that's going to call the function vm. diagnostic.com and then we pass some options to do things like giving it a description making a buffer local or more which you'll see later throughout the configuration and just to be clear there's nothing magical about what's happening in the keymap if we ran Lua vi. diagnostic.com line we're going to have the exact same experience as if we had typed those keys so these two things are exactly the same it's just about adding them to your fingertips instead of to the command line now that we're able to add functionality to our key strokes another important feature is being able to add functionality to when particular events are fired by neovim this is really similar to something like event listeners in JavaScript but we call them Auto commands in neovim because they automatically run some commands in this case the first one that I want to show you is what gives us this functionality that if we do something like Yap and we yank around the paragraph we get that little highlight which shows the region that we just yanked this is really helpful because sometimes it's not clear I yank this line or I yank J or I yank till y it's really nice to get that little bit of feedback that shows you what was previously yanked so how does this happen the first thing is that we have to tell neovim what event we want to listen to that's this text yank post which happens after we've yanked text we give it a description which just helps us know hey this is what it is in case you forget later we have a group and this helps us prevent duplicate listeners if you've used event listeners before and you call something like registering an event listener twice you end up running the code twice which is not what we want to do and groups help prevent that and lastly we have our call back which actually says Hey after we've had this event please execute this code or this command in a sense and that's what all commands are we have a few more throughout the configuration that you'll see but all of them follow this General pattern of registering to an event and then calling some particular call back everything we've done up until now has been useful in the base default configuration for neovim it doesn't install anything else but there's a lot of really awesome and exciting plugins and people working throughout the neovim ecosystem creating really helpful tools for you to be more productive and in my opinion have more fun so to do that we're going to install a plug-in manager you don't have to worry exactly what each of these lines do But ultimately this just checks to see if you have lazy envm installed and if not it installs it for you this is how we get that startup sequence that just magically starts bootstrapping itself so this is sort of the bootstrapping of the plug-in manager and after we bootstrap that then we can start configuring and installing the plugins now that neovim has lazy installed we can use it to update install and check the status of different plugins so we can run lazy and we get this nice menu we can check different things like in installing plugins if there are any not installed we can check for updates by pressing Capital U we can check to profile to see how long it took for lazy to start up each of these items is explained in more detail inside of help lazy but the main one that you'll probably want to do as you start experimenting is just lazy update which allows you to get the updated plugins from your configuration you can always roll back by snapshotting or using the other tools available inside lazy to keep your config safe and secure while you're experimenting with new ideas there's a variety of ways that we can specify what plugins we'd like lazy to install the simplest way is to just pass an owner and repo link like tp/ vm- sluth what this looks for is the GitHub repo under this owner and repo if you'd like to pass something that's outside of GitHub just give the entire URL and lazy will download it from there many NE of them plugins use a setup function to control both when and how a plugin is loaded because of how widespread this idiom is lazy include support for this out of the box the simplest way to do this is to use the Ops keyword and if you pass an empty table that's like saying hey plug-in please load yourself with your default configuration immediately when neovim starts to override the default configuration with the values you want simply Place those in the Ops table in this case we're configuring get signs with what signs we would like to show in the gutter but plugins can be configured with more than just tables instead we can actually run Lua code whenever a plugin is actually loaded fortunately for us this isn't vs it's just Lua code and we can do whatever we want lazy makes it very easy to control when and how the plugin's loaded just like we talked about with setup because we can delay loading of a plugin to some later event we can then delay the execution of the configuration until later as well this helps improve startup time and also helps it so that if you're experimenting with multiple different plugins you can easily enable or disable them without having to rewrite your entire config in this case we wait to load which key until the very lazy event and once it's loaded we call the setup and register additional key maps this is very helpful for separating the witkey config from the rest of your configuration plugins can also specify dependencies dependencies are actually just the same kind of tables that we've been building up to now so you can use any of the same Keys like Ops config or any of the new ones that we'll explain as we go in both your root or your dependency plugin specifications this provides really powerful configuration options for plugins that sort of work together to provide a really powerful experience and here's where we get to the first sort of larger plug-in configuration that we have within Kickstart this is for a fuzzy finder called telescope which was made by a super cool software developer who makes great YouTube videos and would definitely love it if you smashed that like button hit subscribe and rang the bell anyways to use telescope we provided a large range of popular key maps for you and you can explore what the keymaps do in this section but beyond that telescope has its own sort of introspection options that allow you to really quickly explore what's possible to do and what you've already configured let's try a few examples as we've shown before we can do space sh to open up the searching help but what I haven't shown yet is that if you press control forward slash you're going to open up a preview window which shows you all of the available actions that you can currently take within this picker this is contextualized to to each telescope picker so git related ones will have git related commands file ones will have file commands Etc we've included several key maps to help you get started using telescope within neovim lots and lots of different things can be fuzzy finded fuzzy finder I don't know searched for using telescope inside of neovim not just files or help but also your key maps or symbols in a project or Diagnostics you can even search through files that you've opened before or the currently open buffers we've listed each of them out here and there's great help documentation in telescope. builtin which you can check out if you're interested in any more of these or their particular options that they include an example of using the options to customize telescopes behavior is included in the keymap here that helps you be able to search your neovin files with the same keystroke regardless of where you're currently running neovim so this doesn't matter if you're in your config or if you're in a regular project you can always press space SN to search your neovim files you can see each of them shows the preview even though we're not currently in that project how does that work well we call find files and what we do is we provide an override for the current working directory key and we passed the standard path of config to telescope he search for files in this directory more than just configuring the behavior we can actually configure the way that telescope looks as well in the case of searching your current buffer with current buffer fuzzy find we actually want more of a a view that sort of filters down the values here so that when we're searching for something like Advanced example we can see the two different places that we have that within our file we don't need the preview and we don't need all of the same layout so telescope allows you to do this as well for more information about this you can read the layout section of the telescope help the next big section of a lot of important configuration is configuring the LSP now if you don't know what LSP is it means the language server protocol I have a really short video that I'll link in the description sort of explaining a broad overview but the very short version is that neovim speaks the protocol for language servers and needs to know both how to run and execute those external processes as well as how to trigger the different requests that you want to do so that might sound like a lot but walk through each step to make sure it's very clear what's going on so the first thing that we're going to do is we're going to tell neovim hey here's all of the things that I want to be able to do with the LSP this means primarily what we're doing is we're going to be setting up key maps to tell NE ofm when I press something like GD what I want you to do is go to the definition we'll walk through a few of the examples but you can read through the rest of the docs to pick up any of the other key maps that we have there first thing to note is that we are using that create auto command idea again this one is going to run on any time LSP attach is fired as an event and what happens is we're going to run this function whenever that event is fired the important things for here are one it's really good to remember that Lua is a real programming language that just means that you can write Little Helper functions or write for Loops or whatever it is that you need to do to make your configuration both easier to read and easier to maintain in this case we write a small helper function called map that takes some keys a function and a description and then we'll apply that key map in normal mode to the local buffer and prefix LSP as part of the description this is helpful to just make sure that you're actually doing the same thing every time and not forgetting to set this as a buffer mapping things like that the same kind of tips and tricks that you would normally do inside of programming we can apply inside neovim as well the two most important keybinds in my mind for an LSP are go to definition and find references by default in Kickstart we've included GD as go to definition so we just talked about building that map function and now we're using it here on line 459 when we press GD it's going to open up the possible places that that's defined we can press enter and we'll jump there if there's only one option it'll immediately jump to that definition like if we're using keys it's going to jump directly to where that variable is declared important key map is hey where is this thing being used and for that we're going to do gr for sort of goto references so when we press gr on map here we're going to be presented with each of the different references of map so we can press enter and hop immediately over to one of those one really powerful part of LSP is that these things work even across files or sometimes across projects depending on how well the LSP is supported and the rest of your workspace Bas configuration another really powerful thing about LSP is because of the way Neo's LSP is structured we can actually compose multiple tools together to use them in interesting ways for example when I press leader DS or space DS I'm going to look up the document symbols what that means is we're going to look up sort of all the variables or functions or classes or whatever is defined in the current file so when I press space DS we open that up and I can actually fuzzy find over any anything that's in this file so if we do map again we'll go back to where we had map but if we did something like cursor line we're going to go to the only spot we use cursor line this is a really powerful tool for navigating quickly around a file and it's a composition of both telescope which we just talked about and LSP this is one of the great things about neovim is that it's able to compose these tools together so as you learn more about telescope that can also power up and level up your LSP skills and you can keep on moving more quickly and more effortlessly throughout your editor but this gets even more powerful you might be wondering what's kind of the difference between fuzzy finding the symbols versus fuzzy finding just everything in the document well the first one is that the symbols only show definitions so it won't show things in comments but LSP also has a concept of workspace symbols so if we do space WS for workspace symbols I'm actually able to search all across my neovim config so if I look for something like completion we can actually see all of the different places that something with completion is defined throughout my neovim configuration this works as well if your LSP supports this for other languages so you could search across your entire project to look for where a symbol is to find feature of LSP that I want to show you is that it can also provide and help you find documentation for the current thing that you're editing in this case if we put our cursor on top of an identifier and press capital K we can actually see the documentation provided by the LSP this is super useful as you're exploring your code maybe if you were using an inferior editor before you may have used your mouse to make this window pop up but we don't need to do that here we can just press capital K and get straight to reading that friendly manual so what we've done up until now is we've told neovim hey neovim here's the things I want to be able to do with my LSP but now we also need to tell neovim hey neovim here's how you start execute and control LSPs because remember LSPs are actually sort of things that live outside of neoven there's some external process that we're communicating with inside of neovim so we need to inform neovim how to start run and control those external processes so that we can get the code intelligence we're looking for so the first thing that you'll see is setting up capabilities now I know a lot of people just copy paste this into their config but just stop for one second and and let me explain what it does capabilities is actually you informing the LSP what the client so that's neovim what the client is capable of doing so by default neovim is not capable of expanding all the different types of LSP Snippets and autocomplete there's certain other replace strategies or automatic text insertion actions that neovim doesn't Supply however and we'll cover this later in the video we're using a completion plugin called comp which is effectively adding those capabilities to neovim so we're going to merge these capabilities together and then inform all of the LSPs about what we are now capable of doing now that we've configured what neovim is able to do we want to tell neovim here's the servers that I want to run so by default all we have enabled is the Lu language server but to turn on some of these servers all you would need to do is just uncomment this line this would install clang D on the next installation and automatically attach in C files assuming that you have all of the requisite things for running clang D on your system like a relatively new C compiler things like that if you wanted to run go you would just do the same exact thing like this you would once again need go on your computer somewhere so that this could be built and executed some languages have additional tooling outside of just the LSP so you could explore doing those if the base LSP setup isn't doing enough but in general I find myself pretty happy with just an LSP and the same key maps between every language an example of configuring the Lua LSP which is the default inside Kickstart the reason that we do this is we are trying to inform the LSP where it can find all of the other Lua files in your neovim configuration the primary place that happens is here on line 560 where we get all of the runtime files and we send those over for the LSP to check this is how we get things like vm. api. envm starting to provide completion for us with documentation for each of the items this is really really useful as you're trying to configure and execute your neovim config to not just sort of blindly be guessing about what functions might be available to you now that we've told neovim what language servers we need to install we need to actually install them and to do that we use a tool called m now if you're not familiar with Mason for my soy latte loving coffee shop enjoying viewers it's basically like Brew install for neovim and for my single viewers it's kind of like Pac-Man and so what we're going to do is we're going to use Mason to install the LSPs and make sure that they're available in Neo's runtime so after Mason installs the LSP we need some way to connect those installed LSPs with neovim once again I just have to remind you these are external processes we need to inform neovim how to run them the simplest way to do that in Kickstart is using LSP config which is simply a way of saying Hey I want to connect Mason and envm LSP config the way that we do that is by calling the setup function for the servers that we've configured the nice thing about this is that it's always updates so if we add a new entry in the table above in servers it will automatically handle that in LSP config and install them through Mason a feature most LSPs include is the ability to format your file however there's no automatic setup for that in neovim to run that on save or to manage the interactions between external formatters and the LSP itself so one thing that's really nice is this conform envin plugin is useful for us we can set it up to format on Save automatically and it will fall back to calling the LSP formatting if we could find an external tool to do that formatting so if I indent this a few times and then I do right to write the file it automatically formats on Save the last major area of configuration that we have in Kickstart is for autoc completion most of the configuration is actually about setting up keybinds and I need you to bear with me just a little bit the keybinds that I have by default in Kickstart are not what you are used to for most other editors but if you give me some time to explain I hope to be able to convince you why it's at least good to give this a chance before you go back to tab does 85 different tasks so the mappings that we have by default in Kickstart are as follows the first is that we use contrl n and p to move between the next and the previous item in completion so if we were to start typing something like comp. mapping and we wanted to select down here we press contrl n and p to cycle through these items then once we have an item that we're happy with we can press control y to accept that item now if we only had select here and we press contrl y it will complete to the end of that item whatever one is the top item or whatever is selected now you're probably wondering those seem like Neanderthal keybinds and in some ways you're a bit right the keybinds have been around in Vim for longer than probably any of us watching have been alive however because they are the Vim standard keybinds for completion items what you'll find is that contrl n and contrl P show up in many many places throughout neovim for example when you're searching in telescope you can move up and down with control n and contrl p Additionally the reason that I like using contrl Y for accepting is that I really like when Keys only do one thing so I really like that tab when I press tab always inserts some space for alignment and that when I press enter I always get a new line and so for me using the Vim standard keybinds and keeping each key to always doing one particular thing is really helpful for reducing the mental overhead that I have when typing and reducing frustration when you tried to press Tab and then it didn't work and you need to go back or delete what you were writing all these kinds of things I find it keeps me much more in the flow when control y always completes and tab always puts spaces inside of the editor the last thing to mention for envm comp is that envm comp is really a completion engine and what I mean by that is it's sort of a framework for multiple different sources to give possible completion candidates and then you select them all in one unified way what that's really fancy way of saying we can have three different things like envm LSP Lewis niip and path they all get merged into one completion list that's presented to you so if you install other envm comp plugins maybe you want a buffer completion or you want like an AI completion or something like that you'll need to make sure that you add those to the sources for enim comp to make sure that EnV comp's actually getting those items in your config if you've been wondering how we got the really cool note hello or too wow or fix me I haven't even commented on the video yet that's all from this plugin from fol the goat to do comments and once again you can see we're using the combination of the tools we've already learn like dependencies and Ops to easily load and install the plugin and one of my favorite additions that we've added to Kickstart since the last time I made a video is the mini envm plugin this mini envm plugin is actually a collection of small independent plugins that you can either install separately or as one big bundle we have this installed to do a lot of really cool stuff like in these examples we can do something like visually around the next parentheses and we will select in visual ual mode the next set of parentheses or if we wanted to do something like yank inside next quote then we'll do that as well and you'll see that we yanked inside these quotes here finally we can do something like change inside quote and we'll start immediately changing the stuff inside of here it's a really powerful plugin that you can use to really quickly and efficiently edit a lot of text in neoven the plugin comes with a really great surround plugin which you can use to do cool stuff like if we Type S a i w parentheses which I'm sure you're thinking that's an insane number of letters but no no no just follow me S is for surround A is for ad surrounding I is for inner W is for word and then we can do a single character like a parentheses and we add those parentheses around the word that we're currently on you can extend this to delete and replace which is really powerful when you want to move quickly and change things that maybe are sort of far away from your cursor without grabbing your mouse and moving around a bunch the last item that we're using from mini is for the status line and you can configure that or read more about it by reading help mini status line there's also a bunch of other really cool plugins in sort of this mini ecosystem which you can check out in the link provided in Kickstart the last plugin that we have is envm treesitter which is a very powerful plug-in but we have only the basics set up for Kickstart by default we install a few of the grammar we tell treesitter please install new grammar when I open those new files and turn on highlighting and indenting it's possible to do even more impressive things like incremental selection text objects or even showing the context of where your cursor is but you have to check out the links below to try and find those and configure them for a way that you'd like we will have some follow-up videos coming soon about treesitter but in the meantime this does exactly what you need to get started with neovim which is the whole point of this project and that's everything that Kickstart includes by default but like I said at the beginning Kickstart is not a distribution what I want you to do is to take Kickstart and start making it your own I've included a few examples of how you can do that for example we have an indent line plugin included in the repo which you can find by searching for indent line and it just does something very simple it just adds a new plugin it specifies the branch and tells lazy to set this up if what we do is we go down to where we have indent line and uncomment that line when we save and neovim again you'll see that indent blank Line is now installed and when we edit our neovim our n. Lua we have those indent lines that some people really like not personally a fan but that's fine the point of including it in the repo is to show just how easy it is to start extending Kickstart with new plugins and new ideas even in multiple different files in fact we have included as well way for you to not have to manually require each one but you can use the import mechanism from inside of Kickstart you can use the import mechanism that's part of lazy by including more plugins in the file in this custom plugins init Lua folder so with that that's everything that you need to know to get started and to get moving on your neovim journey feel free to delete feel free to add feel free to change the whole point of Kickstart is not that I'm telling you everything that you should be doing but that instead we're giving you a little boost and a little direction to get started and be productive right away I really hope you enjoy the Kickstart project if you like the video once again a great way to say thanks is to smash the like if you want to support me in my work you can support me on GitHub sponsors or be a member of this Channel or all the other sorts of places that people normally do I really appreciate all the support and the love and ultimately sharing this video can really help me out too thanks everybody for your time and I really hope you have as much fun in neovim as I have
Info
Channel: TJ DeVries
Views: 139,582
Rating: undefined out of 5
Keywords:
Id: m8C0Cq9Uv9o
Channel Id: undefined
Length: 33min 59sec (2039 seconds)
Published: Sun Mar 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.