Vim As You Editor - Advanced Motions P1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my name is the primogen and i have been using vim for about 10 years now and i'm pretty fast at using these motions i just wanted to share with you ways to use vim better because the problem with vim is that there's a lot of ways to do things and if you're newer to vim you're probably inundated with the different ways in which you can accomplish various text editing motions and commands and i want to help set you on that right path that good path that coconut oiled path so let's do this let's master some vim motions specifically i find one of the most annoying parts about vim when i started off was the horizontal movements so getting fast at that is huge and we're going to go through ways to get fast coconut oily fast that is i did want to start with something kind of like a little pre-note here if you're not comfortable just doing something like like that just wwcw really quickly and being able to cut out and start typing in something different i i do emphasize that practicing the basics will help you in the long run if you do not feel creamy smooth with w with f and t then you probably need to go back to the drawing board and get good with those ones i have been developing a program called vimby good which i will be upgrading here soon in which has games to become good at these motions honestly just practicing relative line jumping uh w's f's and t's you will honestly get really fast but i want to go even faster so for those that are feeling extra amazing let's go over some very i don't even have a word to put in there yeah so let's just do this alright so the first thing i want to show you is jumping forward text object commands now back in the day if you were to ask me to hey highlight this this type right here and let's replace it with bar i would have done something like this i would have jumped forward to that pressed v jumped to the end yanked it out walked down forward vw back it up one paste it now that's a probably a pretty standard way most people think when they use vim you're using the basic commands and you're using them fairly fast and you can honestly get a lot done just knowing the basic commands so if you're not familiar there's there's this actually pretty neat thing so if i'm in between these parentheses and i go vi parentheses i select everything within those parentheses if i go within these squirrely braces and i go vi within those squirly braces it selects everything in there i can also do a v a squirrely braces and it selects everything and around okay this is very very good to know that means if i am before a squirrely brace and i'm not in between any squirrely braces and i go va squirrely i'll actually select the next one in the line that's pretty awesome it doesn't i don't believe it works with older versions of vim if you're in sevens and below but i believe it works at eights and it works in the latest neo vim if not you can always jump forward to it and then va squirrely brace and it will still work but for our case if we wanted to do this quick we could do y a squirrely brace yank everything in between the squirrely braces plus the squirly braces themselves then i can just do a four down word over viw now i always use a viw and the reason why i always use viw is it doesn't matter where i'm at within the word it always selects that so viw selects it if i'm in the middle viw selects it awesome and once i do that i can just simply paste and i'll paste in that type this is a move i do all the time i'll select something out jump to what i want to replace either do a viw or a vi capital w meaning i select all text until white spaces and then paste over it it's really really nice especially with types with colons in them you can replace types quite quickly so let me actually give you an example that let's pretend we're right here in the result and we want to use that some long type as the return value of our result in rust now there's a couple different ways in which we could do this but the fastest most amazing way is actually to jump back to the closing parentheses and then do a y i capital word that means i selected everything that's contiguous contiguous text jump forward to this bracket paste it in replace it with a bracket and so you can actually accomplish that pretty fast so i love the iws and the capital iws over selecting sometimes is fun and even has some advantages because i think before what i would have done is i probably would have jumped back by space use semicolon to walk back forward one with either l or w v t that yank it jump forward paste it in a that exit right that's way too many steps when really all you need to do is just simply jump back to that select the whole word jump forward paste replace right it's just that simple it's that simple i know this is a lot that's why i said you really do want to be able to master the concrete of this all right master the concrete that's actually not a phrase nobody uses that phrase i don't even know where i'm getting it from okay i don't i don't even know where i'm getting it from but having like a really strong grasp on the fundamentals to the point where you don't have to think is incredibly important and i did want to make a note about capital f jumping or f jumping one of the problems i see with that is that when you do these jumps you have to understand the character in which you want to jump to and if there's any characters in between you have to use semicolon or comma to jump backwards or forwards within that list and for me that's a lot of overhead that's why lately i've been doing a lot of y i capital w's or y i w's because what they do is they allow you to just select a word and it doesn't matter what you need to select up to it just will select the whole thing and for me that is a lot less mental overhead than yt closing brace because it doesn't matter a where i'm at within it and b i don't have to look for the closing brace and then jump too up to it but not including it right there's just a lot less overhead just to go ah just give me the whole thing i can fix that later on and so i could jump here i could va uh you know whatever that thing is and i could paste the whole thing in if i wanted to replace it or i could vi that and then paste it in now one of the problems that just happened there is that when i did that when i pasted i lost what was in my paste buffer paste register it's not a buffer buffers are where you put text registers a lot different there so a super cool remap to have is leader p if i'm in some sort of visual mode and i do leader p it will actually do a delete to the underscore register which means that it just it's gone and then it'll capital p back into that paste let me show you what that looks like so let me change this type to say uh you size right notice that i just did a ci capital w right i didn't have to think about jumping it didn't matter where i was i could just delete the whole thing so now i'm going to do a yw i'm going to jump into this and do a vi carrot and instead of just pasting i'm going to space paste now using that remap what it just did is it replaced everything right it deleted and then pasted it backwards but look what's still inside of my register i still have the use size as opposed to that some type extremely useful to have and to get into the muscle memory to use when you need to do it because sometimes the find and replace sucks right you don't want to have to type out a huge thing for the find and replace instead you just copy it once and you go to the two places that you need to find and replace and then you can just use lead or p to paste it in without losing that paste i don't know i thought it was awesome i thought it was awesome all right so another thing i see a lot of people in vim never take advantage of is a not using something like y y but instead you shift v y the reason why is you get the exact same effect but it's way faster to press two distinct characters than a single like a double tap i hate double tapping i like that kind of that double tap not the other double tap same thing works with vd it's not venereal disease you just simply visually delete that whole line and it doesn't matter whether it's capital uh y or lowercase y same effect as yielded all right so like i said a lot of people never take advantage of already having some of the text you know typed so right now i want to be able to create this serialized buffer method it's going to be a private method so i can jump down paste it in private four jump buffer di squirrely f to the bar dt squirrely brace now notice what i did is i didn't have to type nearly as much and it kind of made it like into a fun game now one thing i really think is important with vim is having fun along the way and for me running these large amounts of sequence of commands is actually really fun because it's like okay i gotta maze my way through right i gotta jump to this one type in a word jump out delete everything inside of it jump forward delete right like you're just like bam bam bam bam going sequentially through the line i find that to be just out of this world fun so that's kind of like a double whammy tip right there make it fun use vyvd and if you already have a line use it so i did give you guys a lot of cool things to be practicing horizontally hopefully that made a lot of sense if you like this subscribe to this channel already press that button if there's any motions horizontal motions that you feel like i didn't really take advantage of or i'm missing let me know in the comments down below if this blows your mind then join the discord or twitch and quit being a pleb and then on a like a final note uh something that's really important to me is having fun so i hope ultimately when you see all these things it's not discouraging but instead it's encouraging that there's still a lot more you can do with vim that it makes you feel like you really want to master these things for me it's it's that intersection of having fun making it feel like editing is a game and getting things done that i just love like when i'm in the zone and i can just edit text at an incredible speed and i'm having a good time doing it for me just enjoy it love it well thank you very much for watching the name is the primogen ghost ride to whim
Info
Channel: ThePrimeagen
Views: 205,432
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, python, bash
Id: qZO9A5F6BZs
Channel Id: undefined
Length: 9min 44sec (584 seconds)
Published: Sun Sep 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.