
so let's see i got onto the sheraton conference wi-fi and uh oh my password's not here the password was sheraton about with the capital s sheraton okay nevermind the password's not here you go so you log on you go to their website and they have a they ask for auth code there and the authority put under the web pages sheraton with the capital and then hit enter and then it redirects you to their advertising site i guess to make you buy stuff i don't know i get why people do that but i wasn't a little insulting at this point i already bought a room here come on
all right ranting um where to begin alright so uh microsoft finally ditched internet explorer right oh yeah they gave it they're giving all their products cool halo names now they got cortana and spartan and what else are they doing trying to i guess get as far away from the baltimore days as possible that'll be a healthy can uh healthy change form though actually it looks like we're already recording so oh so this is going to go on youtube wow all right
well thanks for showing up this morning guys i know it's bright and early welcome to day two of b-sides um if you haven't noticed downstairs we've got some vendors and they could use some love they've pretty much made this happen you know we got a pretty cool badge and a bunch of things for forty dollars and uh the only reason we're able to do that was because the vendor's downstairs so go pick up some free swag put your name on a list if you want more information from them and it would be appreciated
so uh this is eric fowler baylor eric faler this presentation is sponsored by workfront and it's uh from vim muggle to wizard in 10 easy steps eric is a long time linux power user um and vem exponent that's what's with the vm exponent someone that evangelizes vim into it oh you guys are in for a treat then he likes software that's elegant useful and avoids putting too many features too many features we're talking about them uh between the user and their goal he's currently pursuing a master's degree in computer science at usu and is the leader is the lead razz engineer at spelman technologies um i had the pleasure last night of talking a bit with eric um i think you
guys are in for a real treat here i think vam is one of those tools that uh we too off and don't think about and just use all the time so vi is it's more than just a text editor it's become a way of life for power users who can get more done than their peers who use traditional pointy clicky editors notepad plus plus sublime looking at you in this talk you will uncover an unseen world inhabited by wizards who effortly modify their code to use using powerful commands built upon surprisingly simple concepts it's eric's goal to invite you into this world and arm you with 10 of the most useful vi concepts giving you the biggest personal
productivity boost that can be had in 50 minutes he's going to discuss the most successful viclone of them all vim which is available on just about any platform you might encounter and has been actively developed for over 20 years he's going to also explore neovim a project that seeks to modernize and streamline the world's best editor let's give it up for eric thank you
make sure that doesn't break anybody's ear drums um yeah thanks for being here and coming to the only not computer security talk at the computer security conference i'm really pleased to have you here so uh when he said too many features between the user and their goal what i mean by that is features that don't help you get to your goal then definitely has a lot of features it's not lacking that department but the problem with a lot of other programs isn't that they don't have enough features it's just that they have too much that stops you from what you're trying to do all right hang on a minute and where was the there's the one all
right so then muggle the wizard 10 easy steps how many of you consider yourselves muggles all right so you'll be the guy in the left on the handsome red shirt but we're gonna turn into a wizard give you a little pointy wizard hat by the end of this thing and you're gonna be flying through your text this is a tool that you know we use all the time no matter what our specific job is and there's a lot of productivity gains to be had for anybody it's about me um like you said i'm studying a master's in computer science at utah state university my name is pronounced failure eric failor rhymes with epic failure so don't feel bad about hurting
my feelings saying it that way i have been using them virtually every day since 2003 and it dawned on me when i was putting this together that that was as long ago as 12 years ago and that's as long as i was in public school and it doesn't really seem like it was that long ago it doesn't feel like 12 years in fact i couldn't really think of anything that's distinctively 2003 about 2003 so i had to go to google to see what happened then and this wasn't a good year so with the title like vim muggle to wizard i'm kind of implying there's a dichotomy there's two kinds of users in the world you got people that i'm going to say are
from user culture that's who i'll call the muggles and programmer culture people these are wizards so what do you guys think is the distinction between these two cultures what makes a user a user what makes a programmer a wizard anybody don't make me call on you okay we've got experience efficiency i'd say a desire to efficiency
and a lot of yes especially with them a lot of people don't want to sit down and learn all the keyboard commands however if you do it's a lot more efficient but efficient all right so that's exactly it okay i dispute the user friendliness thing because i feel like editors that don't give you a chance to get better at the editor and really use it well or they're actually antagonistic towards easy user but at the early stage when you're first coming into it certainly a friendliness issue yeah all right so that's that's what i want to talk to you about that's what i'm hopefully going to convince you about is that the learning curve isn't a
bad thing it's a good thing so muggles in general the the way they approach their computer it's a specific tool for a specific task they have apps and this app does this that app does that and they kind of keep them in those containers they don't care how the app works just as long as they can get on tumblr or use hashtags or whatever they're doing these days and they want it to look pretty i i don't understand ipads i don't understand the appeal there other than they just looked neat they look like something that we grew up watching on saturday morning cartoons but i mean to use the thing uh it's just defends every sensibility i
have about you know user interface now wizards on the other hand we're the kind of people that we recognize that a computer is a computer it's a machine that can do literally anything it's limited only by our imagination and it does stuff on its own it's automated so we can set it to work tell it what to do then it's going to get the stuff done i don't have to babysit and keep mashing buttons to make it keep going it's not like i'm trying to push a ball uphill it'll do it on its own the way we use our computers is kind of part of our identity and our lifestyle and to get invested in a tool isn't like
a big thing for us because we can understand that that's going to pay off in the long run i've been using vim for over a decade and i feel like i'm able to do more stuff more easily than a lot of my peers but most importantly wizards we like our computers to do our bidding and to work for us and we just really get offended and insulted when the computer expects us to do stuff that the computer should be good at doing like counting and doing a tedious task in the loop over and over again this is what computers are for so let's make our computer do that so my goal is to help you recognize
workflows and patterns in your day-to-day that are kind of muggle-ish in the sense that you're doing dumb stuff that the computer could easily do more quick just as dumbly but more quickly think about how to make your workflows more wizard-like and to get you started on that you know vim's a really great tool to that end but i want to give you the 10 best features that give you the most bang for your buck there's a lot of features it's really hard to decide which 10 ones to go with for this but i think these ones will get you off and running so i mentioned there's a interactive component to this i want you to kind of follow along with me if you
have a laptop so go to this website um innovative.net i got a tarball there with a couple of text files in it look at this i'm getting people at the security conference to go to a url man i'm lead i should have although there'll be pdfs of the slides you can download that trust me it's just the slides guys all right so while you're downloading that and unzipping it and getting the files out wait before you do that is there anybody on a windows platform here are you guys on linux or mac okay well there's a good way to get like a bleeding edge version of them on windows but we'll not talk about that
instead in the meantime i want to talk about the history of vi why is vim the way it is today and how did we get there and all that good stuff and because we're in utah i feel a bit obligated to have a genealogy chart to describe this vim has a long heritage it descends from a line of line editors qed was one of the first ones back in the day and apart from having a really cool name it was ported to unix by guys like dennis ritchie and ken thompson like thompson hack ken thompson so you know this is basically alien technology when he writes it what qed did was when you type in regular expression it would
compile machine code representations of the non-deterministic finite automaton and then run that as a regular expression so that was that's pretty legit um they imported to linux or sorry to unix in the 70s dennis ritchie had a hand in that and then it went through a line of revisions and um kind of refinements even though ed is the standard unix editor it wasn't regarded as being particularly user friendly so some guys try to make it a little bit better over the years and um um bill joy was the guy that did a lot of that work he actually a steve jobs a feature from this editor called bravo that's vim's redo operator when you type
a period and it redoes the last thing you just did so glad you ripped that off but line editors your ui was a piece of paper they were a teletype terminal program for editing text on a typewriter effectively but instead of having a screen he had paper so had some design considerations that were optimized to that environment namely you don't just type text by default you start off in a command mode you have lots of marks and buffers and registers and things that help you keep track of your work because you're really looking at one line at a time but by the time bill joy got involved he um had this terminal the lyric ziggler
adm3a he had a screen so he could have a cursor that needed to be moved around the screen that's a pretty cool feature except you'll notice on this keyboard there's not arrow cluster anywhere this is why vi uses hjk and l to move the cursor around because that's just what his terminal had wasn't him trying to be uber efficient or anything that's just the limitations he had and as a side note like i know a lot of people myself included got into vi because the idea of not using the arrow keys to move the cursor seemed really leak and wizardly but if you think about kind of a dumb argument to make new users because
you're telling them it's really inefficient to move your right hand from here to here to move the arrow keys but then we expect people to move their left hand from here to here to mash escape all the time you'll notice here this little tab looking key right here is actually the escape key so for him hitting escape wasn't a big deal and a lot of vim users in the community will remap their caps lock key to be the escape key just so it's they can you know keep the claim of being ergonomic um a lot of the problems that vi and indeed the line editors were trying to solve are far far gone they're so obsolete now
but we're still talking about vi bill joy had a 300 baud modem from his terminal to the mainframe so his whole thing was trying to limit the bandwidth and the latency it couldn't keep up with his thoughts he wanted something he could give very few commands but get it to do a lot of work so he didn't have to wait for it or you know do dumb stuff over and over again because it's really slow for him but the reason vi has staying power and why we're still using vi based editors 40 years later is because he accidentally got the best ui not even trying to so let's talk about a good ui real quick
a good ui is it's not aerobics like what tom cruise is doing here in fact a lot of people would consider vi to be the epitome of a bad ui and they do everything wrong so there's no gui no mouse support and a lot of people feel like you need that in the text editor got all these weird cryptic commands that are hard to remember like unlike control c that's copy because you know copy starts with c control x of course is cut because cut starts i mean x looks like scissors and you cut with scissors and then naturally paste is ctrl v because the v looks like a down arrow and you're pasting stuff down control z's undo
okay so we all got we all got our own weird cryptic commands vi's just don't happen to be the ones that everybody else uses partly because it predates that standard by a good decade oh that's a dumb argument but it's not discoverable there's not like tool tips and little menus to hold your hand and help you along and that's one of those features i feel get in between you and your goal because once you know what you're doing you don't need tool tips to remind you how to do it right and finally it's a modal program oh this is bad bad stuff you guys shouldn't have modes because there are significant sources of errors confusion
restrictions and complexity now if anybody other than jeff raskin said that i would just i wouldn't even put it in my slides but this this guy's a genius he knows what he's talking about but i think he really hated the original vi didn't tell you what mode you were in it does now and all the other clones do so if you're still live i'd ask him what he thought of that but but despite all these things that vi did wrong lots of people probably more people today than at any point in history are using a vi based editor you know why is that and so let's talk about the learning curve the uis that ui experts are designing
they're geared towards new computer users a lot of this stuff was thought of in the 80s when computers weren't commonplace so to get people to use a computer in the first place was a big feat you had to convince them it was like a real world object they're familiar with like a desktop and you got emails that come to an inbox and you had to use all these stupid abstractions and metaphors for things that as wizards we know we're on a computer we know it's got registers and you know operations and op codes that doesn't scare us or intimidate us it just gets in the way and furthermore looking at this chart what's the difference between
a notepad user over here and a notepad user over here that's been using it for two years versus the guy that just started using it two weeks ago not an awful lot okay you don't just get really good at notepad you get a little bit good at notepad and that's as far as you can go vi on the other hand yeah sure there's a ramp up time but once you get to a certain point you can start adding on new features and these features work together and they they combine and they compose and it makes it all the more powerful all the time ui experts that are designing for this guy he's got this many brain cells knows
what he's doing that well and someone with this many hands i don't think you get to call it a humane interface when it's designed for someone that you know physiologically can't be a human being right because you're in insert mode all the time because presumably in the text editor all you're doing is typing new text does anybody just open up a blank file and type a new line of text and then close it and then the next time you type something no you're like refactoring and rearranging stuff and moving crap around that's why you're not in insert mode all the time because that's not your most common use case and as far as like ipads and touch screens
go like again i don't think these are designed with human physiology in mind because i can't see through my hand to tell what i'm supposed to be touching and i can't feel what i'm touching so my theory is that steve jobs was on one of his legendary acid trips and he's watching beetlejuice when he got the idea for the touch screen because he invented that same way al gore invented the internet right i'm pretty sure that's the marketing leads me to believe so vi on the other hand see what i did there it unleashes your inner cyborg you're going to be having all these commands right your fingertips going to move text around it's going to be awesome
so let's talk about why these old school moves that vim has are the best first one of these is regular expression so at this point if you've got the text file pop open demo.txt and vim and then go find the regular expression section with regular expressions you don't have to experience the file linearly i tried sublime for a little while because i saw my co-workers using it it's got that mini map on the right and that looked really really cool my problem was i was editing little tiny files like fcf stab that they all fit on the screen anyways and i didn't need a map where i was editing these several megabytes long tomcat logs that the map
i mean it all looks the same on the map and the map only shows me a few screen fulls so that didn't buy me a lot but at that time i realized i don't think of the file as like a linear sequence i use regular expressions to jump around where i need to go i mean we use computers to find stuff for us all the time that's what google does and your editor should be finding stuff for you so you don't have to scroll through and search for it you can count how many times stuff's in the file you can make lots of these little boring tedious error prone changes you just tell the computer what to do and then let it do
it so for instance let's talk about in here i got the word jabberwock in here a few times and i want to find out how many times i'm saying jabberwock in this file so i could just highlight it as a regular expression do a search so it highlights it and visualizes it for me and i can hit end the vim command to you know go through all of them and i can just wait till i bottom out and then i could be counting wait a minute i'm on a computer these are really good at counting i also have the computer do the counting right so i'm just going to run this little command here it's a substitute command
but the n flag at the end doesn't actually change it i'm just doing it for the side effect because at the bottom of the screen if you can see that it tells me there are eight matches on eight different lines i got the computer to count this for me stupid fast because you know again computers are really good at that stuff well let's say okay so i got a bit of a confession to make i am i'm into lewis carroll george lucas crossover fanfic i like um lewis carroll poems but i don't like all the nonsense words that he puts in there that just don't mean anything i want him to be grounded in some kind of reality perhaps in a galaxy
far far away where there are nonsense words or actual real things that i've seen on a screen before and there's canon behind it it means something and i'm very passionate about that so let's give jabberwocky the george lucas han shot first treatment i want to change all these borrow goals does anybody know what those are no well let's change the midi chlorians does anybody know those are well it doesn't matter but they sound cooler it's plausible right okay so i made four substitutions of four lines now jabberwocky's getting somewhere cause it's about midichlorians that's that's that's good guys all right um at the end of all these sections in the file i've got a help
command vim has got really really good documentation and you don't have to go out to the web to get it this is an important point because if you're using them to fix your your uh our you'll see your inet d file or your um hosts file or your dns lookup file your resolve.confess the one if you're fixing that and you can't go to the web to get help files are kind of hosed right so it's got all that stuff just installed by default so use it okay so regular expressions take away they do the stuff that computers are good at so you don't have to let's talk about marks not those marks marks are like bookmarks
these are things that keep track of where you are in the file it doesn't change your text file it's not like you put a comment in the file like i usually do that says bookmark it something that's internal to them and if if vi and vim can keep track of where you are in the file then you can use that to your advantage and then tell it to do stuff based on that what i'm in right here this is actually traditional vi this is the same source code that bill joy originally wrote it's since been open source and it's been ported to build on linux so for historical purposes it's kind of fun it's kind of
fun to go back and see how much of this new vim stuff still works even back in the day we'll set a mark i'll set a mark here marks have names uh one character names you've got 26 letters on the keyboard so there's 26 marks you can use by default type m and then the name of the mark so i'll set mark a right there and over here i'm going to put mark b to jump to a mark use the single quote command single quote a takes me back to the line where my a mark is single quote b puts me down here on the b line if i want to go back to the exact character cell that
i set the mark in that's the other single quote your back tick back tick b puts me back on that s which is where i set the mark okay well that's kind of useful you just got to remember what mark you're using but the real powerful thing is that you can tell them to do stuff based on those marks and vim has actually been setting marks for you and you probably didn't even know it useful marks the square bracket marks the opening square bracket marks the point where you first made a change or a yanked text for that matter than the other square bracket marks the end of that region so if you paste in a big
block of text and you need to do something to that block of text you pasted in you can tell them what you're talking about you start a command you say single quote that brace single quote this other brace and then tell it what command you want and it'll do it well i set the a mark and the b mark oh they don't have that in this that was embarrassing so i'll indent the stuff that i marked previously i don't have to be looking at it it could be scrolled way off the screen it could have been something i did 20 minutes ago as long as those marks are still valid vi can find them and it can operate on
that text so vi has been been setting those marks for you might as well start using them x commands these are the command line commands from the line editor heritage from way back in the day and this has probably featured a lot of new people don't like because oh my gosh it's typing heaven forbid i'm in a text editor and they expect me to be able to type right the great thing about these commands it's not because there's a whole bunch of them it's because you can apply them with sniper like precision to exactly the text you want to using any of the above mentioned methods okay you can give a command a range of lines
to operate on and you can either tell it line numbers you can use the marks that you've been setting you can use regular expressions you don't even have to have seen the text if you know there's a certain pattern in your file you can tell the editor to operate on it say from here until the next time you see this word do something so um last week so so i had a directory of all my lewis carroll george lucas crossover fanfic and i got a guest account on one of my computers and one of my guests logged in elevated the privileges and they deleted all my fanfic and it was totally devastating i don't know why someone
would do that first of all but this person was a bit of a noob they didn't cover the tracks very well i got their bash history file so i've got a timestamp i know when they committed the crime okay it was around this time they did it but i don't know which one of my users it was because they all log into the same guest account but if i got the last log i can see what ipad just logged in at that time i'll know who i need to slam the band hammer down on problem is these uh time stamps aren't exactly readable all right so what we're going to do here i'm going to run this command it's going
to go from the current line plus 2 so the first time stamp line down to from the current line plus 76 which is the end of this region i'm going to run this gnarly looking substitute command on it but what this does that's probably worse you can't see at the bottom what this is going to do it's going to find a digit followed by a hash sign and substitute it with the output of the strf time built in vim function so it's going to take the unix e-book time turn into something that i can read then i'm going to ban somebody okay so now these are all readable so go back to shell code and i can see the crime happened around
12 10 p.m on the 15th of march so now all i got to do is see who is logged in then i'm going to prosecute them oh yeah how dare they all right now one of the tricks i just did back there i'll show you this real quick because editing these command lines is fun but you're in vim you expect to do some vim stuff but on the command line at the bottom it's kind of more emaxi you use ctrl w to delete a word and that's okay that's that's good in a pinch but if you really want to do something awesome when you're in command line mode hit ctrl f and it's going to
pop up your complete command history the last 50 or 100 lines where the default is this is a vim buffer all the vim tricks you know and love you can use in here and then when you're done you hit enter and then it's going to execute that command for you so i'll save you a ton of time that's really good that's a really good one registers just like marks vim has been putting stuff into registers for you you guys know what registers are these are the in in other desktop environments it's the cut and paste clipboard because there's only one of them um in vi we've got lots of them dozens of them but the other awesome thing about
them is that you can tell vi to use the text in that register as though it was a vi command so it's a macro all right so this is the really great part registers are good um anytime you delete stuff it goes into a stack of registers there's a default register which is you know the one that you can just hit the p command to paste from that's the double quote anything anything you change like with the delete command or if you yank it's going to go into the default register whose name is double quote but then if you yank stuff there's the zero register which is the default yank register so now your text
is in two places when you delete stuff it goes into the double quote register and also goes into register number one then it shifts register one and register two and so on so right your fingertips you're keeping the last ten things you've deleted that's that comes in really handy if you accidentally delete too much you want to get it back well you sure can so like marks you use a quote mark to introduce that you're referring to a register so it's the double quote when you're talking about registers but the cool thing is that these are macros so let's say i want to do something that's a little bit tricky to do as a regular expression what i typed
out right here are the vi commands that i would do to do this particular operation that's not important though because if you hit the q command and you type the name of a register it'll say recording in the corner how many of you guys have done that accidentally and didn't know what you're doing type q again to turn that off so q the name of a register like say register a and then you do some stuff like go down three lines and hit q if i type at sign a it's going to execute it's going to take the text in register a and then do it as a vi command so you can show them what you want to do and then tell
it to do it again and again so in this case i've got this text here this corresponds to a command i want to do i've got an escape character right here so it gets out of insert mode and i type a j so it goes down to the next line so i don't even have to do that again manually so let's just load this up into register a what i want to do is writing a mail merge for some of my friends and i had you know personalized greetings at the beginning of my mail messages but they're a little bit too honest and i thought maybe some of them would be offended by that so i thought i should
just change it to something generic and bland and unoffensive probably could have done this with a regular expression but you know it's a little bit tricky so i'll just do the macro thing so if i say at sign a it's going to change the offending word into my good so now it says hello there my good fellow well i just typed at sign a three times all right what do i look like a noob it'd be nice if vim can just remember the last macro i executed so i didn't have to tell it every time right and it can so that's at sign at sign i type at sign at sign it remembers the last macro i did
but now i'm typing you know two key strokes for every one thing i want to do when i go to the grocery store and i buy stuff at the checkout register the lady you know takes my hungry man meals and she doesn't scan them all individually she scans the first one types in how many there are and then puts them in the bag well can't my editor do that too well it sure can i'll just tell it i got six more lines here i want to go six at at and it's going to do it because remember the last command the last part of that macro was the j key to go down to the
next line so it just automatically puts the cursor right where it needs to be and then it does it that many times okay start thinking like that and you're going to get your job done a lot easier now what if you don't know there's six more lines right well you can just tell it some crazy big number and then when it gets to the end of the file or if your command errors out because you know the command can't work like you got a regular expression in there it'll just bail out so you don't even have to know how many you got in there you just tell it to do it a bunch of times and then when it gets
done it gets done okay so the point here is that data is code so let's talk about language language is important because i mean everything we do to the computer you can think of in terms of the language and how we get our point across to the computer what we want to do there's a lot of these new editors coming out you got sublime you got adam and they look really really cool but they really just miss the point and they're never going to replace vi because your interaction with the computer is the important part not how it looks and they're all still you know using the mouse and you've got to point and highlight and click and i mean let's be
honest how how good does that really work there's ui guidelines for how big ui elements like buttons are supposed to be because if they're too small people have a hard time clicking them now you want people to put their cursor onto a character and their text file and if they're any you know if their eyesight's any good at all they're going to be using a tiny font so they can see a lot i mean come on guys the reason that vi is never going away the reason it's been around for 40 years is because it's a language it's a simple language and if you understand these basic concepts all these weird cryptic commands all of a
sudden make sense you've got three things in this language you've got a count you've got an operator and you've got a motion that's that's really all there is to it the count parts optional a lot of people leave it off because you're just doing one thing at a time but if you're ever doing more than one thing at a time don't do that thing multiple times tell vi how many times to do it and let vi do it operator these are some of the commands that you're very familiar with out of normal mode anytime you type a command but you need to type some other key to make it finish those are operators not just commands
like the d command d d takes two characters to delete a line that's because d carat will delete from the cursor to the beginning of the line or d j will delete from here down a line see where i'm going with this the really clever bit is the motion you've got lots of ways in vi to position the cursor where you want to be because it's aware that text has things like words and lines and sentences and paragraphs if we've got names and concepts and words for these things shouldn't the editor have a notion of what these things are and this is the part of vi that really makes it brilliant because you can have these basic things you need
to do to text and you have basic ways to describe how much text you want to refer to and then you put the two together there's your cryptic command wow i hope i didn't confuse anybody there because that's just so hard anything that you're using to move the cursor pretty much counts as emotion so marks that we talked about that's emotion regular expressions act as a motion in this context are a beloved hjk and l keys this is the part that makes them awesome because they're not just moving the cursor it tells vi where you want to go and what what you want to do when you get there now here's another quote from a man jeff
raskin computer should not waste your time or require you to do more work than is strictly necessary is your editor wasting your time is it making you do more work than necessary if you're not using vi it probably is just saying so remember com count operator motion and now you're a vim wizard so um vin's been around for a little while vi has been around for a long time uh where are we going in the future what's going to happen next so under the auspices of brown molinar the bdfl of vim it's been been a very strong and stable project they're putting patches out every week but over the years the code's gotten a bit crafty and braum's
become a bit reluctant to change things he's gotten burned by different patch sets people really really need this feature in vi or in them and he'll put it in and then when the bug reports start rolling in they're long gone they're not maintaining it so he's got all this other stuff that he gets to maintain on top of and already being a big project so he's kind of gotten a little bit reluctant to make big sweeping changes over the years and that's really kind of got some people in the community fed up and tired so last year a guy named thiago de ahuda made a bounty source project he wanted to fork them and do some really radical
and drastic things to it when he started out i really didn't think it was going to go anywhere but i'm willing to eat my hat because in the last month or two they've really come a long ways and have gotten it going pretty good so it's called neovim they've done a lot of neat things they're cleaning up the code they're using some more modern libraries to abstract certain things out make it you know more cross-platform downside is their cross-platform libraries aren't on all the platforms so some of the platforms i use vim on neovim's not ever going to be supported on so i'm a bit miffed about that but there are some cool things like in the
tty layer you can distinguish control i from tab so you could use control i in a mapping in the console that'll work in g vim but if you do it in the console the console just sees it as a tab character so they're doing some cool stuff it's definitely worth checking out if you're not afraid of building your own software on this bit alpha e right now just be aware of that but it's it's pretty neat it's going somewhere all right so let's talk about some external tools some external programs how many of you know a unix system you're comfortable there all right so vi or sorry vim it's a component among other components it's designed to work well with stuff
that's already on your computer instead of being a kitchen sink ide and i'll be all kind of big bloaty program got all these great programs on your computer so vim should work with them that's the vi way work in harmony we can pull in text from another file with the read command but as you know on unix we consider just about anything a file it's really easy to pull in the contents of a command so i can read in for example this ls command i want to see how many types of syntax vim can highlight out of the box so i'll just run this command and 582 more lines in my file so there's at least 582 types of syntax that them
just out of the box vanilla will highlight which i think is always really cute when i go to the editor and go to their syntax menu and there's like a couple dozen entries for some reason i'm writing a script and for some reason if i needed bsides.org ip address in my script i could just not go to another x term and run ns lookup and cut and paste it back in i'll just do it in here because i'm already in vim it's already on unix we're really blurring the line between text and files on a computer and text just that can come from anywhere now say i want to go the other way but if i got some text in my
text file or whatever i'm editing right now i want to push it out to another program process it and then bring it back in well that's what the bang command does i can do stuff like run some text through figlet whoops not like that though i gotta tell it what text fig let okay or cal say this comes in handy sometimes one thing i started doing um people are asking me how do you do stuff in vim what do i need to put my vim rc i was just about to grab the mouse and highlight the snippet and then paste it in the chat window then i thought that's what a muggle would do i'm better than
this so i can highlight some text run it through paste bin it oops kind of use the bang so i just taught you guys all right anybody want to go to that website and tell me if that's really what what's there i'll screw it i'll just do it
oh that was embarrassing hey oh you don't believe me you thought i just hit undo right
so um what i just did there um i made a mapping because i like to type out a command like i'm going to type it on the shell i do that very often so i just made this mapping that'll um take the text put my shell in front of it and then the text so basically it's like passing this command to my shell then runs that and puts the output back into my editor so that's this guy right down here no remap capital q bang bang sh and the bang bang says take the current line as a normal mode command basically take the current line and run it through this command it's my shell so whatever i type on there like a
command it'll do put that in your vmrc that'll be awesome who knows what the capital q command in vim does that's what i thought trust me you won't miss it i need a list of all the users on my system bam capital q i know how much battery life do i have what's the prime factorization of two of my favoritest numbers right say my icloud account got hacked again i need to set up a new password done okay now if i need to do something like a hexadecimal times table right i know how to do that with unix commands i could write like a one-off python or perl script to do that but i know i can
just use seek to print out the sequence of numbers then printf to format them as you know hexadecimal but you know what i really wanted was a table so if i pass it through format and i just think there's you know going to be 16 things on the line two characters per digit plus a space so that's three characters so i've got 48 characters there's new line at the end well simple math bam i got my times table just like that okay we're turning our text buffer into a text stream and we have any other program on our computer that can take text can manipulate it plug it back into what we're doing don't need other
terminals you don't need to cut and paste anything all right it's the way to be guys wow what did i do
let's guess i think i was on slide 40. that's pretty good guess
all right this is where we want to be we're going to do the splits it's not uncomfortable it's not awkward guys promise splitting windows this is one of the greatest features of them it's very flexible a lot of other editors visual studio they let you split it like down the middle or maybe down the middle this way or some of them like do a grid and that's very very confining it was like a tiling window manager you can open the same file in five different places at once or you can open five different files in you know five little views at once vim doesn't care it puts it up there the way you do that is the control w
command puts it kind of in the sub mode where the next character refers to some window operation now a lot of the commands that you're already familiar with like moving the cursor up down left and right well naturally if you want to go to the window above you'd use ctrl w k to go up and it's like a tiling window manager at this point it's super useful so i got two windows here i can do control w down to go here ctrl w v to make a new vertical split ctrl w s to split yet again i can say split i don't know proc partitions and take a look at that file control wc will close whatever window my cursor is
in control w o will make my current window the only window it's really really great especially if you've got a nice big monitor and you've got a nice small font you can see everything you need to see all at once so naturally you're going to ask well hey if i can see two files at the same time can i compare them better question can my editor compare them for me the answer is of course silly so here's the final draft of my um improvement to jabberwocky it's going to be a re-release in stunning 3d courtesy george lucas and i've gone through and changed all the silly louis carroll nonce words for silly george lucas not
swords and then the jabberwock you see here i replace that with jar jar binks because if there's anybody that needs to be decapitated it's that guy all the lines that i've changed from magenta um the words are red if you're on g even you can get better color schemes or on a 256 color terminal you can get better color schemes than this this is just vanilla out of the box but you know if i needed to put changes from this buffer to the other one you got commands to do that i can do dp to push the difference over to the other side or if i want to do the other sense i can say d o to pull the other side over here
you know it's really great check the demo.txt file it'll tell you a few more of those commands it's a really good way to manage your merges visualization visual mode it's interesting because vi itself was a visual mode of x the line editor and then we've got yet another visual mode which is how we highlight text it's a really convenient and flexible way to select blocks of text that don't quite fit into the normal um like operator motion like that kind of emotion it's and it's also kind of nice sometimes just to see what you're doing it's also the only way to select a block a text like a rectangle of text a lot of these new trendy editors have
multiple cursors now that's the new must-have feature and they're a little bit muggly in their implementation so i don't favor it a whole lot but also all the stuff that they do with multiple cursors we've been able to do in vim at least since vim version three with visual block mode or the plain old substitute command so let me show you some of the stuff that they like to do come over here and i want to rename all of these array references from elements to something else well i can do that in fewer keystrokes or another thing that you can do with multiple cursors is i want to add another different expression into this array d reference operation well ctrl v
go down a few lines i can add i to it that covers a lot of the use cases that i'll show you on the cool videos i mean i gotta admit multiple cursors is kind of fun it does feel cool to see i type one character but like it doesn't enter into the text that looks really cool it makes you feel pretty awesome but when you use it for a little while you kind of realize in making it look pretty it's just really not it's really not actually that useful you know a lot of the use cases are less useful than a regular expression search because you got to hit control d a whole bunch of times or like
alt f3 or something and it's like really slow to the implementation if you get a big log file like the ones i hack on it's just painful but anyways visual block mode you guys learn about that one that will change your life that's a really good one if you're in visual block mode you select some text you got a beginning point and an ending point if you use capital i to move the cursor usually it's going to take you to the beginning of the line in visual block mode it takes you to the beginning of the block so you can prepend text to your selection and then analogously capital a takes it to the end of the selection
much like in regular mode capital a takes you to the end of the line i just point that out because little i and little a don't quite work in visual mode like you would expect so they got to be capitalized but super awesome super awesome stuff who knows what the three virtues of a good programmer are it's a larry wall quote anybody name those anybody heard of those laziness is one of them that's uh right there good you can read you got laziness hubris and impatience as a programmer those are good virtues to have because they lead you to think about having the computer do all that boring stuff so you don't have to do manual labor that's that's why we're
all in it cause we don't like working outside right am i right okay insert mode completion if you're in a file you hit control n and it's going to you know complete your keyword this is kind of standard fair in editors these days control x control f you're in insert mode you're typing the name of a file how many times have you written a program that uses a file you spelled the name of the file wrong so your program doesn't work okay control x control f it'll auto complete file system paths so you don't have to have those typos ever again there's a lot of ways you can complete stuff if you're like me and you're a bad
speller i'm in insert mode and i spilled this wrong control x s will do spelling completion okay you got a little window here you can see all the stuff control x control v those vim keywords so like i talked about before you're in command line mode here i'm starting to type oh what command was that buff something oh control x control v and it's going to give me possibilities okay so basically the main thing you want to remember if you're typing stuff control n is your friend it's going to auto populate a list of words that are already in any of the files you have open on the theory that most likely that's the kind of stuff you want to
type so how do we learn to be good at something is it this easy you just jack into the matrix and take the red pill and you know everything also it's a little bit of work but you got to keep in mind what man tom haverford says sometimes you got to work a little in order to ball a lot learning vims step-by-step process i recommend doing it one bit at a time but as we're getting started i recommend the cold turkey method just dive into it tell a lot of people you're gonna do it so you can't just wuss out and you know shamefully go back to whatever you're doing before with the 10 tips i'm teaching today
hopefully the learning curve is not going to be so intimidating you're going to get up to speed really fast but i say stick with it for a month at the end of that month if you do go back to your other editor hopefully you're going to be hitting escape too much and typing w colon wq and all your files because the point here is you're making it into muscle memory once you've learned it you don't need to relearn it's just like riding a bike you don't have to think about it anymore and that's the part of the learning curve that well it's not a learning curve i like to call it the experience curve because once you've got that experience
you're not thinking about it anymore then it's not a problem it's automatic it's a reflex thing i noticed with a lot of people that are good at them they'll get to this point on the chart and they'll stop it's usually the point where they learn the redo operator they can hit dot and tell them to redo the same thing they just did but you know somewhere else and they think oh my goodness i'm so much better than i'll ever be with notepad and they quit learning don't do that there's a lot of features in vim you've got to keep trying them out and you'll you'll learn lots of new things you'll always progress but it builds on the
stuff you already know so it's not even a difficult thing it's not even hard all right so the last feature the one thing i want you to remember from this if you don't remember anything else remember this thing and you're just going to be so awesome and you'll be doing stuff so much faster let's just talk about it text objects who's heard of text objects okay perfect i'm going to show you something new in the in the com scheme of things these kind of fit into the motion category but they're not motions they don't move the cursor but it goes back to the idea that we've got names for certain structures in our text we've got quoted strings
we've got brackets we've got blocks of code we've got tags if we've got names for these things and we can kind of give it an idea we should have our editor comprehend text the same way that we do right so we can be speaking the same language that's what text objects do so right here i got a bit of javascript i pulled off the b sides web page i've got lots of things in here i've got a parenthesis i've got some literal strings i've got some blocks of text i got tags wouldn't it be nice if i could tell them to like delete everything or highlight everything inside this block or you know i got this function call i
want to change what's happening in here what if i could just it doesn't matter if i put my cursor at the beginning of the argument or at the end of the argument or on the opening paren as long as i'm in the parent somewhere i can just tell them do something with these parens and i can with the text object so the way it works you give it a operator that's going to be one of yank delete change visual mode then another letter i for inside meaning inside whatever thing i'm going to tell you next or a for uh like a entire thingamajig and just another character to tell it what thingamajig is if it's a
parenthesis well type a parentheses if it's a quote mark just type one of the quote marks square braces and this like index d reference here v a square brace i'm going to highlight everything inside the square braces and the square brace in three characters i've told it to highlight well here are three characters that's a bad example how about this block of code va curly brace now i can just refactor this whole function or i don't like xml i i'm more of like a json guy or whatever so for me i would just assume delete it all so d a t for tag delete a tag my life just got simpler no more xml so if you guys don't remember anything
else remember delete all the xmls and then you will be a text editing cyborg and when you get the hang of text objects i mean it really feels like you're in a ghost in the shell and you're just hacking away because oh man it's a great feeling you didn't even touch the mouse to do all that so here at the end of things we're at the end of our wizarding journey i hope you've realized that vi isn't hard it just seems hard but it's really pretty simple with these 10 features you've got enough idea of how to edit your text you can do it super efficient super fast the great thing about a lot of these features they
kind of build on each other they complement each other it creates a whole entire system that it's not just a text editor it's like a rebel an repl you know like you got in python or ruby or lisp where you're just interactively editing stuff i mean that's what vi is for text pick up new features make it a point every week to just find some new feature read a blog or read the help file and just put it into your workflow go out of your way to do it if you do it the muggley way hit undo and go back and do the new wizarding way after a week it's either going to be muscle memory and you're not thinking
about it anymore in which case you're saving time or it doesn't fit your flow and then just move on to something else i mean heaven knows there's plenty of features in vi you're not going to run out anytime soon but before we part now that you've gotten your wizard hat and i guess a crystal ball for some reason you're well on your way to becoming a text editing wizard but i want to leave you with one final piece of advice yeah i know you're waiting for that all right you can find me online i'm i got an email address i'm on frino to hang out in like the vim channel the neovim channel dc801 my slides are on my website so you can
go fetch those later thank you for listening
you