VimRC 2021 (Jan): How to setup your Vim RC

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
20 21 the year of the vim rc okay this year we're gonna get after this year we're gonna discover everything you need to make the most bang and rc out there okay the coconut oil will be full for an entire year if you can get this right because you know what here's the deal i mean i'm also sick of this right i don't want this for a vmrc just a single large file of just configuration that keeps on going i want something smoother better and more awesome so today we're going to go over how to set up your vim rc and then on top of it some special execution order and how to organize this so you don't have the gigantic mess that i have 2021 vim rc let's do this my theme experience is quite customized at this point in fact it's about 340 lines of customized vim experience that allows me to be able to pull up say my current get changes i can go and i can actually see uh the change list right here i can go through a whole slew of different things undo trees i can jump to the terminal if i want to jump to the terminal i can execute specific project commands if i want to right my vim experience has been highly customized and i did it only through a few lines of code well if 340 is a few right a few times 100 effectively but you don't have to go to that length to have a great vim experience so let's create a pretty good vim experience with a few lines of code afterwards i'm going to actually show you how i'm going to break up my 340 line vimrc and actually make it into multiple files for easier management all right so before we talk about the vim rc let's talk about where do you even put this vmrc what happens well when you launch vim when i do this what happens is that the vim environment itself gets initialized right they're going to have a whole slew of things that they do and then after that it's going to have a set of directories it's going to look into an attempt to load a rc from that and it's going to take the first one it finds if you are in neovim which is what i am in it will look for an init vim or an init lua if you are in regular vim it's going to do dot vim rc if you're a nano you can simply turn off this video and gently place the toaster you can just simply turn off the youtube video and you can go find that stupid rock you've been living under and remain under there for quite some time so if you're using vim simply put your vim rc in your home directory if you're using neovim simply put it inside of the dot config nvm directory that is where i have mine you can see it right here i just sim link it to my little repo that way i can live update it and i don't have to edit this spot all right so let's start our vim rc so the first thing i'm going to do is that i got to get rid of all this right because i don't think i should go through and try to explain 340 lines of customizations i have made for myself but instead let's talk about what you should do so let's first delete all that save it and re-open up vim nothing but bare bones neo-vim your your vim experience if you're on 8-1 should be approximately equivalent so first let's just open up this quick file one thing you'll notice right away is that default settings actually put a tab eight spaces non-expanded right so it's just a tab character eight length that can be a little rough little rough equals true right here okay that is not very great but everything else is effectively the same right i can hop between these i can highlight i can yank i can do all that right everything seems pretty nice right for neovim you'll get the default experience of your carrot or your cursor being that thin line i hate the thin line they call me old-fashioned i've just used vim for too long to like the thin line but nonetheless pretty standard experience maybe some things don't look as good as they should be right but you can get by with this but let's not get by with it let's make it better this is my vimrc right now as you can see it's completely empty this is the file we're working on not looking too good so let's start first with tabs so here are my tab options okay so if you get confused at what any one of these tab options mean or you forget what they mean you have a couple options here you can simply go help and then type in the words you see tab stop you'll go to the help menu for that tab stop you can also do options which will give you every single possible option that is available inside of them and you can search through it until you find the one that you want to find right so tab stop there you go here's like a shorthand description shift with the number of spaces look at this so it's like a nice it's something easy right you don't have to look through that whole help menu instead you get this nice little kind of synopsis little summary a little tweet if you will of what it means so let's take this and this is the one i'm going to use so i'm just simply going to close down vam and i'm going to reopen vim let's reopen up our old file our old test typescript file and let's go function test uh three and you'll notice now that we're getting something a little bit better right oh gosh even in tesco it bothers me we're getting soft tabs that aren't tabs and they are for long so this is kind of the experience that i wanted right all right so we've already improved our vim experience and it's pretty nice because when i do something like this you'll notice that it continues to indent correctly just a few lines of configuration and we already have a better experience all right i'm going to throw out a couple extra options that i just personally think are really valuable to have on so here are my options you do not have to have the same options that i have but let me kind of go over a good portion of them okay so xrc this is kind of cool whenever you do vim period meaning you're opening up a project starting at this point if there is a vimrc inside of that directory it will automatically source it for you so i use this to have a bunch of custom executions for various projects right i have little customizations for each project to be able to build it to run lint you get the idea gui cursor of course i prefer my cursor to always remain as a block so when i go into insert mode which i think right now i still have it is this i do not like that thin cursor it throws me off it's just not what i'm used to i prefer to always remain as a block relative numbers well let's just see what those do so let's go like this set relative number what it does is as i move around you'll notice that zero is the line i'm on and it will let you know the numbers up and down so if i wanted to jump down to sign column yes way down here at the bottom i could just press 12 j and i'll jump right to it and i can tell right away how what i have to press to get up there because i have the relative numbers on it just makes life a little bit easier now unfortunately my stuff is so disorganized that i should probably jump down here jump up and paste this right here because i also want set new or set number and what that does is it actually makes it so that shows me the current line number that i'm on so as i go down it'll say oh this is actually line 31. so it's a little bit better than zero i personally think so this is where things kind of turn into my personal customization no highlight search means that when i search when i press enter right now highlight search is on right because it remains right here i don't want that thing to remain highlighted after i get done searching it drives me nuts so instead of me every single time i get done searching i type in no h to turn it off i just set it as a default option so that it always remains off hidden hidden is actually really awesome you should definitely always have this on i have no idea why this isn't a default option but effectively what it does is it keeps any buffer you've been editing around in the background that means if you don't save it you can navigate away from it without saving it that means it's still open in the background yes you'll use a little bit more memory but let's just face it if you're using vs code right now you're used to a couple terabytes of ram required and maybe the few megabytes needed to keep an extra buffer isn't going to bother you that much so i love this one just because it keeps everything open and i don't have to have everything in a perfect state it allows for fast swapping back and forth between stuff without having to be worried about its current save state no air bells i think this one should be obvious i'd be shocked actually if this was not a default option at this point it is not okay well i don't like things ring and dangling in my ear balls okay that's not fun i don't want any of that all right we've already gone over all of these no wrap this one should be pretty straightforward effectively if you're in vim and you go all the way across it will actually wrap the text i do not like wrapping i don't want any of that so when i do set no ramp it will actually just make it go all the way over right it's just something i prefer smart casing you know what i realized as i did this i have smart casing on but i have ignore case off so smart case only works with ignore case a meaning that when i go help smart case what you will see is that it will do a simple search and if you use a capital letter it will then become a case sensitive search if you don't do a capital letter it will be a case in sensitive search which is actually pretty cool but you have to have ignore case on which i don't even have on so you know what honestly what what am i doing what am i doing with my life so i can just get rid of that once again this is a personal opinion i prefer to be in complete control i like you know i i'm kind of too pedantic maybe for that kind of stuff i like when i search for event with a lowercase e i want to find everything that has a lowercase e event right and when i do a capital e i want the capital e i don't want my capitals getting mixed up with my lower cases when i don't say so once again maybe a little too pedantic i don't know i don't even know all right these four kind of all go together it all is about how do you keep history you can look up what each one of these do but i i would recommend this uh especially these last two because it works fantastic with the plugin called undo tree which is from an editor that starts with an e which shall not be named in this channel and if you name it i will st i will bet i will ban your ass okay don't you do it but these four simply are all about just keeping history uh you can you can do help you can look them up this is my preferred setting i don't like swap files they end up causing a lot of just problems i don't need the backup i like the undo dir and the undo file and using proper plugins for it that is my personal love all right incremental search is fantastic if you don't know what incremental search is let me just show you i n c notice that it will highlight as i search that is very fantastic so if you don't have that on i find that i whenever i do uh like regex find and replaces it's a lot harder without incremental search on scroll off is an awesome one uh if you start scrolling down you'll notice that you don't actually go anywhere until you get to the bottom of the file or the top of the file so what scroll off does set scroll off equals eight as you get near the bottom it will start scrolling when you're eight away that's really nice right because that means you just kind of keep the cursor more in the center i find it also nicer for control u and control d jumping is because it doesn't cause my cursor to go all the way to the bottom but kind of keep everything more centered in the screen i'm going to skip a couple of these because these are more specific uh especially all of these these a lot of these are specific except for two of them so let me just put these two together right here these two i like a lot sign column what that does is it adds an extra column and this is really great for any sort of linting right uh so if i like this set sign column yes it's going to add this extra column and whenever i have say an error a linting error a actual like you know lsp error some sort of message that i need to see it'll actually put like a little e here for error if you have any sort of git integration it will put that little sign here inside the sign column i love that a lot and of course color column 80 where my heart's at i believe you should never exceed 80 lines of code it's just me to screw you if you think otherwise no i'm just kidding or am i kidding i don't even know really so there you go so i like this little bar right here to alert me the reason why i personally like this i know we're digressing here for a moment is that with four space tabs and 80 columns often whenever i start exceeding that it just simply means that i'm probably indenting a little too far maybe on my i'm on my third fourth or fifth indent maybe i need to rethink about what i'm doing and refactor my code a little bit nicer so it's kind of like a guideline for me i try never to exceed it but if i do i don't die on that hill but in the end it's like a really nice way for me to know how dirty am i being with my coat there are tons of options uh in fact there's so many options if you go to the options you can go peruse this to your pleasure is full uh but honestly what i do is usually when i find something that's a little bit goofy i tend to just go google it to see if there's any options just because it's kind of hard sometimes to search through this many options you find yourself getting too many of them right because then you're like well what about the cursor okay no no no no no no no no no no no no no no no right there's sometimes it's a little bit more difficult or you don't know the right word to say when searching for something so honestly either look through here get a quick google you could also use tab completion if you're just like what's that tab one again let's hit tab then you'll see all the tab help options right here right and then you can go okay well what's tab page i don't even know what that is and it'll give you a little breakdown of the tab page obviously that's not a set option but nonetheless it's a way you can search through help so now that we have a proper set of sets let's start actually customizing vim with some plugins there's quite a few options you can use for plug-in managers all right i used to use bundle bundle became deprecated now i just use vim plug uh there's vim's own plug-in manager itself i just like this one okay i just use it i'm used to it whatever it really doesn't matter it's like the least consequential part of using plug-ins is the thing that manages them all i simply want is a way for me to easily specify what i want any scripts that need to be ran upon installation or updating and that's it and the rest of it is taken care of for me so i use vin plug you can check it out go look at how to install it whatever it's pretty straightforward and once you have that you'll notice right away that now that i've sourced my file again things are starting to look a little bit different i didn't even change anything other than this it's already getting a little bit more spicy now that i have my plug-in manager installed all i got to do is add these two lines and add in plug-ins in betwixt to them so i'm gonna jump over here i'm gonna grab telescope telescope's a fantastic plug-in by our very own tiege and not only that but it's like an fcf replacement but it is neovim only it's largely lu it has fuzzy finding all this great stuff it's fantastic plug-in so i just like this plug paste it in and that's that and then i like this plug install it goes in here it goes out it clones it it's done that's that and so now i should be able to use telescope but you know what you know what kind of bothers me i want a better color scheme than this okay because this color scheme it's not it's not doing it for me okay this is not doing anything for me all right groov box community edition go in here paste that do that uh do that get that extra eye in there just you know because i like to assert my dominance and then remove the eye do that give the old shout out right here and then of course plug install get groov box installed yes and then go color scheme groove box that is so much better okay gosh i've been i've been struggling there for a little bit so let's add in a couple more lines right because i'm going to want that color scheme groove box and of course i'm also going to want that highlight whatever this is so i can have my sweet animoo background i was told i'm supposed to love anime so i love i'm tr i'm trying to i hope i love the correct animes i don't even know there we go we got him and now i have groove box on i have my fuzzy finder ready to rock this is fantastic so this is kind of where you needed to go discover what plug-ins you like personally some of the big ones are going to be the neovim lsp so if you're not part of the lsp whatever i mean i can't help you if you're not part of neovam you don't your editor doesn't come one yet to go ride the have fun with that one so neofim lsp telescope fantastic ah tree sitter groov box community edition of course undue tree fantastic fugitive i mean it's t-pope it's t-pope you can't i mean come on come on come on t-pop t-pop by the way t-pope your hair it was so beautiful what happened man all right so as you can see adding plugins isn't too hard you just gotta go find the ones you love okay but here's the deal how do i even interact with telescope well let's talk about remaps remaps aren't all that hard it really only you only need to know three things first you need to know the mode you want to remap second you need to have a left hand side or it's the thing that you need to execute to execute the remap and the right hand side it's the thing you're going to do when that remap has been hit or the sequence of keys has been done so let's talk about one right here so i'm gonna go like this n for normal mode right now i'm in insert mode then i do a nor for no recursive execution meaning that you can actually have these things recursively execute you can have remaps that actually execute other remaps i know that's crazy for me so i always keep it nor right and then simply map so that means i'm gonna have a normal mode no recursive execution map and let's do something special let's do leader project search and then let's re-execute this to actually use telescope to do a word search over this project and then now let's do the right hand side which is going to be this command right so what we've done here is i've required i have executed lua required in telescope and i'm going to grep for a string but first i'm going to use the vim input function to request input from the user all right so let's shout out this file shout out percent sign and let's execute this but what's leader i have this thing i've never seen what this is leader is a key you get to choose and you can use it as a way to set how you do shortcuts so what i like to do is i like to set mine to so that means when i do space ps it'll actually execute this lua code and it'll give me the grep for string underneath so now i can go okay let's search it for nvim lua and it'll say up here's your two places that you have it i can jump there it will open it up this is fantastic i've now set one of my remaps so this is kind of how all these things end up happening is that you will install some set of plugins then you will have to have some remaps that make sense for you like if i want a project wide search this is how i want it to be set up this is where the power vim really starts to shine you get to determine how shortcuts look and what key sequences to use now personally i would definitely choose space as your leader key uh my primary reason why is a lot of people will also do comma the reason why i do not like comma let's say i want to go up to uh this a right here or this e right here i want to so i want to jump to this e right here so i press fe and then i do semicolon semicolon and i'm jumping forward to the e and i overshoot it well how do i go backwards comma if you have sp leader as comma there will be like a 50 millisecond to 100 millisecond to some amount of millisecond wait i'm sure that's even customizable that you have to wait before the comma itself will be executed and that drives me nuts i i can't do it so instead i just like simply to have space all right so in general this is how i tend to do my vim rc is i have all my sets up at top i then have my plugins then i'll have kind of like my basic kind of more editor settings and let's right so i have a let map leader there's a bunch of let's you'll do for various plugins i have them all defined and then at the bottom i'll have my remaps and then even after that i'll have my auto commands now we haven't gone over auto commands yet auto commands are exactly what they are they sound like right they're just something that happens automatically for you and you can listen to a set of different events that happen kind of think of it like if you ever do javascript and you have say on key down callback that gets called every single time someone presses down a key you don't have to ask each time to listen to the next event you just simply say i want to listen to all of them and i will do the logic to filter and do the appropriate action each time so let me show you what that looks like so the first thing i'm going to do is i'm going to paste in this function don't worry about this function it's obvious what it does is that it trims any trailing white space now i'm going to paste in some auto command good stuff right here so here we go so let's kind of explain this so this is vimel you don't have to learn it most of the things you need you can find right off the internet honestly it's not it's not too bad i found this off the internet stack overflow perhaps but what you need to know is how to use them so the first thing i do is i create what is called an auto group what this means is that all of these are going to be grouped together and each time i source this file i will remove all of the listeners that are within this group and reattach them the reason why that's important is imagine you source your file a couple times and you didn't remove the previous one you could execute this the amount of times you source it say you sourced it five times you could have five listeners trimming white space five times for you you could have some legacy things happening that you've already removed still happening until you exited them and relaunched it so that's why auto groups are so cool because you don't want to clear out all the auto commands because then all your plugins may not work instead you just want to clear out the ones you've set up so i have my own auto group right here the primegen and then i clear out all the commands that are associated with this group and then i set a single auto command this auto command before i write my current buffer which by the way this window that i'm looking at this is the buffer that i'm editing i'll do it for all file types and the action that i will do is i will call this function called trim white space with no arguments that means it'll call this it will trim all the white space and then the rest of the buffer right hooks will all execute so let's look at what that means all right so let's take this out and let's add in some white spaces and when i save as you can see we got ourselves some white spaces now so let's bring it back in shadow percent sign and now you'll notice that white space is gone if i retry to do it again white space is gone so you get the idea these are auto commands there's a ton of auto commands so let's go like this help buff right pre you'll notice it's right here there's a bunch in here but if you scroll around you'll see that there's tons of commands that you can do tons and tons of commands and these are all hooks that will happen you can specify what type of file types and all of that that you can execute them on all right so this concludes kind of the vim rc intro approach still there's gonna be a lot of work for you to do to make them the way you want it to be i can't do that for you okay you can go check out my vim rc linked down below so now let's switch gears and let's take my vim rc and let's actually make it a little bit more robust a little bit split up a little bit easier to use because honestly i have a fuzzy finder i don't need to simply have one big file i can split it up logically and make it easier to edit each one of my plugins and the settings i prefer and even to find those settings so i don't have to search through a multi-hundred line file all right so let's break up the vim rc effectively how vim works is that first vim itself will run it'll do load up all the stuff it needs to load up to be successful in your system then it has a set of runtime paths it will look in for your vim rc or your knit vim slash and knit lure if you're on neopim once it finds that it'll execute that line by line after that it will load everything inside of the plugin folders found in all of the runtime paths and then they'll do an after and then there's some other folders file types blah blah that get loaded at various times auto loads on the fly all that there's a bunch of loading that goes on but right now what we should be concerned about is that after it runs your vim rc it will run everything in a plug-in folder found in the runtime path so what i'm going to do is i'm going to break up my entire vimrc and pull out every single plugin and make it its own the first thing i did is i took out all of my sets so now my sets are all just simply a single file in plug-in sets them like that's it that's all it is and along with that i also have an install script where are you install script there you are that simply make sure that i have the folders properly created in my config neo vim plugin after plugin and lua and then i find all of the files and just automatically sim link them over that way i only need to run this when i create a new file everything will always be kind of similar to nicely so let's check out what i did so how i get my colors is i have this little fun function called color my pencils it'll go through and it will load what i want and then it will call it to load it and then i'll also add the leader now i don't have to have this in my main vim rc this will be loaded after my main vmrc and it'll ensure that i have the proper colors i also have my fire envium settings really i don't need that inside of my main vim rc this is just for fire enveim right i don't need my all my telescope stuff because that's specifically for telescope right net rw oh yeah lsp oh yeah look at the look at that look at how many lines were dedicated just to lsp that i didn't need let's get that out there we don't need that do we baby come on no we don't but either way i split all of these up and now let's test it out so when i load it it's all over there it's all there telescope works it still use the same control p that i had so okay everything seems to be loaded let's go to parse frame this is http 2. let's look at this http 2 parse frame let's see what an http 2 frame is i'm going to use my jump to definition there you go it all works it works exactly the way it was working beforehand the only difference now is that my vim rc is tiny it has the plugins that i use fantastic and then it has a series of pretty much all vim items right i can have my sex if i need to have my sex i have my vex i have you know like moving things up and down look at this oh look at this sweet one oh yeah look at that look at that it's just right there how sweet is that anyways i have my just all my vim specific stuff in here and i don't have to have any my plug-in stuff in here anymore obviously i still have a couple you know scraggler still sitting by but whatever they don't i could move those out as well this honestly makes management of my vimarcs way easier so now i can just simply go like this uh lsp i want to go look at my lsp settings i can see it right there my plugin there we go okay i want to change oh i have duplicates right there let's get rid of that one boom i've just saved it the sim link is now updated next time i start vim it'll be great that thing will be gone va will not exist anymore personally i think that this is gonna be one of the greatest changes i've made to my vmrc in 2021 maybe even be the best ever i'll have all the links down below i'll also have a link out to tj's uh version of his right here so this is one of the core contributors of neovim this is how he has everything set up we probably will have somewhat similar setups i will also link out the discord there is a ton of questions answers and just cool plugins that are shared within this discord we have you know 1400 people in the discord lots of him enthusiasts check it out link down below i also stream on twitch check it out we build vim plugins i program for netflix who knows what i'm going to be doing on stream thank you so much for watching my name is the primogen year 2021 it's your greatest vim rc year of your life hey i okay hey hey hey i understand that undo tree is from that editor you like okay that that e editor okay okay hey hey hey hey calm down okay i understand that you know what i admit it that you could have at least one good idea and that is it
Info
Channel: ThePrimeagen
Views: 178,227
Rating: undefined out of 5
Keywords: software, vim, programming, javascript, typescript, software engineering, web developing, web developer, software developer, developer, cpp, programmer humor, humor, reactjs, js, ecmascript, tc39, Netflix, Engineering, Engineer, Facebook, Amazon, Interviews, Software Interviews, vimrc, neovim, spacevim, vim c++, vim editor, text editor, vscode, vscode vim, vim plugins, autocomplete, vim autocomplete, nodejs, twitch, developer productivity, spacemacs, algorithms, datastructures, Data Structures
Id: DogKdiRx7ls
Channel Id: undefined
Length: 27min 40sec (1660 seconds)
Published: Sun Jan 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.