From 0 to IDE in NEOVIM from scratch | FREE COURSE // EP 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
neovim is by far my favorite text editor and with the right configuration it can compete with the very best of editors like VSS code or intellig or sublime teex or whatever else but getting to that point is really difficult there are tons of plugins and configurations and pre-built neovim configs it's really hard to understand where you're supposed to start and what you're supposed to do in order to get a great Vim setup that Rivals an IDE I imagine it almost like this ocean of plugins and configurations and in this video series I want to like the captain of the boat that sort of steers you through this ocean and gets you to a nice safe island with a beautiful neovim configuration that works just like an IDE so this will be a series and in this first episode I'm going to cover just a few of the basics like getting a package manager installing a few of your first packages some of the things that I think are like kind of core to the neovim experience and then we're going to do a lot more interesting stuff from there so be sure to subscribe and follow along with this series it's going to be fun let's get into it [Music] now who is this series for well it's for those of you who already are at least somewhat familiar with vim and Neo and you just want to take your configuration to that next level and take your understanding of that configuration to the next level if you're not as familiar with Vim you can exit with colon Q by the way then do some reading uh practice a little bit with VI and then come back here and check things out when you're ready now in this episode we're going to cover a few things number one setting up your initial configuration file the init.lua file oh yeah we're doing this in Lu by the way baby it's going to be awesome next we're going to choose and install a package manager then we're going to install our first package which is a color scheme then we're going to cover fuzzy finding files and gripping through your code base with telescope and then finally we're going to finish things off with highlighting and indenting using tree sitter so let's get into it so the very first thing we're going to want to do is make sure neovim is actually installed on our machine now neovim is supported on all the major operating systems um I am using Macos so I'm going to be using in the directions here have home brew so I'm going to be using Brew to install on my Mac OS machine if you're on Linux of course there are different package managers for different Linux distributions so pick the one that's right for you and install it using that package manager and then for Windows it looks like there's actually a few different ways to do it uh the most popular one looks like wind get but I don't really know windows so I can't really tell you for sure how it works so I'm going to go ahead into my terminal and I'm going to install neovim with Brew install neovim Brew is going to run some updating stuff and there we go we already have the latest version of neovim which is 0.9.4 at the time of this video and so we can just type envm and we're in now the very first thing we're going to want to do here is create our init.lua file we're making this configuration in Lua which is a scripting language that has a runtime built into neovim which by the way is I think the main reason for this explosion of Neo's popularity and all these amazing plugins that have come out recently but we're going to do our configuration in Lua and what we need to do is create an init.lua file that is the convention for neovim and the convention is that we put it in our home directory. config do/ envm SL init.lua now why do we put this here what is the deal with this directory why is this so special well it all has to do with Neo's runtime path a runtime path is basically the directories that neovim will look within to find things that it should Source in Lua or in other configuration files and specifically the configuration for an anit do Lua is to have things in your local home directory in a config directory SL envm so anything within config envm is going to be loaded by neovim and Lu's convention is that anything that is called init.lua will be automatically loaded so so that's why we put an init.lua Inc config envm init.lua so now let's create that file we want to open it with neovim config NVM and knit. Lua and there we go we're in let's write this file with colon W and it is written it has been written now within our configuration file there's a bunch of stuff we can do here but I like to start things off with just a couple little things that I like to use uh throughout Vim or neovim and I have the lines that I like right here essentially all these do is um they set certain values within a Vim configuration that allow me to use spaces as tabs instead of the tab character and to use two spaces for each tab so whenever I indent I'm indenting two spaces now that's just for me you guys might like four spaces you might like tabs whatever this is how I like to use Vim so I start off with this now we can write this in our Lua file in it. Lua rather and if we try and source it we can do this special thing where you type colon Source percent and that'll Source this file and if we call Source wait a minute we have an error why did that happen because this isn't a vimscript file this is Lua we do not write Vim script code in a Lua file that's ridiculous so how do we set Vim variables and configurations from within a Lua file well it's done using things called meta accessors or functions that expose vim's lower level apis to the L runtime within neovim but for us what we're going to want to use is the vm. CMD function and what that does is it allows us to run any kind of Vim command within the string that comes after this function declaration so let's call that so now we can edit our file and since it's multiple lines I'm going to create a quick macro here q q now I'm recording in the Q macro I'll type insert vm. CMD open a parenthesis open some quotes hit Escape go to the end close quote close parentheses Escape down start line now I hit Q again now my macro is recorded I can just do at Q at Q at Q and this now is a Lua file running Vim commands for neovim so now if I Source this file there are no complaints and what happens is that all of my indents and everything else is now two spaces cool great start gang okay so now we have a couple little uh configuration settings that we like in our neovim config it's time to make a big decision we need to install a package manager now a package manager in neovim is basically what it sounds like it's a thing that manages the packages inside of your neovim configuration it'll install them it'll run certain commands that need to be run it'll have other features I'm sure but it's essentially a package for packages if that makes sense now there are two two main popular package managers in neovim that is Packer and lazy believe it or not I don't think there's a whole lot of difference between the two of these plugins lazy. envm seems to have much better performance and it has an awesome UI but both of these offer very similar features they do lazy loading they have some kind of performance enhancements um they obviously install packages but it seems like the consensus these days is to go with lazy because it is lazy loing first it seems to have better performance and it has an awesome UI so let's go ahead and install lazy. envm now the installation process is fairly straightforward what you have to do is copy and paste a couple of Snippets into your init.lua file like this and if we look at this really quick what we see here is um we have a local variable called lazy path that's set to a certain path that it wants to look for on your file system and if that does not exist then what it does is it runs a get clone command through vim and clones the repository that we are looking at right here so essentially this little snippet just says hey does this thing exist on the system yet if not we'll clone the repository and then we're good to go now that we have the snippet in place what we're going to want to do is call the setup function for lazy underneath this snippet this will actually load lazy for us now you can see here we have two variables that are currently undefined plug and Ops both of these are Lua tupal so we can just say local plugins is an empty tupal and we can do the same for Ops there's probably a more clever way to declare these variables but whatever now if we write that file and then Source it we now have the lazy command available to us in neovim if we type colon capital L lazy and hit enter we see the lazy goey how cool is that so now lazy is installed on our system and we're ready to install some packages now our configuration has some pretty terrible colors so the first package I want you guys to install is a color scheme to make things look cool and hit now my favorite color scheme is something called Kat poochin it has amazing color default it has an awesome palette and personally I love it it's really really cool I suggest you install the same but you know what there's a million out there so look for whatever you like in their repo they have a neovim link for installation so we can go over here let's in install it in neovim and I believe they even have a section for lazy yep here it is so now in lazy what we can do is we can add to our local plugins Tuple in Lua this line right here this is another Tuple it gives us a string that is the GitHub repository uh URL essentially for this plug-in um it gives us a name which I don't think is super necessary for us and I'm pretty sure this sets the loading priority for lazy so we can go to our local plugins tupal create a new line in here and just paste in what we've copied so now lazy will include this plugin when it calls setup so let's quit envm reload it let's load it at the file that we are actually editing and you can see that lazy automatically detects that we have a new uninstalled package so it installs it for us so now I'm realizing this is actually lazy's default color scheme this happened because we reloaded neovim with installed and now it showed up with this new color scheme this is not Capuchin to enable Capo we have to require the package and call a setup function most packages in Lua export a setup function that you need to call in your configuration essentially what that does is it'll import all of the functions and all the functionality for that package into the neovim L runtime so neovim can then execute it so let's do this for cat poin so underneath our setup we can say require cat pooing and call setup and then underneath that we can use another Vim command function to set our color scheme to cat poochin now if we quit and reload neovim in the file that we were just looking at our n.l file hey look what an awesome looking color scheme this configuration is already looking pretty sick let's keep going so now let's CD into our config directory because I'm honestly getting pretty sick of having to type out this whole entire string every single time and we can call envm in it. Lua great now the next plugin that I think is essential for a great neovim configuration is fuzzy finding your files and grepping throughout your project this one's a no-brainer you want to look at telescope telescope is unbelievable it's an amazing plugin it enables you in your neovim configuration to fuzzy find based on the name of files it allows you to GP through all your files to look for specific strings throughout your project and tons and tons and tons of other stuff there's even modules for telescope so look through all the documentation here it's worked on by one of the sexiest neovim contributors that I know of which is TJ pretty sweet TJ De devise de devise anyway we want to install telescope it's amazing so let's do that and if we scroll down to the lazy. envm section here we can see that we want to add to our T tub another tbal and then we have a dependencies tag here that is set to planer so we make make sure we install planner when we install telescope and we want to add this Tuple to our configuration so let's do that we go to our configuration where we have plugins we want to add a comma after this plugin and then paste our extra tupal in here now we don't need any of this extra stuff we can just do this based on what was given now lazy we'll include telescope in its plugins so if we close neovim and reopen it I believe it's going to install Telescope yes lazy has automatically installed telescope and planery pretty cool lazy is kind of amazing but we can't quite use telescope yet because we still have to initialize it now in the docs it says you want to set a local variable called built-in to the required telescope. builtin function now what this is going to do is he going to load up all of the stuff in the Lua file within the uh module telescope. builtin so what we can do is we can do vm. keap do set to contrl P built-in. findor files this is a function in the built-in module for telescope and it allow us to use fuzzy find to find files in our project so let's quit out of this reopen neovim and it was expecting a string and it got nothing of course I spelled something wrong which happens um basically I have JavaScript brain and I thought that I needed to have parentheses to call the function but actually what you want to do is not that I can now Source in it. Lua and that was also wrong I can Source in it. Lua and it looks like it's working correctly now so if I hit command or control P now I am doing find files which is unbelievable this is great telescope is amazing and when you find files you can fuzzily type what you're looking for and I'm in isn't that great now there's one more I like to do and that is live GP which allows us to GP throughout our project I set it to leader FG which for me is going to be space I didn't even set my leader yet so vi. g. map leer needs to be set to space so now if I type now if I Source this file and type space FG I am live grapping throughout my project I can type lazy and look these are all of the results from me searching for lazy awesome we're getting really cool stuff here Okay cool so now we're getting a lot of cool functionality of of our neovim config the next thing I want to install is a package that is amazing for doing highlighting and also indenting and that package is called treesitter treesitter is a package that provides a simple and easy way to use the interface for tree sitter in neovim and to provide some basic functionality such as highlighting based on it okay so what's tree sitter well tree sitter is essentially a tool that takes Snippets of code and generates an abstract syntax tree out of it why is that helpful well an abstract syntax tree basically keeps the information throughout the code base based on certain symbols that it looks for like say an open uh squiggly brace or an open and close quotes the abstract syntax tree basically takes all of these things and puts them into an easy to digest format for parsers and then people have developed parsers on top of tree sitter that then go through the abstract syntax tree and parse out the pieces that it needs to highlight the text that you see on the screen that's a lot but let's install tree sitter and see if we can see anything different happening here so now we want to add this to our T Tuple here for our plugins it is this and it comes with a build command which calls TS update TS is the tree sitter command so it's updating tree sitter itself so now to our list of uh plins here we want to add tree sitter so now if we leave and reopen neovim hey look at that tree sitter is installed and it probably ran TS update in the background I didn't see it get run here but I'm sure that's what happened so let's see if we can type that TS update all parses are up to date great now let's go to our knit. Lua file using telescope pretty cool and let's configure treesitter for our purposes so from the docs what we want to do is require neovim tree consider configs so very similar to how we do cat poochin or telescope we want to have a local variable and we want to call require envm Treet or configs so now in config we can call stuff like setup and the setup function is going to give us plenty of control over things within treesitter we can say ensure installed and that is a tuple that will include certain things I'm going to do Lua and uh JavaScript and what this will do is it will ensure that the parsers for these languages are installed in tre sitter you can also set it to sync install highlight indent which is what we want we want highlighting and indenting want both of these to be enabled because this will give us both highlighting and indenting obviously I type something incorrect I believe that's right yes I missed a comma whoops okay so now treesitter has installed JavaScript because we say insure installed for Lua and JavaScript and tritter also has Lua installed and now that we have set up Tre sitter by calling the setup function here for config we can see that we now have really really awesome highlighting and it looks amazing so now treesitter is highlighting our code it's indenting it and we it gives us a way to install extra parsers by using insure installed or we can use the TS install command and it's amazing just another huge piece of functionality in our configuration for neovim so what have we done in this episode well we've explained how the init.lua file works we then configured our neovim configuration with some of the initial things that that I like like two spaces for tabs things like that map leader is space and then we went in we selected a package manager for ourselves and we installed some really great packages to start off our neovim configuration namely cat poochin as a color scheme telescope for us to look through our files and do all that stuff and envm tree sitter for highlighting and indenting that's just the beginning of our configuration so stick around I'm going to have more episodes coming out next up we're going to cover something really awesome LSPs so stick around subscribe you're going to love it and hey thanks [Music] DS
Info
Channel: typecraft
Views: 216,030
Rating: undefined out of 5
Keywords: neovim, neovim setup, neovim from scratch, neovim from scratch lua, neovim setup from scratch, zero to ide neovim, 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, vim editor, vim plugins, neovim plugin tutorial, neovim lua config from scratch
Id: zHTeCSVAFNY
Channel Id: undefined
Length: 19min 48sec (1188 seconds)
Published: Sat Dec 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.