Mastering the Vim Language

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This is a good video to watch if you haven't before, a nice introduction to the concepts. Good speaker, good content that is easy to understand. thoughtbot has a bunch of videos on vim from meetups, this link is to their playlist of them:

https://www.youtube.com/playlist?list=PL8tzorAO7s0jy7DQ3Q0FwF3BnXGQnDirs

👍︎︎ 24 👤︎︎ u/textandmetal 📅︎︎ Sep 12 2019 🗫︎ replies

Legendary

👍︎︎ 5 👤︎︎ u/Two_Souls 📅︎︎ Sep 13 2019 🗫︎ replies

That was the talk that made all the difference in vim becoming my one and only editor.

👍︎︎ 5 👤︎︎ u/michaelloistl 📅︎︎ Sep 13 2019 🗫︎ replies

One of the better videos... I member

👍︎︎ 3 👤︎︎ u/BlubbTheFugu 📅︎︎ Sep 13 2019 🗫︎ replies

I watched this the other day and found it super useful!

👍︎︎ 2 👤︎︎ u/dumbdata 📅︎︎ Sep 13 2019 🗫︎ replies

He said insinuated he was going to talk about "the other" text editor worth talking about, but I don't think I heard him bring it up. Did anyone catch anything like that?

👍︎︎ 2 👤︎︎ u/loopsdeer 📅︎︎ Sep 13 2019 🗫︎ replies

this is one of my fav intro to vim vids

