Vim Navigation Commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
great hey everyone so thanks for having me thank you for just being here and listening I don't speak much so it's really cool for me and exciting so I really appreciate that so I'm going to talk about navigating within a file primarily in vim there's two reasons I want to talk about that the first is I think that its beginner and you're learning vim thinking back to me it's really hard to just do anything if you're not comfortable moving around in a file I remember when they gave up my mouse I felt really claustrophobic but not the scrollwheel it was pretty easy for me to get to where I wanted to go but then to see everything I wanted to see was really difficult additionally I have this theory that for sort of more proficient people using them it's really easy to botto with your knowledge right once you could do what you want to do you just do it right so if you can do it three commands instead of one it's good enough right so there's no reason to take the five minutes and and look it up on Google so I just want to go over sort of a lot of really basic commands so if you're really great at min maybe you'll know them all but I have a feeling everyone to learn one or two so now everyone will have sort of no excuse for not knowing them my name's Daniel I work at a small digital events agency my work primarily rails all today so I'll be working around our be file from the demos I'm a few of any feedback feedback is really great I really love it just tell me after that would be helpful or you could always a tweet at me if I'm a Twitter common nighthawk see mmm all right so now let's pop over to BIM so we'll start with a super fun quiz oh I mean I spot a questions and if people wanted to shout out answers that would be really helpful in vim sometimes it's tough we're in typing and you can't see what I'm kind of things so just shout out to scenter up to me well we'll do it again all right so let's start with the question say bottom line on the screen to the middle of the screen and I want my cursor to be there so outline 22 to be in the middle of the screen and that's where I want my cursor to be so anyone could anyone do that that was easy capital lzz that's right does anyone have another way I thought of another three keystroke command shift G Z Z it's the bottom of the screen so line 22 so that the screen is sorry the files 200 lines on control B I have no idea yo ctrl ctrl D yeah fools a full screen so the other way I was thinking about doing it which we were just getting to was controlled d sorry controlled DM so and just to move the cursor after control date so if those seemed like obviously some people know how to do it if they seem a little bit magical that's ok we'll get to them in two slides we'll go over them hopefully that was sort of the motivation for everything because right you should be able to do that if you want to get the bottom of the line for the middle of the screen you could do that really easily in sublime so it should be you know something complex to do with them all right so starting with the most basic command line wise navigations so I'm sure if you're cool enough to go to and meet up you know these so J to go down a line K to go up a line you'll notice the screen doesn't move when I do that but it will when I'm off the screen but you'll have some implications later to get to the bottom of the file capital G to get to the top of the file GG obviously what makes them great is with all the commands you can set a number in front of it so if I wanted to get to line 5050 GG alright so now that was sort of navigating around the file at large but say we wanted to get around the screen so if I wanted to get to the last line on the screen does anyone know how to do that we covered it before what's up no so we'll get to that dollar is important it's getting line wise navigation so L gets you to the last line on the screen capital L thank you m capital M gets you to the middle line in the screen and H gets you to the top of the line of the screen so the mnemonics for that or high middle low so L low and middle age high I think that G commands pressed these are super important to know it's super useful and there's really no reason not to know them are there any questions about any of this cool so now we'll go over shifting around the screen which was something that these commands were really helpful to me I don't know why they're not been tutored more publicized them but they're they're really important all right so say I get down so let's say I want to work on the apricot method I search for it and now I'm on it but it's on the bottom of the screen which is pretty inconvenient so if I want to send through that I hit ZZ to get it to the middle of the screen that's a commanding is a lot I get to where I want to go and then I Center it I really need to see what's above and below where I'm working so that one's really helpful I believe Z dot also works I have less occasion to use that so similar commands RZT puts your current line on the top of the screen which is really great a lot of times you know you'll search for private and then ZT see everything below it ZB gets the line you're working on to the bottom of the screen I think that's less of a use case but you know probably good to know all three all right so say I'm working on this apricot method but now I I want to shift the screen down one line or two lines but I want to keep the cursor where it is that's right ctrl e so when I was first learning I go down J and back ji and that sucks right so ctrl e will do exactly what we want to do and control Y is the inverse of that I think of E standing for end gets you to the end a little bit I don't know ally stands for that's right they both take account I'm so right ten control e does what we want to do those are really helpful for one offs and when you get to the method and you know the last line of the method just isn't on the screen all right so if we want to jump by things bigger than that we could use control D will take us down half a screen at a time you'll see that no matter what the cursor moves so even if there's enough room for the cursor not to move control date moves the screen down half and moves the cursor down that much D for down you for up so control D and you are great for sort of thumbing through half the screen at a time and then to make bigger moves control F will take you down one full screen at a time and B for backward so if you open a file and you don't know exactly where he needs to go but you sort of want to thumb through it somewhere at the scroll wheel either ctrl D or ctrl F are gonna be your best bets I find these really jarring I find it not so helpful to follow so just a quick plug for smooth scroll as a plugin I use it sort of animates it as it goes down so you can keep a little bit better track because I tend to get lost it just looks like sort of discontinued screens to me oh so the result of our game should now make sense so I think Mike's first answer was L Z Z so L to take you to the bottom of the screen is easy to Center it and then the other three three character thing I came up with was ctrl D takes us down half a screen which is the same as moving the bottom of the screen to the middle of the screen and then just getting the cursor to where we want em in the middle any questions about moving around the screen cool alright so now we'll do within a light navigation which which we touched on a little bit so to get to the beginning of the line does anyone know zero great let's get to the end of the line dollar perfect so does anyone know first non blank character online great does anyone know last non blank character of line but there is it's G underscore yeah I think carat will solve almost all of your use cases instead of zero for some reason zero seems more popular so carats really good to know I'm left for some reason you want to delete indentation but even that you can do it a better way there aren't that many use cases for G underscore obviously dollar signs great I've had one a lot where I'll paste in some text from Stack Overflow and it'll have all these airings white spaces and the spacings really off so all of these commands are also really good for writing macros so I'll write a macro so there is trailing whitespace here in this line so QQ to start a macro G underscore then I'll move to the right and then D dollar sign to delete to the end of the line then I'll move down a line and quit the macro so if I want to run that back Q will do it again and then I could just keep doing that so that's been really helpful for you know when I have 20 lines that come in from Stack Overflow probably thousands of whitespace I couldn't find a better way to do that doing a little research apparently finding a place is probably a little bit smarter I think some people in their MRC have delete all trailing whitespace when they save their files but this works nicely for me and I didn't I didn't know G underscore was a thing for a while so I wanted to share that so those are all those are all really helpful for money writing macros one thing that you need to consider right when you go down a line both times you start a macro with the carrot or something to get you to where you want to be before you begin because if you write a macro when you're before the thing then you go down a line and then you're after the thing you need to always worry about resetting but if you use any of these you don't need to be worried about resetting right if you're before after the first line carrot will always get you to the first character in the line all right so those were all been navigating within a file this is just some extra fun stuff so Sam all the way down here but instead of jumping to line 10 I want to get 10% down the file does anyone know that command so it's just 10% so 10% will take you there what the you cases are I don't know sort of cool you know where you a lot of these like 90% down and you could just hop there it's just n followed by percent so without anything proceeding it yeah so like instead of GG your place to GT with person admin so 5% gets us right there yeah it seems so like look I would have hit it by accident almost it's just it's it's like right on top and no one talks about it so one great command that I would guess most most beam users know is the asterisk what the asterisk does is it searches for the word that you're currently on and it takes you to the next occurrence of it so I have highlights on so you'll see all the occurrences of true get me there so what I'll do a lot it's all hit asterisk and then I'll hit the big end to move backwards I think asterisk sort of gets all the credit for this type of search but what pound does is it does the same thing but after us but in Reverse so if you want to go to the previous occurrence of something I'm just an asterisk and that'll take you right there alright so the next thing is um it's not really about navigating around in the file but I just think it's really important I'm surprised how little it's talked about so their word wide motions that everyone knows about so but it brings you to the question quickly of what is a word so e takes you to the end of a word so if I hit E throughout this you'll notice that it it breaks a lot breaks not as in fouls but just stops so what we learned is that words are - delineated they're also period delineated and an exclamation point delineated but if we jump down to this word and we type a it jumps to the end right so it just begs the question what is a word and they're delineated by a very specific set of symbols that you could look up and I think you know they're fairly intuitive but what if I want to act on this entire thing as a word what if I want to delete this it in one go so if I type DW it doesn't work if I wanted to lead till the end but if I type D I big W that does so basically in vim there's a difference between small words and big words so W stands for small word capital W stands for big word and the same goes for E and and B so if I want to delete this entire thing and if I wanted to leak to the end of this and one go DW doesn't do it but D Big W does do it does that make sense so really helpful is just you know di Big W I use that a lot because obviously classes are parried delineated and things like that cool all right the very last thing I'll go over or marks I think some people are a little intimidated by marks but they're super easy so I wanted to just go over them very quickly so say we are C sees a new method say we're working the BlackBerry method we keep coming back to it right we do something down at the bottom of the file we keep going back to it so one thing I used to do was I'd say okay so I'm like 57 try to remember that I'll go back to line 57 that's a terrible way of doing it so you could set a mark and to set a mark followed by whatever register you want to put it in so nm mister the same way q is common for macros just because you hit the same key but you could put it into a register if you wanted so let me throw out let me put em em here so I've set a mark called M on this this line on this space now if I go down to the file and I'm doing something down here and I'm ready to go back I hit back tick and that takes me exactly to where I set the mark if I set the mark and the a register it would be back tick a going back down here again if instead of backtick m i had single apostrophe m that takes me to the first character in the line where the mark was seven i'm so depending on your use case you could use either of those um single sorry lowercase letters are reserved for specific to the file capital letters are reserved for within files so if you wanted to set a mark capital b v and your vim RC you could pop to it from any other file this is everything I'm sure it's not helpful down but I think it'll be good cheat sheet and I'll make the slides online and that's it curious if any one you all yeah I mean here do you understand cool so if this happens can open up for a few minutes if anyone has any great commands I missed I'd love to hear them and I'm sure the group would and if there's any questions yeah that's right yeah you're right I like that a lot just to go over in case anyone missed it so f takes you to the occurrence including it and T takes you right before it so I have blackberry and JDK F sort of comma-separated right now if I do D F comma it deletes everything including the comma and that would be great right if I instead of just deleting this word I'm not going forward but the inverse of that is DT comma if I want them to save the comma which is helpful depending on what you're working with yes that's right so so FF basically puts somewhere that the last thing I line wise searched for was F so I hit semicolon to move forward and I hit a comma to move back and that's good because it stays in the register too so if I was up here I had another Falls and I wanted to get to the last one comma will take me there cool what do you use that for I sort of see the like English language ones and our little dismissive of them wait so did curly brace from here and do a close code that's right I actually opened it with with Nova Marcy just so it's applicable for all operating systems and that's cool so it's like blank line delineate exactly I like that thank you yeah that one's good so this is the percent command it matches I don't even know how to describe them sort of equal and opposite pairs with sort of curly braces and parentheses and I think quotes as well so if I want to jump to the beginning of the ends and same with that that's the percent key and I think backtick backtick takes you to before you made the last jump Sara yeah I don't find that very helpful because J and K are not jumps this jump list is a little counterintuitive to me but yeah those are really good that just goes back to your jump register mm okay that could be different from the cream based on right the order does it's not the last degree doesn't the less time is the same as control six yes the original right that's debatable
Info
Channel: thoughtbot
Views: 112,856
Rating: undefined out of 5
Keywords: thoughtbot, Vim (Software)
Id: Qem8cpbJeYc
Channel Id: undefined
Length: 21min 42sec (1302 seconds)
Published: Wed Oct 14 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.