Ancient City Ruby 2013

Impressive Ruby Productivity with Vim and Tmux

Impress your friends, scare your enemies, and boost your productivity by 800% with this live demonstration of Vim and Tmux. You will learn how to build custom IDEs for each of your projects, navigate quickly between files, write and run tests, view and compare git history, create pull requests, publish gists, format and refactor your code with macros, remote pair program, and more, all without leaving the terminal. Come prepared to learn and ask questions; this is serious business.

Ancient City Ruby 2013

00:00:00.160 my name is Chris and I'm going to be talking about text editor and uh t-o
00:00:05.240 which is a terminal multiplexer so before I do that let me introduce myself and I'm going to keep going back to my keyboard U because my remote's not
00:00:11.759 working uh so I have recently moved uh in the last three years I've lived in three different cities I moved from
00:00:17.199 Seattle to San Francisco and then last month I moved this is the financial district I'm pretty sure those guys are
00:00:22.640 on their way to go buy a startup I moved to Portland Oregon last month that's my fiance and that's my dog Baxter and and
00:00:30.480 I now work for a distributed team which means I work with a lot of people that are nowhere near me so I have two developers I work with in San Diego and
00:00:37.360 I also work with a couple other people in Portland um which is good and bad it's good because I can go days without
00:00:42.640 actually leaving the house um it's uh I guess it's probably a bad thing um but it's good uh because I get to work with
00:00:48.399 lots of different types of people so um that's me in addition to writing code I'm also uh really really really really
00:00:54.760 into photography so if you have uh if you get tired of talking about code want to talk about photos uh or anything else
00:01:01.519 please do okay so let's start talking about some uh some t-o and Vim uh before
00:01:06.600 we do that I want to talk about some of the tools that you might already be using today if you're not using VI and tmu and the first is Ruby mine so who
00:01:13.439 uses Ruby mine on a pretty regular basis like five three people okay so
00:01:21.000 that's cool I mean I've actually worked with uh teams that have used nothing but Ruby mine um and a ruby mine is
00:01:26.200 relatively new uh it came out in 2009 and it's about 9 9 bucks if you wanted a
00:01:31.560 license to use it this is how it looks um this honestly gives me a headache if
00:01:36.799 I have to use this all day because there's just a lot of stuff going on on the left hand side is Ruby mine we have
00:01:42.360 a file tree we have tabs buttons widgets wisos on the right hand side we have a rails server and our rails console
00:01:48.719 things that we kind of need to have open if you're working on a rails app the thing I hate the most though about this is I had this teeny tiny little area
00:01:55.840 that I get to work in all day this little box where I do my coating um not not a lot of fun um who uses Sublime
00:02:02.560 Text this is another editor so way more people this is really popular Sublime Text has actually been around longer
00:02:09.000 than Ruby mine but nobody I know started using it until last year when Sublime Tex 2 was released um in
00:02:16.120 2012 uh Sublime Text is 70 bucks so it's cheaper uh it's also a lot simpler but
00:02:22.959 still very powerful this is how Sublime Text looks exact same window I still have my terminals open but now I have
00:02:29.200 Sublime Text a much bigger typing area and we can actually have a a dark well I
00:02:34.560 believe we can probably do a dark color scheme on Ruby mine but here we have a whole dark interface so in my eyes it's
00:02:40.000 a good thing we still have the giant Mac OS menu bar on the top which I find distracting we are able to still run our
00:02:46.879 tests within Sublime Tech so that's cool we get some of the ID goodness that we might get from Ruby mine but still uh
00:02:52.920 I'm not a fan of this is is not ideal I still find it very distracting so now we move to the magical V and t- monks uh
00:03:00.319 who who uses vim and tmok already okay so I could basically just
00:03:05.840 be done now because and so most people are using this hopefully you find some good stuff
00:03:11.680 uh but more so hopefully you see something I did totally wrong or you know a better way of doing this and you can show me that'd be good that'd be
00:03:16.799 good too so vim and t-mo I've already said kind of what they are Vim is a text editor t-mo is a terminal multiplexer
00:03:23.120 meaning that it just is like a windwing system for your terminals you could stick a bunch of different apps in and and manage those and move them around in
00:03:28.560 panes and windows and um keep everything in the same place Vim will run in the terminal so it too can
00:03:34.360 be managed by t-u so let's look at Vim in t-u ah this is way better uh this is a
00:03:41.920 full screen screenshot we don't have the Mac OS menu bar because everything is running in the terminal we're able to
00:03:46.959 just run it full screen and focus on one thing at a time so on the bottom there we're going to be looking at the bottom
00:03:52.040 of the screen a lot so I apologize if if you can't see this um at the bottom there is my is my status bar we can
00:03:57.920 still quickly open up files just like we can in our other two editors we can
00:04:03.079 still run our tests from within the editor so we still have a lot of the benefits we still have our console running that we can type
00:04:09.680 into and we still have our rail server running so we have all the same cool stuff um but it's not in ourf face all
00:04:15.680 the time so this is this is definitely um how I like to work this is great everything's got the same font same
00:04:22.160 color schemes really cool okay so let's move along t-m so I've already told you
00:04:28.800 what it is let's see how to use it the first thing you're going to want to do is get it installed uh I already have it
00:04:34.720 installed so I got an error but uh you probably don't have it installed so you can do this unless you're already using it the next thing we want to do with
00:04:41.360 t-mo is create a new session the way t-mo works it's a server running on your machine and you can create sessions on
00:04:47.639 it and then your terminal acts as a client to those sessions so even if you close your terminal your session will still be there so this is really helpful
00:04:53.919 if you uh say connect to your development box or whatever and you open up a session and do all this cool stuff
00:04:59.680 you can close your terminal and come back later and resume that session so we're going to create a new session called ancient city and now we're in t-m
00:05:06.560 land so it looks exactly the same as the terminal we were just looking at except we have a status bar on the bottom and
00:05:12.960 in my status bar on the left I have my session name and then I have the list of all my windows and then on the right
00:05:19.319 hand side I have the host name of the machine I'm connected to uh when you have multiple sessions this is sometimes
00:05:24.440 important and then on the right hand side again I have the the date and the time this status bar is totally
00:05:29.720 configurable anything that has output you can stick in your status bar I've seen other things like um CI so a little
00:05:36.199 green heart if your build is good and then it kind of goes back and forth yes uh I've also seen weather scores or uh
00:05:44.000 weather reports uh sports scores uh email accounts DMS on Twitter that kind of
00:05:49.919 stuff uh if you want to get started with t-u you're not really sure uh where to get started here's a link to my t-o
00:05:56.600 configuration and I'll show this later so you don't have to write it down right now but this will have that status bar in there and um give you kind of a
00:06:03.240 starting point there's a ton of comments too so that should be helpful also in there is going to be my keyboard
00:06:08.319 shortcuts so that's why I'm not going to like put keyboard shortcuts on the screen because you can change them to whatever you want so it's kind of
00:06:13.840 pointless for me to share them okay so getting organized so now we
00:06:19.599 know what t-o is let's see how to use it to organize some windows so we are in our teamu session and it is almost lunch
00:06:27.599 so it's time to start working uh first thing we're going to want to do is type IRB so now we can start writing some
00:06:34.280 code right if you're like me you have a lot of um stuff that you work on that does uh that takes time and youd prefer
00:06:40.560 for that stuff to run in the background so we're going to prepare for that and create a new window uh oh I forgot to
00:06:46.199 explain this sorry um so notice we started IRB the window name has changed to Ruby t-mo will automatically find the
00:06:53.280 process name and stick that down to name your window if you wanted to you can name that to something uh more relevant
00:06:58.960 so we can name this this tab to IRB okay so now we're going to create a new window we can do this with a keyboard
00:07:04.759 shortcut and in this window we're going to have some games ready to go just in case just in case uh we're doing
00:07:10.319 something in IRB that takes a while so we're going to rename our our window to games and then we're going to play some
00:07:15.400 games I installed uh yesterday a really awesome gaming Library it's called emex
00:07:20.800 so I'm going to start up a text Adventure if you
00:07:28.360 haven't played this you should cuz it only takes about 3 hours to beat um but t-mo also allows us to create multiple
00:07:34.479 panes inside of our window so we have a second pane over here where we can start a second game so we'll fire up emac
00:07:40.080 again uh and now we can start a game of Tetris yes very fun okay uh okay so now
00:07:47.720 we want to write code so we still have our window running we can go right back over to that window and start writing
00:07:52.759 out our Ruby in this case we're just uh doing something really interesting and adding up the first 100 Million numbers
00:07:59.560 so this is going to take a while so while this is running we can go back to our game still running in the background
00:08:04.960 playing Tetris and boom okay did you see the flash you guys see the bottom part flash um when te when there's a change
00:08:11.919 in the window uh in any other window t-o is going to flash the status bar and then it's going to change the background
00:08:17.479 of the window that has an update for you so notice it's a white background now on IRB if we go to that window we can see
00:08:24.039 the the results been calculated so this is really cool we can use tmok to organize all the stuff we're working on
00:08:29.960 and ignore that it's there and then when there's actually an update that we need to pay attention to t-m will tell us so
00:08:35.159 if you're connected to another machine via SSH and you get disconnected or if you're uh tailing a log repping a log
00:08:41.680 for errors or something like that and um you want to know when an error pops up you can just kind of forget it's there and um pay attention to your to your
00:08:47.480 status bar you don't need to keep checking it I'm going to grab a drink real
00:08:54.920 quick okay so scripting this is really this is one of the really cool Parts about t-u that nobody ever uses um all
00:09:02.760 of the stuff that we just looked at that we can do with t-mo we can do that um via scripts we can ask t-u to do that on
00:09:09.480 the command line we don't need to use keyboard shortcuts so we are now in a rails app and we want to start a rails
00:09:15.399 server in a new window we can use the t-mo new window command to do that so we're going to create a new window
00:09:20.959 called server and start the rail server t-o will create that window for us and then start the server um that's cool so
00:09:28.680 now we can do another one we'll go back to our first window and create a new window for our
00:09:39.519 console cool so in uh in practice I would never do that because I can just
00:09:44.839 use keyboard shortcuts but you can take those same commands and stick them in a script so that this kind of stuff can be
00:09:51.760 automated later so here's an example of a script that you might use this is a simple one but um it it shows the
00:09:57.320 example well this is for like a rails app we can create a new session and then we can create three windows for that
00:10:03.200 session one for the server one for the console and one for vim and then finally we can attach ourselves to that session
00:10:09.920 so we'll run the script real quick to see how that works first we have detached from our team session we are just in the ancient city one notice our
00:10:16.040 status bar is no longer there and now we're going to run our script so we go into our project
00:10:21.680 directory run the t-x
00:10:27.040 and boom that's awesome so notice our uh
00:10:32.440 name is down there just as we've asked it to be we have four Windows already ready to go the first one has got the
00:10:38.839 terminal the second one's got the rails server running our rails console's running in the third and then finally Vim is ready and it's in our project
00:10:45.079 directory so we can just start start writing code this is really cool this is helpful if you have um uh complicated
00:10:51.880 test Suites or other services you depend on you can get all those things fired up maybe um SSH to a couple machines
00:10:58.120 whatever um this is easy way to set up different development environments for your apps those are most of the features I
00:11:05.480 use of t-u on a daily basis if you want to learn more about t-u this is a really good book on pragmatic bookshelf It Is
00:11:12.320 by Brian Hogan first time I've read who it's by okay moving on now we know how
00:11:18.760 to use t-s let's learn how to use Vim so we're going to go over some of the stuff that you probably used to doing in your
00:11:24.040 other editors and then some other stuff that your other editors probably can't do or maybe can do I'm not sure so a
00:11:30.839 quick intro most everybody in here has probably used Vim but we're still going to do an intro just in case somebody
00:11:35.959 hasn't we don't want to have them be completely lost so we are inside t-mo now uh and we want to start Vim you can
00:11:41.920 do that by using the vi command you might actually have to use Vim depending on your installation but VI is going to
00:11:47.040 work for us on Mac OS now we're in Vim so the basic things that you want your text header to be able to do is open a
00:11:53.320 file add text or change text in the file and then write those changes so we're going to look at those three things
00:11:58.920 really quickly um uh Vim operates on modes so by default we've started and
00:12:05.760 Vim is in what's called normal mode so this is really confusing to people who first start using Vim because you can't
00:12:11.000 actually type people will start typing and it it it does weird things like select text or delete text or save your
00:12:16.560 file or quit Vim or whatever and it's it's extremely confusing so just remember when you start up you're not in a mode where you can type you're in
00:12:22.920 normal mode um other modes you're going to be using all the time are visual mode which is where you're selecting text uh
00:12:29.320 command line mode which is where you're in the bottom corner of vims command line entering entering commands and then insert mode where you're actually
00:12:35.880 inserting text so let's do those three things I talked about um to open a file
00:12:40.920 we're going to press the colon key that puts us in the command line mode now we're in the lower leand corner on vims
00:12:46.279 command line and we'll type edit math. RB so e math. RB so we want to edit a
00:12:51.639 file called math. RB now we're ready to type so we enter insert mode you do that by pressing the I key notice my status
00:12:58.399 bar has changed to bright green that's uh Vim doesn't do this by default but I love being able to know what mode I'm in
00:13:05.399 so this is something I've just stuck in my vmrc it's like one line it's really simple um you can check that out now
00:13:10.680 we're in insert mode so I'm going to start typing and we are writing a ad method for Ruby's math module so really
00:13:19.440 cool almost done yes okay so we are now done typing
00:13:25.720 so we want to get out of insert mode so we're going to use the Escape key to get out of insert insert mode finally we
00:13:31.160 want to write our changes so we're going to go back down to the command line and use the W command so colon W for right
00:13:39.480 and our files changed okay so that's the Vim Basics probably everybody already knew how to do that so let's move along
00:13:44.760 to something else here's my vimrc this is has the status bar changes that we looked at it's also got a bunch of other
00:13:50.720 things that I like in Vim you may not like them so please don't just copy it otherwise you might be very confused um but there are lots of comments so you
00:13:57.000 know what um the configuration is doing okay the next thing so we heard today a
00:14:03.160 great talk about testing so let's see how to make that a good thing in
00:14:08.320 Vim uh we already know how to open files um so we looked at the uh math
00:14:14.720 Library just a second ago Let's test drive that so we'll write a test we'll run our test and we'll actually test drive that method we looked at and we'll
00:14:20.320 do it from within Vim so the first thing we need to do when starting a new library is we need to create a couple directories we want to create a li
00:14:26.399 directory to put our code in and a spec directory to put our test in right so we can do that in Vim we'll use Theon key
00:14:32.639 notice we're in the bottom left hand corner and we're just using the bash makeer command in Vim we can run any
00:14:38.199 shell command we want we just use a we proceed it with an exclamation mark to tell uh Vim we'd like to Shell out to
00:14:43.560 run this so we run that and now we have our two directories so next thing we want to do is write a spec so we can do
00:14:50.320 that again by going to the command line and we're going to edit our spec file math spec and now we can start writing
00:14:56.920 out the test so this this will look uh very clear to people who have used rspec
00:15:02.000 before we're just requiring our math library that doesn't exist yet and then
00:15:07.279 we're going to describe the add method with one example adding two
00:15:23.560 numbers okay we expect two plus four to equal six that makes sense all right the next thing we want to do is run our test
00:15:29.839 if we're using something like uh Ruby mine there's probably a button for this uh uh but we're not um if we're using um
00:15:37.000 Sublime Text there's a keyboard shortcut you can use to to run the file and I think it's aware of whether you're running a spec or not in Vim we can do
00:15:43.079 the same thing so um you can press comma T this doesn't do this by default but again this is very simple it's basically
00:15:48.639 going to Shell out like we saw when we made a directory run rpec and then we can see the results um it has some other
00:15:54.519 magic in here too for example if you're not currently on a spec file and you press comma t um then it's going to run
00:16:00.040 the last spec that you ran so that enables you to bounce around between files and continue running the same spec so we're going to press comma T our spec
00:16:07.120 runs and this is a an error right we don't have our math Library yet so now
00:16:12.319 we need to create that math Library we're going to come down here in the command line create the math
00:16:18.079 Library run our test again and now we have a failure so we
00:16:24.839 don't have our method add so now we can add the method ad
00:16:35.600 okay now we can hello that was weird sorry now we can run our test again so
00:16:41.560 we're going to press comma T we have another failure expect six got nil so we'll stick a six in
00:16:49.279 there run our test again
00:16:56.399 green okay so this is obviously not the code we want uh so we need to write another test um Vim is actually keeping
00:17:03.120 track of every place my cursor has been and every file I've had open so if we want to go back to our spec file to add
00:17:08.160 another test we press control o the way I remember this is um I try to visualize
00:17:13.199 the files I've opened as a stack and I don't know why why control o makes sense but I I imagine going out to the previous file so if I press crol o I go
00:17:20.480 back to my spec file and now we can write another spec so that we actually get some code that we think is going to be right we're just going to do adding
00:17:27.240 two negative numbers now
00:17:39.559 very good we'll now run our test again with commat t and we got a failure just as we expected time to go back to our uh
00:17:47.120 implementation code so instead of pressing CR o for out I think go in so control I is what you're going to press
00:17:52.760 to do this this goes the other direction in Vim in vim's stack of where your cursor's been sounds very confusing but
00:17:58.559 um just get you'll get used to it I promise give it a try so now we go back and we can finish writing out the code
00:18:04.240 that we think is going to make the test pass run it again and we're green so
00:18:11.360 that's testing in Vim um pretty straightforward what I really like about this approach I've seen people use um I
00:18:17.720 I was just talking to somebody about this yesterday I've seen people use splits for example to show their test results um I for me I I can really only
00:18:24.799 do one thing at a time so it's nice to have just like looking at one thing at a time you're looking at your code you run
00:18:30.000 your test you're just looking at your results it's very clean and pretty you're just looking at your um um test
00:18:35.120 and your code and you know it it makes sense you don't need to have everything on the screen at once um so it's very
00:18:40.400 focused all right moving along search something we do all the time in our editors is search for stuff so I'm going
00:18:47.640 to show you how to search in vim and how to do Replacements in Vim so here's the math library that we've been looking at
00:18:53.679 except notice my variable names are horrible they're single letter variable names so we want to do a search and
00:18:59.080 replace to fix that we want to replace L with left and R with right so to start a
00:19:04.280 search in Vim you use the for SL key that'll bring you down into the command
00:19:10.200 line down here again and you can type out what you'd like to search for so if we search for L you'll notice we get
00:19:15.320 four L's this is obviously not exactly what we want to search for but it's it's pretty close to go through your search
00:19:21.960 results keep hitting the end key and you'll just keep toggling through your search results if you have a huge file
00:19:27.320 this is really really useful to find all the cases of something in a file okay so let's refine our search a little bit so
00:19:33.799 that we're only getting the variable names we're not getting every single L on the file you can perform we're down here in the left hand corner forgot to
00:19:39.880 add a big bright red arrow um we are searching for just the word L now um which you probably can't see that what
00:19:46.000 we're doing is we're using a left carrot l and a right carrot that's vim's way of saying find the word L Vim supports all
00:19:52.080 kinds of regular Expressions so you can make really complicated queries if you like so if we do this search we now have
00:19:58.200 just the two things we're looking for so the next step we want to do is replace we want to replace the L with the word
00:20:03.919 left so we are going to use a command to do this we will enter the command line mode and we're going to use percent s
00:20:10.559 which means search the whole file and we're going to tell it what to search for and what to replace it for so in
00:20:16.760 this case we've already done our search so I've left our search term completely blank because Vim will just remember the
00:20:22.480 last thing we search for and I put left in there as what I'd like to replace it with next we can stick two parameters on
00:20:29.159 the end um if you'd like I stick um G on here to say replace everything every occurrence in the file not just the
00:20:34.799 first one you find and then also a c which means we want a confirmation for our search and replace so every time
00:20:40.720 you're going to do a replacement ask me before you do it so when we press enter our first results highlighted Vim is
00:20:46.400 asking us if we'd like to make the replacement we hit yes and then we'll hit yes one more time and we're done so
00:20:52.480 we're going to do this one more time but we're going to do it way quicker um we're going to do for R so instead of doing the search First and and then the
00:20:58.919 replacement we'll just do it all in one command so we're in the bottom left here again we're searching for the word r
00:21:05.720 we're going to place it with right and then stick the same two parameters on there and we're done so search and
00:21:12.480 replace in Vim it's very very easy okay um the second to last thing I
00:21:18.640 want to talk about in Vim is macros this is something I've never seen any other editor do and if they do it they do it totally different um a Vim macro is is
00:21:26.520 basically a recording of everything you do and you can save it um to any key you'd like and then replay that you can replay
00:21:33.000 it on one line you can replay it on five lines you can replay it in multiple files it's extremely powerful for little
00:21:39.760 Annoying tasks that you need to do over and over and over again um so here's an example uh I have a a table here these
00:21:46.840 are of my friends the First Column is last name second column is first name uh
00:21:52.480 and the last column is the year they were born before we get started with macros
00:21:58.919 uh this list is out of order so I'd like to sort it so this is how you can quickly sort in Vim we'll press VIP to
00:22:05.840 visually select the paragraph that our cursor is on and then we can run a command so I'll enter command line and
00:22:12.720 I'll type sort now our list is sorted and this
00:22:17.960 works on many different types of text and input so it's really cool that we can um sort like that okay now it's time
00:22:23.480 to record our macro so what I'd like to do on the end of each line is put the
00:22:29.200 person's age in parentheses so imagine I was popular and I had thousands and thousands of friends this would probably
00:22:35.640 take me the rest of my life to do this right um because not only do you need to type it out but you need to figure out
00:22:41.039 the age of each person based on the year they were born so instead we're going to record a macro so the first step in
00:22:46.880 recording a macro is telling them you want to record a macro so to do that you press the q key followed by where you'd
00:22:52.799 like to save the macro which register you'd like to save it in so I usually just press QQ because it's fast so we're
00:22:59.440 going to save we're going to start recording a macro and we're going to save it in the Q register so QQ we're recording if you look in the bottom left
00:23:06.200 vim's going to tell you that it that you're recording if you use Vim on a regular basis you've probably seen that you've been recording and you didn't
00:23:11.799 know you were recording uh so that's what that means you're recording a macro um so now it's time to actually record
00:23:18.200 our macro Vim is aware that we are wanting to record a macro so we start typing what we want to do the first
00:23:23.559 thing we want to do is go to the end of the line so we'll hit a dollar sign now we're on top of the year they were born
00:23:28.880 so we'd like to copy that so we can use it later for some math so we're going to press y IW to yank the word that our
00:23:34.679 cursor is on now that's saved off and stored somewhere in a register we can use it later next we're going to hit
00:23:40.360 capital A to put us at the end of the line and put us in insert mode so notice we have the bright green bar at the
00:23:46.120 bottom that's you could tell we're in insert mode and now we can start typing so we'll add that first parentheses next
00:23:52.159 thing we want to do now is is figure out the age so we actually have to do some math here um we can't just type uh Vim
00:23:57.880 can do math for us it has what's called the expression register so if we press control r equal sign that's going to
00:24:03.760 take us back down into the bottom left hand corner that we keep looking at and we now have an equals prompt so we can
00:24:09.200 type an expression thenm will evaluate it and stick it back up in our buffer so we're going to type
00:24:14.360 23 minus and then we want to paste the year that we already copied so we'll do
00:24:19.400 controlr and then the double quote so that gets pasted in now we have 2013 minus 2005 when you press enter we get
00:24:25.960 the result eight so now we can just finish typing out the line looks good we're done typing so
00:24:33.480 we'll get out of insert mode we'll hit the Escape key and I would say we're done now but there's one more thing we
00:24:39.120 want to do because we want to run this macro multiple times and chain it together we'll finish our macro by
00:24:44.559 moving to the next line that way it just it automatically increments to the next line so now we're done uh so we'll hit
00:24:50.880 the same key we used to start recording we'll hit the q key uh notice in the corner it no longer says we're recording
00:24:58.159 okay Okay so we've got our macro it's saved off time to replay it you can replay a macro by using the at sign and
00:25:04.440 then typing where you saved it to so remember we press uh we pressed in the beginning QQ meaning we recorded our
00:25:09.679 macro to the Q register so to replay that macro we'll do at Q done and notice our cursor is already
00:25:17.279 on the next line so we have four more lines we want to do this four more times instead of typing it four times we can
00:25:22.520 type four at Q and it runs four more times done so it's very easy I love
00:25:28.919 macros okay the last cool Vim thing the argument list has anyone actually used argument list
00:25:35.960 before three people have used the argument list four people okay I just learned about this so I'm actually still
00:25:41.600 kind of excited about it um this is the Vim argument list uh uh the argument list in Vim is a list
00:25:48.760 of arguments so you can put yes done the cool thing
00:25:54.440 though is you could put any um any uh file you want in vim's argument list and
00:25:59.919 then do stuff to that list so all the things we've looked at um search and replace macros anything else you do in
00:26:05.880 Vim you can do across a whole big old set of files if you load them up in the argument list um so we're going to go
00:26:11.600 back to this wonderful wonderful math Library extension and um practice the
00:26:16.640 argument list so let's say we've decided we no longer want a monkey patch math we want to be good citizens and rename our
00:26:21.760 module to something different uh if we only had this one file that'd be fine we would just do a search and replace and
00:26:27.640 be done with it but we probably also have a spec and we're probably using this file all over the place right so we
00:26:33.279 need to do a search and replace across multiple files this is exactly where the argument list is helpful so let's do
00:26:40.440 that um the first thing we want to do is load up our argument list with all the files we want to do a search and replace
00:26:45.960 on so we enter command mode we're in the corner we're going to use the command args AR RGS and anything you put after
00:26:54.440 that will be loaded into the argument list so you can actually type file names or in this case we're just going to um
00:27:00.039 shell out to bash and let um the find command find all the Ruby files in the lib and the spec directory and load them
00:27:05.760 into our argument list so now argument list is loaded up if you want to see what files are in the argument list just
00:27:12.480 type the same exact command go to the command line type args with no parameters and vim's going to print out
00:27:19.480 what's in the argument list so we have two files we have our library that we wrote and we have our spec file that we
00:27:24.679 wrote that's good now we want to do our search and replace across all all the files so we'll enter the command line
00:27:30.440 mode again this time we're going to use the AR do command because we want to do something for each of the arguments and
00:27:36.840 then you just type out what you want to do for each of the arguments so we're going to do a search for math replace it
00:27:42.720 with my math and when we're done we're going to write the file so you press enter Vim does it it'll tell you on the
00:27:49.720 bottom that it did it so it did it for two files and then it opens the last file it worked on so here's our spec
00:27:55.720 notice we now have my math instead of math if we look back at the actual module we have my math here as well uh
00:28:01.880 this is a really cool feature and you can use it like I said for macros as well and since a macro can do anything
00:28:07.760 uh you can do anything with the argument list uh this is a quick section I don't
00:28:13.799 use a lot of plugins but um I want to share three that I do use all the time so um these are really really useful if
00:28:20.880 you're in a rails project you're used to working with a bajillion files and having to open a bajillion files a second so a plugin I use for that is
00:28:27.519 called control p contrl p can be activated um how I've set it up in my vmrc you might do
00:28:33.720 something different you press comma F and you're going to get this giant little search box that pops up you can
00:28:39.360 start typing and it's just going to do a fuzzy search to narrow down search results when you find what you're
00:28:44.440 looking for press enter the file opens that's control P um the next plugin I want to talk about is searching through
00:28:51.159 files so that's how you would search for a specific file let's say you want to define a constant um throughout your
00:28:56.200 project I would use silver Searcher for that that Um this can be activated by me pressing comma a and then we're down in
00:29:03.240 the command line and we can type what we'd like to search for search will be
00:29:09.880 performed and we'll get all our results in a pain here at the bottom when you find what you want to looking for again just press enter and it'll open up for
00:29:17.000 you last plugin I want to talk about is g. VM so I don't create a lot of gist
00:29:22.840 but when I do this is really helpful let's say uh we have our math Library hypothetical math library and we
00:29:29.760 want to share it with somebody a good way to do that is just to create a gist and then give them the URL so I would
00:29:34.880 usually just select the text and then go to GitHub and create the gist and then um paste the URL and send it to them on email or chat or something like that
00:29:41.720 with g.v uh it's a lot shorter we'll just enter the command line type the word gist and then a gist will be
00:29:49.039 created and our browser will open so it's pretty cool I love that uh if you want to learn more about Vim
00:29:56.640 which there's way more to learn about about Vim this is a really good book it's by um Drew Neil who also does a
00:30:02.720 screencast series called vimcasts he hasn't done a new screencast in a while but there's a ton on there that you can
00:30:08.120 look at Drew also has a workshop that he does and you can work uh in a small
00:30:13.159 group of just a few people I've done this myself and is awesome that's actually where I learned about the argument list uh and I didn't want to
00:30:19.000 like reveal too much of his magic sauce so I'll leave you just that one uh this is great uh I know like I said there's
00:30:24.799 one this month there might be one um after that as well and finally there is a new email group called Vim SF and when
00:30:32.039 I was in San Francisco um that's how I became aware of this there's a Meetup as well associated with this so if you're
00:30:37.600 in San Francisco go to the meetups if you're not in San Francisco at least hop on the email list and you can hear some
00:30:43.240 cool um Vim tips as well uh let me get a drink of water again and then this will be the last
00:30:49.760 thing we talk about today so remote pairing like I said I
00:30:56.039 work with uh people that aren't sitting next to me so this is extremely powerful tool to be able to do remote pairing vim
00:31:01.880 and t-s uh how many people have tried doing remote pairing even with v tmu or
00:31:06.960 anything else so a lot of people who uses like a screen sharing apps like
00:31:12.440 Skype or um nobody uses screen does everybody use vim and tmok already for this okay everybody does okay well we'll
00:31:18.799 show you how to do it anyway uh this is a different way to do it um unless this is how you do it let me know uh the cool
00:31:25.360 thing about using vim and t-u for remote pairing is we're not using a screen sharing app that's like the best part
00:31:30.919 because you know how glitchy those are and how slow they are right also you'll have one person who's on their giant iMac sitting at home and another person
00:31:37.279 who's on 11inch MacBook Air and the poor person on the MacBook Air can't read any of the text because it's a huge screen
00:31:43.279 and they're using Ruby mine so it's really bad so uh we are going to see how to do
00:31:49.639 a t-u session and the reason why this works so much better is because you're just using SSH and you can use your own
00:31:55.200 color scheme you can use your own terminal you can use your own font size you can use your own font you can feel
00:32:00.480 way more comfortable and the response when you're typing on someone else's machine is is significantly faster so
00:32:06.720 the first thing you want to be able to do is create a new session that you can use to pair with somebody by default the
00:32:13.919 session you create in t-o is going to be uh private meaning that only you can access it or other people in your user
00:32:19.679 group but if you're going to have um somebody you trust don't ever pair with somebody you don't trust um if you have
00:32:25.080 somebody um SSH into your machine uh then you're going to want to create a session that they two can connect to so
00:32:31.679 we're going to create a t-u session and we're going to tell t-u to to store that session in sltm pair then we're just
00:32:38.120 going to change the permissions of it so that anybody can read and write it and then we'll connect to it so now we're going to attach ourselves to that
00:32:44.399 session that now anybody can look at okay so we're in so this looks
00:32:50.600 exactly like all the other t- sessions we've been using because it is um the next thing we're going to do is see how
00:32:57.039 um our friend or whatever um in my case I'm going to be using Louisa as an example she's my fiance and she will be
00:33:02.360 pairing with me she is on the right hand side and on the left hand side is the terminal we've just been looking at um
00:33:09.240 this is me so notice I'm still on my t-u session she just sshed into my machine
00:33:15.320 and now she wants to start working so she has to connect to the t-mo session so she's going to use the exact same um
00:33:21.039 t-mo command I used attach and tell what session to attach to and now she's
00:33:26.639 attached so we both had the exact same session name and we're both ready to go anything she types I'll see on my side
00:33:33.600 anything I type she'll see on her side notice too we each have our own color scheme we're actually using different
00:33:39.120 terminals uh it's pretty awesome and it's very fast okay so we're done um
00:33:45.279 let's talk about the scenario now where you have me at home working from home in my pajamas on my giant iMac and I'm
00:33:51.519 pairing with somebody who's at work on an 11in MacBook Air how does t-o handle that so here's the scenario I uh
00:33:59.519 demonstrated on one screen uh we have me who's running a bigger terminal Louisa who's running a teeny tiny little
00:34:05.440 terminal um notice I have a green border here that's t-mo's way of saying this is
00:34:12.119 your typing area I can't type outside of that as she makes her terminal smaller my typing area also gets smaller my
00:34:18.839 resolution is not changing my font's not changing but my typing area is changing uh when she makes it bigger my typing
00:34:24.879 area gets bigger as well so we can be working in completely different size Terminals and uh the person on the larger screen will just kind of not be
00:34:31.280 able to type outside of the area that the other person can see when she disconnects then my little green border
00:34:37.000 goes away and I'm all by myself again um working in the session uh so that's all I got that's V
00:34:43.200 t-u uh if you looks like a lot of people are already using it so hopefully you learned something um but somebody that
00:34:49.320 isn't using it I would recommend you try it um it's pretty cool it's a lot of fun it feels really crazy at first uh but I
00:34:55.320 promise it'll be worth it uh and if you have any questions feel free to send me an email or hit me up on Twitter or something like that um
00:35:12.280 thanks