👍︎︎ 2 👤︎︎ u/x_ero 📅︎︎ Sep 13 2019 🗫︎ replies
Captions
Oh my talk is called mastering the vim language which is an extremely lofty title that I will probably not live up to but I'm going to give it my best so vim is an extremely interesting editor it's one of frankly the two very interesting editors we're going to hear about both tonight how exciting this talk is going to be about my recent probably over the past year kind of focus on what really does make them unique what makes it special and how can I get better at using those features so a quick introduction to me for anyone that doesn't know me my name is Chris to me I work here at thoughtbot they're kind enough to provide the pizza and space and beer and friendship so all good things I'm on Twitter as Chris to me and I'm at a blog as see to me calm so you can find me at any of those places and happy to chat with you about anything so I love them this is something that you could probably guess about me as someone who runs a vim meetup but I really do it's by far my favorite tool that I use and it's also the tool that I use the most there are many features of it that I love many things that make me happy when I use it but one of the core pieces is that over the many years that I've used it I've yet to hit the ceiling I've yet to find that edge where you know what I've learned it I got it all that's definitely not something that's happened and in fact I've met no one that I can think of that has found that edge that it said like I've got it I know all of them and so this might seem like something that's actually not great that's kind of a negative but to me since this is the tool that I use most every single day I love that I can constantly sharpen that so I can constantly get better at it I can adapt myself or the editor better to my workflows I don't want something that has a ceiling frankly I want to keep getting better at it and then definitely delivers on that front and I think this is actually really important and somewhat undervalued a lot of people talk about how fast you can be in vim but for me it's not really about speed speeds nice it's a benefit that I do get from using them but it's not the key reason that I use it I use them because I don't have to think that's a lot of people reference this quote not actually related to them the original quote but typing is not the bottleneck and so they're talking about well you know what sure you can be fast into them but that doesn't really matter typing is not the bottleneck the original reference this typing is not the bottleneck quote is related to TDD but I do hear it sometimes used as an argument as to why like vim is probably not worth it and I agree the speed alone is not a reason to use an editor but the corollary to typing is not a bottleneck I think is actually really interesting thinking is the bottleneck that time I spend not typing that time I spend thinking is the most important and I'm limited in two ways I'm limited in time related to that like it just takes some time to think but more importantly to me I have a limited amount of thinking that I've found to be useful within a given day I only have so many units of thought that I can put out into the world and frankly I want to spend zero of them on my editor and that's why I love them them gives me a language to express the changes that I want to make in the most concise efficient and easy to interface with way that I've ever found I don't speak VIMS language then speaks my language and that means that I don't have to think about it I kind of just put my hands on the keyboard after I figured out the change I want to make and it happens that's kind of magical but it's also really practical and that I'm not wasting any thought cycles on telling the editor what to do so VIMS killer feature is the language that it provides for defining changes so just as a quick introduction to this general concept most editors as you type on the keyboard it's going to literally enter the character that you typed into the document that you're editing it treats that inserting of text as the primary action vim spins this on its head and says actually most of the time especially as programmers but even generally as writers we're editing we're not writing we are going through and we're changing text that already exists so then chose to optimize for editing text and I believe that that was a very good choice it gives you a whole language to express the changes that you want to make very concisely repeatably undo ibly it has all of these wonderful features that fall out of treating changing text as the primary concern so let's break this down to get a little more practical the syntax of the language is broken down into verbs and nouns operations and text that you want to operate on so for instance we have a very simple example here D and then thank you let's pull this over here to D and then we'll delete but it's going to wait until you tell it what to delete W is for word so d w typed in sequence will delete a word and again just to keep this nice impractical I have a sample document here and if I happen to be at the beginning of the word initialize D W will delete that word that's a nice little party trick on its own but it does demonstrate the core of the language we have operations and we have the text that we want to change so well undo that here we can come back to the idea so let's talk about this at a little bit higher of a level we'll break it down to the two sides of the verbs and the nouns so actually before we go into that I do want to talk about the idea that these commands that you give them a command being a combination of an operator and a noun have these really great features that they're both repeatable and undoable so if I come back into this document I made that change here to delete a word and now if I move around I can go anywhere else in this document and by typing dot them remembers the last change that I made which happen to be delete a word and I can use this anywhere I want any word that I find in the document I can repeat that change and that change again is that combination of the operation and the noun even better I can undo these and you'll note that when I undo them they undo is these atomic operations it's not individual characters that are being restored but it's the entire word it's that distinct change that I made that I can now undo so I can define a change and then I can kind of stamp that out through the document repeating it as necessary and very directly undo it in the exact way that I did it this is extremely powerful and we'll talk about this a little bit more later on and how you can leverage this but there's a really important characteristics of the language that Ben provides so coming back to the syntax of the language again we start with verbs this is the operation that you want to make so here I've got a sample of them there are more than these but just to focus in on a few D will delete and again that's going to wait for what you want to operate on C will change which is delete and get ready to insert and type in new text the greater than symbol is going to indent the less than as the corollary will outdent v will visually select so it will actually highlight a portion of text and Y will yank so to give again couple practical examples here we've already done D W that will delete a word but now C W puts me into insert mode and I can say hello now again we've got that repeatability feature so if I come here and I hit dot I've now repeated that change which also includes adding the word hello and again the undo covers all of that so this is again this very expressive language that captures all of these different features similarly this doesn't work so well for a word so I'll use a different motion here but if I say indent greater than and then J to go down it will indent the current line and the line below the motion that I just described similarly if I yank a word here then I can paste that word so yank is to copy in vim so we have all of these different things that operate with those same nouns but our different operations so those are the core that's where we start from and now we can move on to the motions this is where things get very interesting kind of expand in possibility very quickly so we've already covered W for word B is the reverse of that you can go back to J I just demonstrated to go down so it's great about this is every motion everything that you use to move around in a document in BIM also acts as a way to operate on it to make a change so the same thing that would move me a certain distance I can now change over that I can yank Oh that I can operate on the same bodies of text that I can define with all those motions so once you know the one you automatically know the other this is great but it is a little bit limited what if you happen to be in the middle of some text that you want to operate on this is where things get very interesting we get text objects and text objects allow you to operate from anywhere within a defined body of text so for instance I W in sequence will define inner word which will operate anywhere within a word but on that whole word I T similarly is inner tag so for HTML XML cetera type tags I quote for inside the quotes I P for inner paragraph etc so here we can give a quick demonstration I'll go over here so that I'm inside of these single quotes and I'll start I'll demonstrate kind of a few successive things so di W it's going to delete the word that I'm on di quote inside the quotes di bracket inside the brackets di paren inside the parens and di P dip which is always fun to say inside the paragraph what's great is there's not a lot to remember there actually those come to me very easily when I'm looking at the text I see quotes and I know I want to operate inside those quotes so it's D I quote I almost don't remember anything about that that just happens that just falls out of my fingers which is amazing to me and so each of these again have that same wonderful repeatability so if I happen to be here inside of the word result I can say change inner word type out hello as what I want to change to and now I can be on an entirely different word but because then has an understanding of word what that means dot will repeat that change exactly what I want to do change this word that I'm currently on and to hello this gets even more interesting if I go over to a sample using some HTML so here we have some structured HTML and them again has an understanding it has a text object to describe this HTML I happen to be on AP tag here a paragraph tag and I can say change enter tag CIT and again I'll use that same repeat that I actually sorry I miss that there CIT hello and hit escape and now I can repeat that on any of the other tags that's an li tag not a P tag but again I said change inner tag not change the inner P tag so vim knows what I mean and tags are actually especially interesting because here you can see my cursor is on the closed tag my cursor is not even really inside the tag but vim still knows a tag is defined by this whole structure and inside the tag is still that text that's in there so even though I'm on the close tag or in this case I'll go over to the open tag I can still repeat that change and I can move up here if I'm on UL hello I can change that so then again gives me this very expressive language for defining and repeating these changes that is surprisingly well-suited to exactly how I think about these changes so these are text objects if you're not familiar with them I highly suggest looking into them I remember the day that I learned inner word and it was just this kind of mind expanding experiences like okay well I'm using vim for the rest of my life that's clear it was it was a good day it was a very good day so now we get to what I think are kind of the most interesting of being nouns that we can use these are parameterised text objects I don't know that they're actually called that I needed a word so I chose that word to describe them but what I mean by that is the text object alone is not complete it needs more you need to target something so f finds and it can find any character so I can F a and it will find the next occurrence of a T is similar but it goes up to but not including that character and similarly I can use search as a text object so I'll demonstrate that here if I want to change everything up to the L and list I can target that by saying C T Big L C T Big L and now I can type out hello so I'm able to target that uniquely there are other ones that would work there but that one is special in that it lets me target basically anything so here for instance there's a lot of stuff in the way words won't work inner words won't work but if I want to go out to the one I can say change F single quote so find all the way up to the single quote and now I'm right up next to the single quote and one and again this has the benefit that I can repeat all of these so as a great example of this I can use searching so I can use searching to define the text I want to operate on and then repeat that so for instance here I have the word other all the way out there in that second quoted string within the brackets within all sorts of other things so I really don't have another way to get there fo is unfortunately not going to get me there because there's a one in the way F single quote not going to get me there F comma gets me close but still not quite there but if I search I can find other luckily them recognizes that that's a useful way to get around so I can say change search search being the slash character type out other and you can see it's actually progressively highlighting for me so I don't even have to quickly get this I can progressively type this out see what it's finding so for instance if i just type o it's going to find that first one the minute I typed the T it knows to target out to other hit enter there and then hello and I'll close the quote again and now once again this has the benefit that this is repeatable so if I hit dot here it repeats that up to that same search pattern so thinking about this each of F T and then they both have a capital version big F goes backwards big T goes backwards search and question mark which is the reverse of search go in the other direction all of those work on any of the characters that are available or in the case of search literally anything you type in which is basically infinity so that's a lot so in preparation for this talk I decided to do a little bit of math and figure out just roughly what are we talking about here how many different things can I define so we've got five operators that's actually very can Servat if there's more operators than that some 10-ish motions I've shown a bunch of those already there's more than that similarly text objects enter paragraph enter word all of the fftt motions times 35 maybe 70 characters depending on how you count it all the uppercase and lowercase letters numbers punctuation and lastly let's call it a hundred for search which is totally not accurate because you can search for just about anything but just taking these we have 2000 ish distinct commands that then that I can express very cleanly to them and I don't have to memorize 30 things and let's be clear that memorization memorization is a strong word if I want to delete something I have to remember D that's very easy found a delete in her word iw it all I don't even consider it memorization at this point these things just come to my head I don't translate into them this just happens I've got 2000 commands at my disposal this is pretty incredible to me so this is actually pretty common theme a lot of people have talked about this idea it's a I've got links here to a number of blog post this is one called learning vim as a language by Ben McCormack that describes kind of his approach to learning and how he got that much more value out of them when you started to think about it as this language and this grammar for describing changes similarly the carbon 5 blog has a wonderful post on text objects the definitive guide which like mine is a very lofty title but they do a great job of covering most of the text objects that there are this is another post why Adam can't replace vim and it talks about the history of Emacs and them and what they each got right and the fact that editors like sublime and Adam have really followed in emacs's path on extensibility and configurability and kind of miss the boat on the whole composability thing those 2000 commands that I just described that them has not a lot of editors have copied that and mostly they just call themselves BIM clones because they want to stay close to the title similarly this is a great post from use vim comm called stop the configuration madness that's suggesting just a real focus on this core of them this language for defining changes and particularly it has this great quote you know what improves productivity mastering motions and operators and I would agree with that I've found the most value in this as something that I've kind of worked on within my usage of them lastly there is the classic canonical text which is a stack overflow answer called your problem with vim is you don't drop it V or VI and this talks about them is VI improved but that great stuff that core that language for editing text comes from VI and this post goes into surprising detail for a stack overflow post on what that means what this language is how do we build up commands and how do we use them most efficiently so if you've not read this one in particular I would highly suggest it but all of those posts are pretty great and will give you a little bit more information on you know this style of working with them which is kind of the core style of working with them so now my tips for mastering the vim language the first is the dot command the dot command is that thing that lets you repeat a change so I try as much as possible these days to think about my changes in light of the dot command would not be able to repeat the change that I'm trying to make if not I've probably done something wrong because vim has this very expressive language and if I cannot express my change in it it's probably me not them that is limited so an example of this is try to use text objects over motions so text object being inter word versus W word being emotion and as an example here if I happen to be on the beginning of the word results and I say change word hello if I come down to this second instance of the word results and I repeat it it's actually moving forward through the word it's a motion forward it's not defining a region of text whereas if I instead even if I'm at the beginning change inner word hello and then I'm here in the middle that repeats and it repeats on anything that then considers a word from anywhere in that thing that then considers a word so I almost never use motions unless I - for instance I I don't think I've ever used W as the way to define a change it's always change in a word mostly because of that light shining moment that happened in my history where I discovered it but also because those changes are more repeatable they're more expressive of actually what you're trying to do similarly ah let's say prefer text objects yeah that's definitely that repeat dot vim is a plugin that you can use that extends this idea out to more and more things so it allows other plugins to opt into repeatability and allows you to repeat a lot more things you wouldn't necessarily be able to otherwise this is by T Pope and there's a link here so you can use that if you're interested additionally relative number who here uses relative number all right that's most everybody for those that don't maybe this will convince you relative number is an absolutely amazing feature it's a relatively new feature like to issue years old which invents 40-year history depending on how you count that's new and it allows for line based editing in a very intuitive way so I'm going to slide a little bit further out of the way you can see the numbers over here on the side with relative number turned off we get the absolute line number so as I move around nothing changes and say I wanted to change from result down to complicated so I want to like kind of combine these two I don't really have a good way to do that let's see it's 15 minus 9 that's 6 ish I only know that because I had relative number on earlier so I can get that but I had to do math and again the whole point of vim is I don't want to thank certainly don't want to do math so relative number if I turn that back on will actually show me the exact number of lines so if I move back up to where I started there we can see 6 and again that's really the only reason I knew the answer to that question and now the question of how do I change from here down to complicated well my eyes follow down to complicated move out to the side see the number 6 and then it's change 6j change 6 down this is unbelievably useful I use this many many times a day I'm not actually sure how I got around in vim without it I'm also not sure how it took them so long to introduce this as a feature as an addition here you can see that I actually have the absolute line number this is a even more recent feature that was added so that you can have the best of both worlds essentially the current line is given the absolute line number and all relative lines off of that are given their relative value which is pretty amazing a little bit tricky for pairing but you know if you go to line five four three two you have to kind of chase your pair but I find that that comes up rarely enough and is easily worked around this is absolutely worth it so definitely check out relative number if you're not using it now and that just allows you to target lines in a much more meaningful way lastly visual mode is a smell I mean this in the programming sense of the term smell it's an indication that something might not be right so coming back to the language metaphor don't use two sentences where one will do with visual mode you type one change one operation one command which is visually select something then you make your change you can usually express that in just a single change operation a single command and in fact by doing two you actually break repeatability so if I'm here on this word and I'd say be iw I've now visually selected it doesn't really show up on a projector but the word result is highlighted say change type in hello if I come down to this word results and I hit dot that doesn't repeat it's not the same operation that didn't get that whole thing whereas again change in a word hello come down here dot that does repeat and it's actually very rare that vim does not have the expressiveness to target what you're looking at this is definitely true of lines if you're using capital V visual mode where you're selecting whole lines relative numbers got you covered absolutely if you're working within a line and you just don't have another way to express it then your visual mode can be a tool but again the word smell feels right to me here it's an indication that there might be a better way so be mindful of that look at when you're using visual mode and say wait could I do this a different way that's a great way to continually kind of up your game with text objects and the whole vim language so now we get into the fun stuff the vim language is amazing what comes out of the box if you're remoting into a server and you're running with bear bin is surprisingly expressive but it turns out that there are more things that we might want to do so these are a number of plugins I'm going to move pretty quickly through them but I'll give you a quick idea of what each of them do they all act as the verb and a BIM command but allow you to do something unique so we'll start with surround T Pope plugin as so many are and surround lets you delete change and add surrounding things so to demonstrate this if I have this quoted text here I can delete surrounding D s quote D s is delete surrounding that's the operation double quote is what I'm targeting that's my object if you will I can also change surrounding CS CS double quote single quote so change surrounding target the double quotes change them into single quotes I can even add surrounding so if I come up here to the word results Y s there's no good way to say add a surrounding y si W double quote surround the inner word with double quotes and again because of all of the magic of them and repeat them this is repeatable I can move somewhere else and I can repeat that operation of adding a surrounding character which is pretty magical this even works with tags so here I'm inside of a P tag say I wanted to change that to an H to change surrounding tag h2 there we go which again blew my mind T Pope you do some good work so that's surround dot them next we have commentary another T Pope original this one is for commenting out content so here we're in a ruby file comments and Ruby are denoted with a hash sign at the beginning of the line so I could type that in but that's not fun so CML comments over the given line L just means to the left but because a comment is a line when a line wise operation comment out this whole thing I can also go down so to say cm J that are it's down a line I can target the entire paragraphs cm IP so this gives me an operation to comment things it also works in Reverse so cm IP there will uncomment so I can toggle comments on and off again with that same expressive language that BIM gives us for everything else replaced with register if I were to copy the word so yanked inner word to get that word into my clipboard I now have the word results and I want to change the word calculate into results and I happen to be in the middle of it typically the way you would do this is VI W to visually select the word and then paste but that's boring and not repeatable and not expressive enough so there is a plugin called replace with register that uses gr go replace there's only so many keys so we have to get fancy with some of these gr iw will replace the inner word and that again is repeatable and the same way that anything else is this also can work with a given register so vim has lots of clipboards and you can say use this clipboard or that clipboard of that clipboard so again it expands that language even further next actually a few that I've built up because it's something again that I've been really getting into within vim so here I'm inside of a string say I want a two title case so capitalize the first letter of all the words I can say GTI single quote and I can now title case inside of that string I can do the same thing for a see the whole paragraph why not nope not total GT there we go leader GTI P that capitalizes the whole paragraph this is specially useful in prose I read a lot of markdown so title casing a line works out really well for me less useful on a Ruby paragraph but you get the idea next sort motion this is one for sorting contents is especially useful in something like a gem file if your company says we should keep everything in alphabetical order that's really tedious to do by hand them does have a sort operation that you can use on a visual selection but again I don't want to use a visual selection so here at Mathis two Gs go sort GS IP will work the inner paragraph so that actually you can see what it's doing there so it's taking them all and sorting them into alphabetical order very useful for things like gem files or other require statements or anything that you want to keep in alphabetical order and last system copy I like to keep my VIN and system clipboard separate some people connect them but I find that gets really noisy especially because I actually use a utility here which keeps track of my clipboard the last 50 entries and I make use of that pretty extensively so if everything I copied or deleted in vim went into that it would just destroy this history but now that means I have an operation CP in my case for copy and I can target anything so CP I single quotes will put can can strong parameters there into my clipboard or CPI P for copy inside this paragraph and now I have everything from there inside of my clipboard so again just giving me that same expressive language for operations that wouldn't have it otherwise again these are all plugins that are linked here and I'll have the show notes available show notes the talk notes that's what this is so similar to the verbs you can actually make custom nouns custom text objects these are a few that I actually happen to use and we'll see a few more in a minute but again just to give a quick summary of what these are the first is indent so if I jump down here into one of these groups I don't really have a good way to target these lines if I happen to be at the top it's very easy using relative number to target them but what if I'm in the middle I can certainly see a distinct body of text there but I can't describe it to them at least not before the indent text object so that is I I and I can use it with any of those changes that I talked about before so cm III will comment the inner indent and again this has the same wonderful repeatability well it's not the one interesting there but it did repeat it so I can repeat that across and similar to inner indent I can also have an indent which is basically any text at the same indentation delimited by a greater indentation so here if they happen to be separated by new lines I can still say cm AI and that will comment out all of them and again I can delete those I can change those I can indent I can D dent I can target them and do anything I want to them so that's pretty exciting entire this one comes up surprisingly often for me I just want to target the whole document I want to operate on the entire document so for instance cm AE comment an entire thing d AE delete an entire thing all of these I now have a way to describe I now have a language that's repeatable and undoable all of those wonderful things that we've talked about so far line another one that surprised me how useful I've found it so if I come down here to the word gem coffee rails again don't really have a good way to describe the text starting from the G all the way out to the end but it turns out that's often what we care about in a line we don't care about that beginning whitespace so what I can do here is I can change enter line CIL and now that puts me into change mode and I can repeat that not sure why I lost that but thing so there are some edge cases but I'm actually surprised I've never seen that before cool that's what happens when you give a talk but enter line and a line a line being including the text but not the new line at the end is actually extremely useful as well and a final one Ruby block so this is one that is syntax aware it understands the language that you're operating on so here we have a couple of different Ruby methods I'm able to target this first one very easily if I want to comment it out say cm IP because this happens to be a paragraph and vinz understanding of the world but if I come down here and I try and repeat that same change cm IP targets everything not separated by a distinct line that's not what I mean I mean a ruby block so drew neil has actually built up a plugin that allows me to target a ruby block cm a are a are being that new text object targets a ruby block which is pretty cool has the same repeatability same undo ability all of those great things so again that two thousand number that I told you about in the beginning which was a conservative estimate has now just blown I've put new things on each side I didn't do the calculation but it grew by a lot and most importantly it grew by the things that I care about them continues to speak my language I don't have to speak its language and so this extension of the vim language I find extremely powerful or empowering I guess is the right way to put it and extremely useful to me so I'm going to have all of the links to those excuse me to those in addition on the wiki for the custom text object there's kind of a bass plug-in that others build on top of there's a whole list of all of the other ones this was written by the wonderful kana who does amazing amazing than plug and work just kind of overwhelming but so there's all of these and you can check out their ones custom to specific language if you're a JavaScript developer you can get a function related one most anything you'd need is in here so that about wraps it up for me in conclusion my feeling is that having a composable language for operations and text objects it's one honking great idea let's do more of those so those are my feelings do we have any questions anything you guys want me to clarify that's a lot of talking for no questions really today right so the question just to repeat it for the audience at home surround them is an example of a plug-in that many many people use and seems common enough that it might be worth pushing that upstream into them proper so I cannot answer that directly whether or not that's something that they're looking at or how difficult that would be I know that there's a certain kind of boundary and that them is written in C and surround is written in vim script which are very different languages fundamentally it's certainly something that they could add but I think there's kind of an ideal around them that let's not change too much the thing has had 40 years to grow and a lot of people would say let's add nothing to it I know many people that actually run with no syntax highlighting with no plugins just cor vim and they probably would be opposed to that kind of change that said neo vim is an example of the community saying no no let's let's keep growing so again I can't answer for certain as to whether it's something they're looking at or how easy it would be but my guess is core of them for a little while is going to say that seems to be working fine and a plug-in will leave that to the external ecosystem and keep Corvin more focused that'd be my guess any other questions all right well thank you guys very much happy to talk about this after and thank you for coming out to the bend Meetup and you
Info
Channel: thoughtbot
Views: 451,324
Rating: 4.961741 out of 5
Keywords: thoughtbot, meetup, nyc, Vim (Software)
Id: wlR5gYd6um0
Channel Id: undefined
Length: 36min 19sec (2179 seconds)
Published: Fri May 29 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.