WEBVTT 00:00:00.030 --> 00:00:05.339 Okay, cool. So, welcome to the third 00:00:03.360 --> 00:00:07.500 lecture of the missing semester of your 00:00:05.339 --> 00:00:09.990 si a second today we're going to be 00:00:07.500 --> 00:00:11.759 talking about text editors this is a 00:00:09.990 --> 00:00:13.259 topic that I really like I think it's 00:00:11.759 --> 00:00:14.940 one of the most valuable topics that 00:00:13.259 --> 00:00:17.130 we're teaching in this class because as 00:00:14.940 --> 00:00:19.619 programmers you spend so much of your 00:00:17.130 --> 00:00:21.840 time editing text editing programs that 00:00:19.619 --> 00:00:23.609 if you invest time into making yourself 00:00:21.840 --> 00:00:25.580 more efficient at doing this you'll save 00:00:23.609 --> 00:00:27.990 a ton of time probably hundreds of hours 00:00:25.580 --> 00:00:31.980 over the course of your undergrad or 00:00:27.990 --> 00:00:33.510 over the course of your career so text 00:00:31.980 --> 00:00:36.480 editors are a little bit different than 00:00:33.510 --> 00:00:38.280 other programs you might use to edit say 00:00:36.480 --> 00:00:39.750 things like English prose because 00:00:38.280 --> 00:00:41.760 programming is different than writing 00:00:39.750 --> 00:00:44.160 English prose when you're programming 00:00:41.760 --> 00:00:45.600 you spend a lot of time reading what 00:00:44.160 --> 00:00:47.579 you've written you spend a lot of time 00:00:45.600 --> 00:00:49.079 navigating around a buffer and you spend 00:00:47.579 --> 00:00:51.030 a lot of time making little edits to 00:00:49.079 --> 00:00:52.860 code all over the place rather than just 00:00:51.030 --> 00:00:53.789 writing in a long stream like you do 00:00:52.860 --> 00:00:55.289 when you're writing an essay or 00:00:53.789 --> 00:00:56.460 something and so it makes sense that 00:00:55.289 --> 00:00:57.899 there different programs for these 00:00:56.460 --> 00:00:59.309 different purposes right so yeah things 00:00:57.899 --> 00:01:01.440 like Microsoft Word for writing essays 00:00:59.309 --> 00:01:05.820 and things like vim and Emacs and vs 00:01:01.440 --> 00:01:07.409 code and sublime for writing code so the 00:01:05.820 --> 00:01:09.180 way you learn a text editor and become 00:01:07.409 --> 00:01:11.130 really good at it is you start with a 00:01:09.180 --> 00:01:12.840 tutorial and so that's basically going 00:01:11.130 --> 00:01:15.720 to be the function of today's lecture 00:01:12.840 --> 00:01:17.759 plus the exercises we've given you and 00:01:15.720 --> 00:01:19.950 then after the tutorial you need to 00:01:17.759 --> 00:01:22.020 stick with the editor for all your 00:01:19.950 --> 00:01:24.000 editing tasks and when you're learning a 00:01:22.020 --> 00:01:25.380 sophisticated tool so today we're going 00:01:24.000 --> 00:01:26.850 to teach you vim which is one powerful 00:01:25.380 --> 00:01:28.229 editor that a lot of programmers use 00:01:26.850 --> 00:01:30.240 when you're learning such a 00:01:28.229 --> 00:01:32.400 sophisticated tool it may be the case 00:01:30.240 --> 00:01:33.750 that initially switching to this tool 00:01:32.400 --> 00:01:35.850 slows you down a little bit when you're 00:01:33.750 --> 00:01:38.729 programming but stick with it because 00:01:35.850 --> 00:01:41.340 I'd say that in about 20 hours of 00:01:38.729 --> 00:01:42.990 programming using a new editor you'll be 00:01:41.340 --> 00:01:44.790 back to the same speed at which you 00:01:42.990 --> 00:01:46.350 programmed using your old tool and then 00:01:44.790 --> 00:01:47.759 after that the benefits will start and 00:01:46.350 --> 00:01:50.189 you'll get faster and faster as you 00:01:47.759 --> 00:01:53.579 learn more with these sophisticated 00:01:50.189 --> 00:01:55.079 programs like them it takes not way too 00:01:53.579 --> 00:01:58.200 long to learn the basics but a lifetime 00:01:55.079 --> 00:01:59.759 to master and so throughout the time 00:01:58.200 --> 00:02:01.649 you're using this tool make sure you 00:01:59.759 --> 00:02:03.240 look things up as you go if you ever get 00:02:01.649 --> 00:02:04.710 to a point where you're like oh this is 00:02:03.240 --> 00:02:06.420 a really inefficient way of doing things 00:02:04.710 --> 00:02:09.660 is there a better way the answer is 00:02:06.420 --> 00:02:11.730 almost always yes because these text 00:02:09.660 --> 00:02:13.709 editors were written by programmers for 00:02:11.730 --> 00:02:13.970 programmers and so of course like the 00:02:13.709 --> 00:02:15.200 peep 00:02:13.970 --> 00:02:17.330 I wrote these tolls ran into the same 00:02:15.200 --> 00:02:18.080 kinds of issues and fixed them so that 00:02:17.330 --> 00:02:19.760 you don't need to deal with these 00:02:18.080 --> 00:02:21.860 anymore and so yeah as you're learning 00:02:19.760 --> 00:02:23.870 make sure you look things up as you go 00:02:21.860 --> 00:02:25.370 either use Google or feel free to send 00:02:23.870 --> 00:02:27.320 us emails if you have questions or come 00:02:25.370 --> 00:02:29.590 to office hours and we'll help you 00:02:27.320 --> 00:02:32.300 figure out how to do things really fast 00:02:29.590 --> 00:02:34.130 so as far as which editor to learn in 00:02:32.300 --> 00:02:35.510 previous iterations of this class we 00:02:34.130 --> 00:02:36.890 actually avoided teaching a specific 00:02:35.510 --> 00:02:39.050 editor because we didn't want to enforce 00:02:36.890 --> 00:02:40.430 our opinions on you guys but we actually 00:02:39.050 --> 00:02:42.050 think that it's really useful to teach 00:02:40.430 --> 00:02:44.900 you how to use one particular tool and 00:02:42.050 --> 00:02:46.459 use it well and so people have really 00:02:44.900 --> 00:02:48.500 strong opinions about editor so you can 00:02:46.459 --> 00:02:52.040 see the course notes for more links on 00:02:48.500 --> 00:02:54.080 this topic looking at which editors have 00:02:52.040 --> 00:02:56.660 been popular over the years Stack 00:02:54.080 --> 00:02:59.090 Overflow I'm sure you've all heard of 00:02:56.660 --> 00:03:00.320 that does a survey every year asking 00:02:59.090 --> 00:03:02.000 developers various questions and one 00:03:00.320 --> 00:03:03.440 thing to ask is which TextEdit Derk do 00:03:02.000 --> 00:03:05.300 you use and it seems to be that 00:03:03.440 --> 00:03:07.730 currently the most popular kind of 00:03:05.300 --> 00:03:10.160 graphical editor is vs code and the most 00:03:07.730 --> 00:03:12.440 popular editor that is based within a 00:03:10.160 --> 00:03:13.910 command line interface is vim and so 00:03:12.440 --> 00:03:16.040 we're going to be teaching you vim and 00:03:13.910 --> 00:03:17.810 there a couple reasons for this one is 00:03:16.040 --> 00:03:19.970 that all the instructors so me John and 00:03:17.810 --> 00:03:21.320 Jose use vim as our primary editor and 00:03:19.970 --> 00:03:23.150 we've been doing this for many years and 00:03:21.320 --> 00:03:25.010 we've been very happy with it 00:03:23.150 --> 00:03:28.820 and we think that there are a lot of 00:03:25.010 --> 00:03:30.500 interesting ideas behind them so even if 00:03:28.820 --> 00:03:32.450 you don't end up using this particular 00:03:30.500 --> 00:03:35.540 tool in the long term I think it's 00:03:32.450 --> 00:03:37.280 valuable to learn these ideas and also a 00:03:35.540 --> 00:03:39.200 lot of tools have actually been really 00:03:37.280 --> 00:03:42.200 excited about the ideas in vim and so 00:03:39.200 --> 00:03:44.360 they support a vim emulation mode for 00:03:42.200 --> 00:03:45.820 example vs code what's apparently the 00:03:44.360 --> 00:03:48.170 most popular editor in use today 00:03:45.820 --> 00:03:50.660 supports vim bindings and this vim 00:03:48.170 --> 00:03:53.630 emulation mode as of now has like 1.4 00:03:50.660 --> 00:03:56.450 million downloads and as you'll see over 00:03:53.630 --> 00:03:57.830 the course of this lecture a lot of 00:03:56.450 --> 00:03:59.570 different tools like including your 00:03:57.830 --> 00:04:01.730 shell including things like the Python 00:03:59.570 --> 00:04:03.200 repple and like Jupiter notebook and all 00:04:01.730 --> 00:04:04.940 sorts of other things even your web 00:04:03.200 --> 00:04:06.890 browser can support of emulation mode 00:04:04.940 --> 00:04:10.400 and so yeah we're going to be teaching 00:04:06.890 --> 00:04:12.140 you this really neat tool today and in 00:04:10.400 --> 00:04:14.390 this lecture we can't really cover all 00:04:12.140 --> 00:04:17.030 of them right it's a very powerful tool 00:04:14.390 --> 00:04:18.769 but our goal is to teach you and the 00:04:17.030 --> 00:04:20.720 core philosophy of them like the really 00:04:18.769 --> 00:04:22.370 neat ideas behind it and then in 00:04:20.720 --> 00:04:23.750 addition to that some of the basics like 00:04:22.370 --> 00:04:25.490 how do you open a file close a file 00:04:23.750 --> 00:04:27.010 navigate around a file make edits and 00:04:25.490 --> 00:04:28.630 things like that and 00:04:27.010 --> 00:04:29.950 you may not remember every single little 00:04:28.630 --> 00:04:31.030 detail from this lecture because we're 00:04:29.950 --> 00:04:32.860 gonna go pretty fast through some of the 00:04:31.030 --> 00:04:34.510 material but it's all in the lecture 00:04:32.860 --> 00:04:36.640 notes and then the exercises actually 00:04:34.510 --> 00:04:37.900 give you links to some tutorials and 00:04:36.640 --> 00:04:40.030 things so I highly recommend that you 00:04:37.900 --> 00:04:43.840 actually go through all the exercises at 00:04:40.030 --> 00:04:49.450 least the non advanced exercises any 00:04:43.840 --> 00:04:51.250 questions so far great okay so one of 00:04:49.450 --> 00:04:54.160 the really cool ideas behind them is 00:04:51.250 --> 00:04:56.080 that vim is a modal editor what does 00:04:54.160 --> 00:04:58.450 this mean modal comes from the word mode 00:04:56.080 --> 00:05:00.970 and this means that vim has multiple 00:04:58.450 --> 00:05:02.920 operating modes and this is kind of 00:05:00.970 --> 00:05:04.570 developed from the idea that when you're 00:05:02.920 --> 00:05:05.950 programming there often times where 00:05:04.570 --> 00:05:07.420 you're doing different types of things 00:05:05.950 --> 00:05:09.220 like sometimes you're reading code 00:05:07.420 --> 00:05:10.960 sometimes you're making small edits to 00:05:09.220 --> 00:05:12.340 code like you're finding a particular 00:05:10.960 --> 00:05:15.040 point like changing a little thing 00:05:12.340 --> 00:05:16.540 somewhere sometimes you're just writing 00:05:15.040 --> 00:05:17.470 a lot of code in one go like suppose 00:05:16.540 --> 00:05:19.090 you're just writing a function from 00:05:17.470 --> 00:05:20.380 scratch and so there's different 00:05:19.090 --> 00:05:24.070 operating modes for doing these 00:05:20.380 --> 00:05:25.180 different types of things and so I'm 00:05:24.070 --> 00:05:26.470 actually want to write this down on the 00:05:25.180 --> 00:05:28.780 blackboard so I'll have a useful thing 00:05:26.470 --> 00:05:33.280 to refer to later so when you start vim 00:05:28.780 --> 00:05:35.260 up it starts up in what's called normal 00:05:33.280 --> 00:05:37.270 mode and in this mode all the different 00:05:35.260 --> 00:05:38.650 key combinations behave in one way and 00:05:37.270 --> 00:05:40.030 then there are different key 00:05:38.650 --> 00:05:42.400 combinations that switch you between 00:05:40.030 --> 00:05:45.880 normal mode and other modes which change 00:05:42.400 --> 00:05:47.950 the meaning of different keys so for the 00:05:45.880 --> 00:05:49.870 most part you'll be spending most of 00:05:47.950 --> 00:05:55.420 your time in vim in normal mode or what 00:05:49.870 --> 00:05:57.400 is called insert mode and to go to 00:05:55.420 --> 00:05:59.530 insert mode you press the key I for 00:05:57.400 --> 00:06:01.600 normal mode and to go from insert mode 00:05:59.530 --> 00:06:06.700 back to normal mode you press the Escape 00:06:01.600 --> 00:06:09.580 key a little note on notation because 00:06:06.700 --> 00:06:11.020 we'll need this later in the notation 00:06:09.580 --> 00:06:12.610 I'm going to be using in this lecture 00:06:11.020 --> 00:06:15.100 and what's also in the lecture notes and 00:06:12.610 --> 00:06:16.150 what vim uses to give you feedback they 00:06:15.100 --> 00:06:17.740 have a couple different ways of talking 00:06:16.150 --> 00:06:19.270 about different keys so when they're 00:06:17.740 --> 00:06:20.440 talking about bare keys like just the 00:06:19.270 --> 00:06:22.660 eye key on your keyboard they'll just 00:06:20.440 --> 00:06:24.310 say eye but for a different key 00:06:22.660 --> 00:06:27.130 combinations like when you press control 00:06:24.310 --> 00:06:29.920 and something like say control V it's 00:06:27.130 --> 00:06:32.350 notated in one of like approximately 00:06:29.920 --> 00:06:34.600 three ways one way that can be notated 00:06:32.350 --> 00:06:37.480 is a caret and then the control 00:06:34.600 --> 00:06:39.580 character so this is control V another 00:06:37.480 --> 00:06:40.660 way this might be written I think we've 00:06:39.580 --> 00:06:42.250 written it this way in 00:06:40.660 --> 00:06:43.150 lecture notes as control-v this is 00:06:42.250 --> 00:06:46.060 probably the one you're more used to 00:06:43.150 --> 00:06:48.880 seeing and then in some parts of them 00:06:46.060 --> 00:06:51.010 this is written as angle brackets C - V 00:06:48.880 --> 00:06:54.210 close angle bracket so just a little bit 00:06:51.010 --> 00:06:54.210 of notation that will be useful later 00:06:54.220 --> 00:06:59.350 so yeah vim has a couple different modes 00:06:56.950 --> 00:07:01.540 where normal mode is designed for 00:06:59.350 --> 00:07:03.520 navigating around a file reading things 00:07:01.540 --> 00:07:05.620 going from file to file things like that 00:07:03.520 --> 00:07:08.380 and then insert mode is where you type 00:07:05.620 --> 00:07:10.330 in text so most keys that you press here 00:07:08.380 --> 00:07:12.040 will just go into your text buffer where 00:07:10.330 --> 00:07:13.780 as keys that you press here are not 00:07:12.040 --> 00:07:15.190 being put into the buffer and instead 00:07:13.780 --> 00:07:20.380 are used for things like navigation or 00:07:15.190 --> 00:07:21.520 making edits and actually the picture is 00:07:20.380 --> 00:07:23.200 a little bit more complicated than this 00:07:21.520 --> 00:07:24.370 there are a whole bunch of other modes 00:07:23.200 --> 00:07:25.900 and I'm just gonna write them down here 00:07:24.370 --> 00:07:29.050 because we'll have them here to refer to 00:07:25.900 --> 00:07:33.100 later and so if it also has a replace 00:07:29.050 --> 00:07:34.030 mode for rather than inserting text and 00:07:33.100 --> 00:07:36.160 kind of pushing what's ahead of it 00:07:34.030 --> 00:07:37.810 forward it will overwrite text and then 00:07:36.160 --> 00:07:44.920 it has a bunch of different modes for 00:07:37.810 --> 00:07:48.040 selection so it has a mode called visual 00:07:44.920 --> 00:07:53.710 mode and then it has visual line and 00:07:48.040 --> 00:07:57.040 visual block this one is enter via the R 00:07:53.710 --> 00:08:01.810 key this was entered via the V key this 00:07:57.040 --> 00:08:05.680 one is entered via shift B and this one 00:08:01.810 --> 00:08:13.300 is entered via control V and then 00:08:05.680 --> 00:08:17.430 there's the command line mode which is 00:08:13.300 --> 00:08:17.430 entered via the colon key 00:08:19.180 --> 00:08:31.300 okay so now that we have that on the 00:08:21.070 --> 00:08:35.230 board to refer to later we can actually 00:08:31.300 --> 00:08:36.340 try some of this out all right so one 00:08:35.230 --> 00:08:38.560 thing we noticed looking at that picture 00:08:36.340 --> 00:08:40.390 is that to go from normal mode to any of 00:08:38.560 --> 00:08:41.800 the other modes we press some key but to 00:08:40.390 --> 00:08:43.330 go from any of the other modes back to 00:08:41.800 --> 00:08:45.190 normal mode where we spend a lot of our 00:08:43.330 --> 00:08:48.640 time we use the Escape key on our 00:08:45.190 --> 00:08:49.960 keyboard so for this reason since you 00:08:48.640 --> 00:08:51.970 under pressing the Escape key a lot when 00:08:49.960 --> 00:08:53.650 using vim a lot of programmers rebind 00:08:51.970 --> 00:08:55.180 one of the keys on their keyboard to be 00:08:53.650 --> 00:08:56.620 escape because it's really inconvenient 00:08:55.180 --> 00:08:58.060 to reach up with your left pinkie to 00:08:56.620 --> 00:08:59.920 press that tiny little Escape key in the 00:08:58.060 --> 00:09:01.870 corner of your keyboard and so a lot of 00:08:59.920 --> 00:09:04.540 people use the caps lock key instead so 00:09:01.870 --> 00:09:06.580 it's right there in the home row and we 00:09:04.540 --> 00:09:14.380 have some links in the lecture notes for 00:09:06.580 --> 00:09:15.730 how you can do this key rebinding okay 00:09:14.380 --> 00:09:17.500 so now that we've talked about kind of 00:09:15.730 --> 00:09:19.300 one of the core ideas of vim the idea of 00:09:17.500 --> 00:09:20.830 modal editing we can talk about some of 00:09:19.300 --> 00:09:23.080 the basics like how do you open up this 00:09:20.830 --> 00:09:25.870 text editor how do you open file save 00:09:23.080 --> 00:09:28.240 files and things like that and so this 00:09:25.870 --> 00:09:29.740 is a command line based program although 00:09:28.240 --> 00:09:31.900 there are some graphical variants and 00:09:29.740 --> 00:09:34.420 the way you start this program is by 00:09:31.900 --> 00:09:35.800 running vim one thing you might notice 00:09:34.420 --> 00:09:37.510 is that in the bottom left corner of my 00:09:35.800 --> 00:09:40.090 screen they actually saw what I just 00:09:37.510 --> 00:09:41.530 typed this will be useful later in this 00:09:40.090 --> 00:09:44.020 lecture where I'm actually typing in 00:09:41.530 --> 00:09:45.370 commands for vim and I'll be saying what 00:09:44.020 --> 00:09:47.890 I'm typing but you'll also see it on the 00:09:45.370 --> 00:09:50.380 screen so if I press ctrl C see it says 00:09:47.890 --> 00:09:55.510 ctrl C over there is that text big 00:09:50.380 --> 00:09:57.610 enough for everybody to read great okay 00:09:55.510 --> 00:09:59.800 so the way we open vim is just by 00:09:57.610 --> 00:10:02.470 running the program vim on our command 00:09:59.800 --> 00:10:03.790 line and this comes pre-installed on 00:10:02.470 --> 00:10:05.020 most systems and if you don't have it 00:10:03.790 --> 00:10:07.600 you can install it using your package 00:10:05.020 --> 00:10:08.560 manager vim can also take an argument if 00:10:07.600 --> 00:10:10.570 we want to use it to edit a particular 00:10:08.560 --> 00:10:12.850 file instead of just opening up the 00:10:10.570 --> 00:10:15.310 program then later opening a file so for 00:10:12.850 --> 00:10:17.140 example I have a file in this directory 00:10:15.310 --> 00:10:19.690 this is actually the lecture notes for 00:10:17.140 --> 00:10:21.940 this lecture so I can do vim editors MD 00:10:19.690 --> 00:10:25.690 and press ENTER and then boom them is 00:10:21.940 --> 00:10:29.820 started and then in this lecture I'm not 00:10:25.690 --> 00:10:32.860 running vim in the completely Exton I've 00:10:29.820 --> 00:10:34.930 configured a couple of things that 00:10:32.860 --> 00:10:36.940 behave a little bit nicer by defaults 00:10:34.930 --> 00:10:38.410 little things like having line numbers 00:10:36.940 --> 00:10:40.210 on the left or having some more status 00:10:38.410 --> 00:10:41.140 information on the bottom and if you 00:10:40.210 --> 00:10:42.850 want to start with this default 00:10:41.140 --> 00:10:43.930 configuration we have a link to this in 00:10:42.850 --> 00:10:49.270 the lecture notes so you can get a 00:10:43.930 --> 00:10:51.250 slightly more sane config by default. So, 00:10:49.270 --> 00:10:53.290 once you've opened Vim, what do you do? 00:10:51.250 --> 00:10:54.580 Well, as I said earlier, Vim starts in 00:10:53.290 --> 00:10:57.880 normal mode, so if I just start typing 00:10:54.580 --> 00:10:59.650 letters like, say, type X it didn't insert 00:10:57.880 --> 00:11:01.660 X into the buffer. You can see the cursor 00:10:59.650 --> 00:11:03.610 up in the top left: it actually deleted 00:11:01.660 --> 00:11:07.300 one of the characters. That's because I'm 00:11:03.610 --> 00:11:08.620 in normal mode, not insert mode. So insert 00:11:07.300 --> 00:11:09.850 mode is basically what you're used to with 00:11:08.620 --> 00:11:10.900 all the other text editors you've used 00:11:09.850 --> 00:11:12.310 in the past, where there's a cursor 00:11:10.900 --> 00:11:15.310 somewhere, you press the character, and it 00:11:12.310 --> 00:11:18.130 just goes into your buffer. I'm instead 00:11:15.310 --> 00:11:19.900 in vim you start a normal mode and you 00:11:18.130 --> 00:11:21.610 can press I to go into insert mode so 00:11:19.900 --> 00:11:23.980 see I've pressed I and then in the 00:11:21.610 --> 00:11:26.500 bottom left notice that it says - - 00:11:23.980 --> 00:11:27.850 insert the bottom left always tells you 00:11:26.500 --> 00:11:29.650 what mode you're in unless this normal 00:11:27.850 --> 00:11:31.270 mode in which case it's blank and now 00:11:29.650 --> 00:11:33.250 that I'm an insert mode if I press the X 00:11:31.270 --> 00:11:35.740 character for example see it just gets 00:11:33.250 --> 00:11:37.450 inserted into my text buffer and I can 00:11:35.740 --> 00:11:39.580 backspace over at type other stuff and 00:11:37.450 --> 00:11:41.400 now my text editor kind of behaves like 00:11:39.580 --> 00:11:43.780 you'd expect any other program to behave 00:11:41.400 --> 00:11:45.520 so from this point how to go back to 00:11:43.780 --> 00:11:48.910 normal mode if I want to stop inserting 00:11:45.520 --> 00:11:51.670 characters. Yes, exactly. I press escape. 00:11:48.910 --> 00:11:53.830 And, that's the symbol my keystroke 00:11:51.670 --> 00:11:58.960 visualizer uses for escape, so 00:11:53.830 --> 00:12:01.150 just be aware of that. And then, Vim has 00:11:58.960 --> 00:12:02.890 this idea, that using the mouse is 00:12:01.150 --> 00:12:04.570 inefficient, like your hands are on the 00:12:02.890 --> 00:12:06.460 keyboard, moving your hand over to the 00:12:04.570 --> 00:12:08.290 mouse takes a lot of time, right, like you 00:12:06.460 --> 00:12:09.610 don't want to waste those couple of 00:12:08.290 --> 00:12:11.410 milliseconds while you're programming, 00:12:09.610 --> 00:12:13.990 like in the middle of things. So, instead, 00:12:11.410 --> 00:12:15.700 all Vim functionality can be accessed 00:12:13.990 --> 00:12:16.780 just through the keyboard. And, it's all 00:12:15.700 --> 00:12:19.330 sorts of things you might be used to 00:12:16.780 --> 00:12:21.460 doing like opening files by going, like, 00:12:19.330 --> 00:12:23.050 file open, or file save, or things like 00:12:21.460 --> 00:12:25.450 that, or instead access through the 00:12:23.050 --> 00:12:27.520 keyboard. And, how is that done? That's 00:12:25.450 --> 00:12:28.690 done through one of the other Vim modes 00:12:27.520 --> 00:12:31.960 that are on the board over there. In 00:12:28.690 --> 00:12:33.850 particular, through command line mode. So, 00:12:31.960 --> 00:12:36.370 if you're in normal mode, and you press 00:12:33.850 --> 00:12:39.370 the ":" key, you'll notice that the 00:12:36.370 --> 00:12:41.320 cursor - I guess my visualizer is covering 00:12:39.370 --> 00:12:43.060 the thing right now but it's gone - the 00:12:41.320 --> 00:12:46.110 cursor jumps to the bottom - the bottom 00:12:43.060 --> 00:12:48.510 left - and it shows that ":" I just typed. 00:12:46.110 --> 00:12:50.220 Now, I can type in a command. So, you can 00:12:48.510 --> 00:12:51.570 think of this almost like the command 00:12:50.220 --> 00:12:53.160 shell that we've talked been talking 00:12:51.570 --> 00:12:54.029 about over the last few days, except this 00:12:53.160 --> 00:12:55.800 is Vim's 00:12:54.029 --> 00:12:57.200 command shell, so you give Vim commands 00:12:55.800 --> 00:12:59.339 here, instead of shell commands. And 00:12:57.200 --> 00:13:00.600 there are a bunch of built-in commands 00:12:59.339 --> 00:13:02.820 that do all the things that you're used 00:13:00.600 --> 00:13:04.260 to. Like, for example, one command that you 00:13:02.820 --> 00:13:05.670 might want to know is how to quit this 00:13:04.260 --> 00:13:07.440 editor. You might notice that if you're in 00:13:05.670 --> 00:13:08.730 normal mode, I can press "Escape" to go 00:13:07.440 --> 00:13:11.940 back from command line mode to normal 00:13:08.730 --> 00:13:13.560 mode, and I press "control C", unlike what 00:13:11.940 --> 00:13:16.019 happens to a lot of programs, this doesn't 00:13:13.560 --> 00:13:18.360 quit Vim. So, how do I quit Vim? I can 00:13:16.019 --> 00:13:19.860 press ":", and then go into command 00:13:18.360 --> 00:13:23.430 line mode, and then I can type in the 00:13:19.860 --> 00:13:24.870 command "quit". "Q-U-I-T". You'll see that I 00:13:23.430 --> 00:13:28.560 - maybe I should move this over to the 00:13:24.870 --> 00:13:31.350 middle or something - see, it says ":quit" 00:13:28.560 --> 00:13:32.910 and I press ENTER, and it quits Vim. I can 00:13:31.350 --> 00:13:35.490 open Vim up again. There's actually a 00:13:32.910 --> 00:13:38.430 short form for this command, just ":q", and 00:13:35.490 --> 00:13:40.019 that'll do the same thing. And, there are a 00:13:38.430 --> 00:13:42.839 bunch of other useful commands like this. 00:13:40.019 --> 00:13:45.149 So, some other handy ones to know are 00:13:42.839 --> 00:13:47.790 how do you save a file? So, suppose I make 00:13:45.149 --> 00:13:51.420 some edits here, like "hello world". 00:13:47.790 --> 00:13:53.970 So, I pressed "i" to go into insert mode - or 00:13:51.420 --> 00:13:55.560 let me redo that - I press "i" to go into 00:13:53.970 --> 00:14:02.010 insert mode. Right now, I can use the down 00:13:55.560 --> 00:14:03.240 arrow to... I think I've slightly I 00:14:02.010 --> 00:14:07.019 should fix that. Can you fix the config, 00:14:03.240 --> 00:14:11.730 actually, John? Never mind that. 00:14:07.019 --> 00:14:14.820 Okay, so, suppose I go down to this line, 00:14:11.730 --> 00:14:17.010 and I press "i" to go into insert mode, and 00:14:14.820 --> 00:14:18.930 type in some text, and then press "escape" 00:14:17.010 --> 00:14:20.610 to go back to normal mode. Now, how do I 00:14:18.930 --> 00:14:22.680 actually save this file? Well, there's 00:14:20.610 --> 00:14:25.550 another command for that. So, ":" to go 00:14:22.680 --> 00:14:30.480 into command mode, and then I can type "W"... 00:14:25.550 --> 00:14:33.240 ...and press "Enter". "W" stands for write. And, 00:14:30.480 --> 00:14:35.699 it says in the bottom "editors.md" 00:14:33.240 --> 00:14:37.829 whatever blah blah written. And, so, this 00:14:35.699 --> 00:14:40.320 means it saved the file and so now if I 00:14:37.829 --> 00:14:42.209 ":q" to quit and open the same file, 00:14:40.320 --> 00:14:46.850 again, you'll see that the changes have 00:14:42.209 --> 00:14:49.019 been persisted. There are a couple other 00:14:46.850 --> 00:14:50.130 there's... So, there's a ton of different 00:14:49.019 --> 00:14:53.070 Vim commands that are useful for 00:14:50.130 --> 00:14:56.100 different reasons. But, I'll just explain 00:14:53.070 --> 00:14:59.070 a couple more to you now. One command 00:14:56.100 --> 00:15:01.500 that's really useful is help. ":help" 00:14:59.070 --> 00:15:04.080 And you can do ":help", and then type in a 00:15:01.500 --> 00:15:06.090 particular key, or a particular command, 00:15:04.080 --> 00:15:08.580 and get help for that keystroke or that 00:15:06.090 --> 00:15:10.950 command. So, if I want to know what 00:15:08.580 --> 00:15:15.420 ":w" does, I 00:15:10.950 --> 00:15:21.300 can do : help : W, and that'll give me 00:15:15.420 --> 00:15:23.160 the documentation on : w or : write. If I 00:15:21.300 --> 00:15:25.560 do : q, it'll close this window and bring 00:15:23.160 --> 00:15:28.530 me back to where I was before. 00:15:25.560 --> 00:15:35.340 And, notice that ":help :w" is different 00:15:28.530 --> 00:15:38.190 from ":help w", because the W key is the W 00:15:35.340 --> 00:15:40.590 that, like, when you're in normal mode and 00:15:38.190 --> 00:15:41.670 press W, what happens is just the W key 00:15:40.590 --> 00:15:43.530 here without the ":". 00:15:41.670 --> 00:15:50.340 And, if I look for help for ":w", that's 00:15:43.530 --> 00:15:56.040 the help for the W command. So, now you 00:15:50.340 --> 00:15:58.110 basically have the bare fundamentals 00:15:56.040 --> 00:16:00.720 needed to use them. right? You can open 00:15:58.110 --> 00:16:03.180 the editor, use it to edit a particular 00:16:00.720 --> 00:16:05.010 file, press "i" to go into insert mode and 00:16:03.180 --> 00:16:06.840 type in some text, press "escape" to go 00:16:05.010 --> 00:16:09.630 back to normal mode, and then :w to save 00:16:06.840 --> 00:16:11.460 your changes, :w to quit. So, like already 00:16:09.630 --> 00:16:13.920 you have the bare fundamentals necessary 00:16:11.460 --> 00:16:17.210 to edit files using Vim, albeit somewhat 00:16:13.920 --> 00:16:23.700 inefficiently. So, any questions so far? 00:16:17.210 --> 00:16:25.470 Yeah in the back. Yeah so the question is, 00:16:23.700 --> 00:16:27.060 What's the benefit of the 00:16:25.470 --> 00:16:28.590 normal mode? And, we'll talk about that in 00:16:27.060 --> 00:16:31.560 more detail, in like five minutes. 00:16:28.590 --> 00:16:33.030 But, in short, insert mode is just for 00:16:31.560 --> 00:16:34.920 typing in text. So, I'm in insert mode, I 00:16:33.030 --> 00:16:36.270 can type in text. But, when I'm 00:16:34.920 --> 00:16:39.000 programming, I actually spend a lot of 00:16:36.270 --> 00:16:40.590 time moving around my file making small 00:16:39.000 --> 00:16:42.210 little changes. So, I go here and like, oh 00:16:40.590 --> 00:16:45.390 maybe I want to change this HTTPS link to 00:16:42.210 --> 00:16:48.120 an HTTP. 00:16:45.390 --> 00:16:49.920 I can make like small point edits, things 00:16:48.120 --> 00:16:51.120 like that, in normal mode. And we'll see a 00:16:49.920 --> 00:16:52.920 whole lot more of that in about five 00:16:51.120 --> 00:16:59.130 minutes. Good question! 00:16:52.920 --> 00:17:05.070 Any other questions? Okay cool. So, moving 00:16:59.130 --> 00:17:11.100 along, one other thing that's kind of 00:17:05.070 --> 00:17:12.720 useful to know, I think, is, at a high 00:17:11.100 --> 00:17:15.479 level, Vim's model of 00:17:12.720 --> 00:17:16.470 buffers versus windows versus tabs. So, 00:17:15.479 --> 00:17:17.939 it's probably the case that whatever 00:17:16.470 --> 00:17:19.829 program you were using before, like 00:17:17.939 --> 00:17:21.899 Sublime Text or VS Code or whatever, 00:17:19.829 --> 00:17:23.249 you could open multiple files in it, 00:17:21.899 --> 00:17:24.899 right, and you could probably have 00:17:23.249 --> 00:17:27.449 multiple tabs open and have multiple 00:17:24.899 --> 00:17:29.129 windows open of your editor. So, Vim also 00:17:27.449 --> 00:17:31.200 has a notion of those different things. 00:17:29.129 --> 00:17:34.379 But, its model is a little bit different 00:17:31.200 --> 00:17:36.359 than most other programs. So, Vim 00:17:34.379 --> 00:17:38.340 maintains a set of open buffers - that's 00:17:36.359 --> 00:17:40.320 the word it uses for open files - and so, 00:17:38.340 --> 00:17:42.239 it has a set of open files, and then kind 00:17:40.320 --> 00:17:44.489 of separately from that, you can have a 00:17:42.239 --> 00:17:46.619 number of tabs, and tabs can have windows. 00:17:44.489 --> 00:17:47.460 The kind of weird thing which makes Vim 00:17:46.619 --> 00:17:48.899 a little bit different than the 00:17:47.460 --> 00:17:50.729 program you've probably used in the past is 00:17:48.899 --> 00:17:52.049 that there isn't necessarily a 00:17:50.729 --> 00:17:55.200 one-to-one correspondence between 00:17:52.049 --> 00:17:56.669 buffers and windows. So, one thing I can 00:17:55.200 --> 00:17:58.259 do, for example, here - and we'll show you 00:17:56.669 --> 00:18:00.989 the key combinations and stuff for this 00:17:58.259 --> 00:18:02.220 later - but one thing you can do is create 00:18:00.989 --> 00:18:04.109 two different windows. So, I have one 00:18:02.220 --> 00:18:07.139 window up here, and then one window down 00:18:04.109 --> 00:18:08.609 here. And, notice that the same files open 00:18:07.139 --> 00:18:10.529 in both windows. So, if I make some edits 00:18:08.609 --> 00:18:11.759 over here, they actually happen in the 00:18:10.529 --> 00:18:13.729 bottom window, as well, because it's the 00:18:11.759 --> 00:18:14.412 same buffer that's open in both windows. 00:18:14.412 --> 00:18:18.269 And, this is kind of useful, for, say, 00:18:16.590 --> 00:18:19.830 looking at two different parts of a 00:18:18.269 --> 00:18:20.940 single file at the same time. Like, so you 00:18:19.830 --> 00:18:22.919 want to be able to look at the top of a 00:18:20.940 --> 00:18:25.049 file, say at an import to your program, 00:18:22.919 --> 00:18:27.809 while you're down below, working 00:18:25.049 --> 00:18:29.129 somewhere else. So, this is one helpful 00:18:27.809 --> 00:18:32.999 thing to keep in mind, that Vim has this 00:18:29.129 --> 00:18:35.729 idea of - there are a number of tabs, and 00:18:32.999 --> 00:18:38.159 each tab has some number of windows, and 00:18:35.729 --> 00:18:40.649 then each window has, uh, corresponds to 00:18:38.159 --> 00:18:42.269 some buffer. But, a particular buffer can 00:18:40.649 --> 00:18:44.399 be open in zero or more windows at a 00:18:42.269 --> 00:18:45.809 time. Just one thing that confused me 00:18:44.399 --> 00:18:48.049 when I was initially learning Vim, so I 00:18:45.809 --> 00:18:50.669 want to explain that early on. And then, 00:18:48.049 --> 00:18:53.580 the ":q" command, which we talked about 00:18:50.669 --> 00:18:55.349 earlier, is not exactly quit. It's kind of 00:18:53.580 --> 00:18:56.729 "close the current window", and then, when 00:18:55.349 --> 00:18:59.460 there are no more open windows, Vim will 00:18:56.729 --> 00:19:01.320 quit. So, here, if I do ":q", it'll only 00:18:59.460 --> 00:19:03.570 close the window, I think, on the top here 00:19:01.320 --> 00:19:05.609 because that's the one I was in, and, now, 00:19:03.570 --> 00:19:08.159 the remaining window becomes fullscreen. 00:19:05.609 --> 00:19:10.379 I can do : Q again to close this. Now we're in 00:19:08.159 --> 00:19:14.879 the second tab that I'd opened. If I do :Q 00:19:10.379 --> 00:19:16.229 a final time, okay, now, Vim exits. And if 00:19:14.879 --> 00:19:17.940 you don't want to press ":q" way too many 00:19:16.229 --> 00:19:21.419 times... Okay, so, here I have three split 00:19:17.940 --> 00:19:24.589 windows. If I do ":qa", for quit all, it 00:19:21.419 --> 00:19:24.589 closes all the open windows. 00:19:25.370 --> 00:19:30.660 All right, so, now, to answer your question of 00:19:28.650 --> 00:19:32.610 "What is normal mode actually for?" This is 00:19:30.660 --> 00:19:34.080 another, really cool idea in Vim, and I 00:19:32.610 --> 00:19:36.030 think this is actually, like, the most 00:19:34.080 --> 00:19:38.550 fundamentally interesting idea of this 00:19:36.030 --> 00:19:42.000 program. It's that, like, you're all 00:19:38.550 --> 00:19:44.370 programmers, you like programming; Vim has 00:19:42.000 --> 00:19:47.220 this idea that Vim's normal mode, like, 00:19:44.370 --> 00:19:49.740 Vim's interface, itself, is a programming 00:19:47.220 --> 00:19:51.060 language. And, let me repeat that. 00:19:49.740 --> 00:19:52.860 That's like a kind of fundamentally 00:19:51.060 --> 00:19:54.020 interesting idea: the interface is a 00:19:52.860 --> 00:19:56.250 programming language. 00:19:54.020 --> 00:19:57.570 What does that mean? It means that 00:19:56.250 --> 00:19:59.280 different key combinations have 00:19:57.570 --> 00:20:00.150 different effects, and, once you learn the 00:19:59.280 --> 00:20:02.400 different effects, you can actually 00:20:00.150 --> 00:20:03.390 combine them together - just like in a 00:20:02.400 --> 00:20:04.770 programming language - you can learn 00:20:03.390 --> 00:20:05.880 different functions and stuff and then 00:20:04.770 --> 00:20:08.070 glue them all together to make an 00:20:05.880 --> 00:20:09.870 interesting program. In the same way, once 00:20:08.070 --> 00:20:10.980 you learn Vim's different movement and 00:20:09.870 --> 00:20:13.890 editing commands, and things like that, 00:20:10.980 --> 00:20:16.950 you can talk to Vim by programming Vim 00:20:13.890 --> 00:20:19.170 through its interface. And, once this 00:20:16.950 --> 00:20:20.880 becomes muscle memory, you can basically 00:20:19.170 --> 00:20:22.440 edit files at the speed at which you 00:20:20.880 --> 00:20:23.640 think. Like at least for me, I don't think 00:20:22.440 --> 00:20:25.320 I've been able to do this with any other 00:20:23.640 --> 00:20:29.010 text editor that I've used in the past, 00:20:25.320 --> 00:20:31.380 but this one gets pretty close. So, let's 00:20:29.010 --> 00:20:34.170 dig into how exactly normal mode works. 00:20:31.380 --> 00:20:36.140 So, you can try to follow along with this, 00:20:34.170 --> 00:20:38.400 like, open up some random file in Vim, and 00:20:36.140 --> 00:20:40.470 follow some of the key combinations I 00:20:38.400 --> 00:20:42.330 type in. So, one basic thing that you 00:20:40.470 --> 00:20:44.010 might want to do, is just navigate around 00:20:42.330 --> 00:20:46.020 a buffer. Like, move your cursor up/down/ 00:20:44.010 --> 00:20:48.510 left/right. And, so the way you do that in 00:20:46.020 --> 00:20:50.700 Vim, is using the hjkl keys, not the arrow 00:20:48.510 --> 00:20:52.050 keys. Though they do work by default, try 00:20:50.700 --> 00:20:53.520 to avoid them, because you don't want to 00:20:52.050 --> 00:20:54.660 have to move your hand all the way over 00:20:53.520 --> 00:20:57.240 to the arrow keys. Like, there's a ton of 00:20:54.660 --> 00:21:00.510 time you're wasting, right? HJKL is right 00:20:57.240 --> 00:21:04.020 on the home row. And, so, J moves down, K 00:21:00.510 --> 00:21:06.390 moves up, H moves left, and L moves right. 00:21:04.020 --> 00:21:08.940 And, this may seem a little unintuitive 00:21:06.390 --> 00:21:10.410 now; there was some historical reason for 00:21:08.940 --> 00:21:13.440 it, like, the keyboard the original vi 00:21:10.410 --> 00:21:14.910 developer used had the hjkl keys, like, 00:21:13.440 --> 00:21:17.040 labeled, and arranged in a way that made 00:21:14.910 --> 00:21:19.260 this more reasonable. But, this will very 00:21:17.040 --> 00:21:20.370 soon become muscle memory. So, this is the 00:21:19.260 --> 00:21:24.270 basic way you can move your cursor 00:21:20.370 --> 00:21:26.070 around while in normal mode. Now, what 00:21:24.270 --> 00:21:27.720 else can you do? Well, if we had to move 00:21:26.070 --> 00:21:29.820 around files like this, it'd be really 00:21:27.720 --> 00:21:31.590 slow. We don't want to have to 00:21:29.820 --> 00:21:33.210 hold down these keys, and like, wait for a 00:21:31.590 --> 00:21:34.350 long time for Vim to do its thing. And 00:21:33.210 --> 00:21:35.760 so, there are all these other, different 00:21:34.350 --> 00:21:36.650 key combinations for doing different 00:21:35.760 --> 00:21:38.120 movements. 00:21:36.650 --> 00:21:39.200 Also, by the way, this is all in the 00:21:38.120 --> 00:21:40.940 lecture notes, so you don't need to 00:21:39.200 --> 00:21:43.550 memorize every single key and its 00:21:40.940 --> 00:21:45.320 meaning right now. Just try to understand 00:21:43.550 --> 00:21:47.570 the overall idea that Vim's interface is 00:21:45.320 --> 00:21:50.000 a programming language. So, another thing 00:21:47.570 --> 00:21:52.820 you can do is press the W key. This moves 00:21:50.000 --> 00:21:54.620 the cursor forward by one word. And then, 00:21:52.820 --> 00:21:57.740 similarly, the "B" key moves the cursor 00:21:54.620 --> 00:21:59.360 backward by one word. So, this allows 00:21:57.740 --> 00:22:01.820 slightly more efficient movement within 00:21:59.360 --> 00:22:04.010 the line. There's also the "E" key for 00:22:01.820 --> 00:22:06.620 moving to the end of a word. I'm going to 00:22:04.010 --> 00:22:08.030 move this over a little bit. So, if I'm 00:22:06.620 --> 00:22:09.800 here, for example, and I press the "E" key 00:22:08.030 --> 00:22:12.850 it'll go to the end of this word, end of 00:22:09.800 --> 00:22:15.980 this word, end of the next word and so on. 00:22:12.850 --> 00:22:17.720 You can also move by whole lines, so zero 00:22:15.980 --> 00:22:19.760 moves to the beginning of a line, dollar 00:22:17.720 --> 00:22:22.640 sign moves to the end of a line, and the 00:22:19.760 --> 00:22:25.790 caret key moves to the first non-empty 00:22:22.640 --> 00:22:31.730 character on a line. So, let me find one 00:22:25.790 --> 00:22:33.590 of those, for example. So, here, my 00:22:31.730 --> 00:22:34.760 cursor's right here; if I press 0, my 00:22:33.590 --> 00:22:37.040 cursor goes to the beginning of the line, 00:22:34.760 --> 00:22:39.590 dollar sign, end of the current line; and 00:22:37.040 --> 00:22:41.270 if I press caret, where, like, on what 00:22:39.590 --> 00:22:44.840 character will the curser end up? Can 00:22:41.270 --> 00:22:47.870 anybody guess? So, caret goes to the first 00:22:44.840 --> 00:22:53.000 non-empty character on a line, kind of 00:22:47.870 --> 00:22:57.200 like Regex caret. Yeah, exactly! It goes 00:22:53.000 --> 00:22:59.780 to this dash. Let's talk about some more 00:22:57.200 --> 00:23:01.220 movement commands. There're ways to 00:22:59.780 --> 00:23:06.230 scroll up and down in a buffer, so 00:23:01.220 --> 00:23:08.510 control U goes up, and control D scrolls 00:23:06.230 --> 00:23:10.850 down. So, this is better than holding down 00:23:08.510 --> 00:23:13.190 the K or J keys, for example. This is a 00:23:10.850 --> 00:23:17.720 lot slower than moving by entire pages. 00:23:13.190 --> 00:23:19.970 Control D and control U. There's also 00:23:17.720 --> 00:23:22.400 ways to move by the entire buffer. So, 00:23:19.970 --> 00:23:26.420 capital "G" moves all the way down... "gg" 00:23:22.400 --> 00:23:28.490 moves all the way up. Some of these 00:23:26.420 --> 00:23:29.600 movement keys are mnemonics; so, they're 00:23:28.490 --> 00:23:31.400 like, a little bit easier to remember for 00:23:29.600 --> 00:23:33.440 that reason, right, like, "W" is word, "B" 00:23:31.400 --> 00:23:36.230 is beginning of word, E is end of word. Those 00:23:33.440 --> 00:23:38.030 all seem pretty logical. 0, caret and 00:23:36.230 --> 00:23:39.559 dollar, kind of inspired from Regex, so 00:23:38.030 --> 00:23:41.120 those make a little bit of sense. There's 00:23:39.559 --> 00:23:42.890 some other ones that, like, don't 00:23:41.120 --> 00:23:43.940 necessarily make way too much sense, but, 00:23:42.890 --> 00:23:46.310 there are only so many keys on your 00:23:43.940 --> 00:23:48.590 keyboard, so what are you going to do? For 00:23:46.310 --> 00:23:49.430 example, the "L" key moves your cursor to 00:23:48.590 --> 00:23:51.890 the lowest 00:23:49.430 --> 00:23:54.920 line that's shown on the screen. "L" for 00:23:51.890 --> 00:24:01.430 lowest makes sense, M for middle, and then H for 00:23:54.920 --> 00:24:02.660 highest, I guess. And, there's a whole 00:24:01.430 --> 00:24:04.250 bunch of other interesting movements 00:24:02.660 --> 00:24:05.330 like this. So, we're obviously not going 00:24:04.250 --> 00:24:07.070 to be able to cover all of them right 00:24:05.330 --> 00:24:08.690 now, but you'll be able to go through 00:24:07.070 --> 00:24:11.320 them in the Vim tutor exercise, which is 00:24:08.690 --> 00:24:15.790 exercise number one for this lecture. 00:24:11.320 --> 00:24:18.080 Some other ones I want to talk about now - 00:24:15.790 --> 00:24:19.640 maybe I'll talk about one more. There's 00:24:18.080 --> 00:24:21.440 another movement called "find". This is 00:24:19.640 --> 00:24:23.210 also kind of useful. Suppose I'm on this 00:24:21.440 --> 00:24:25.340 line, and I want to jump to the first 00:24:23.210 --> 00:24:27.260 character that equal's to... Like, I 00:24:25.340 --> 00:24:31.310 want to jump to the first "o". I can press 00:24:27.260 --> 00:24:33.860 "fo", and my cursor moves to the first 00:24:31.310 --> 00:24:35.210 "o". I've like, found "o". I can do fw and 00:24:33.860 --> 00:24:39.560 it'll move to the first "w", which I think 00:24:35.210 --> 00:24:40.880 is right here. fc: find the first C. I can 00:24:39.560 --> 00:24:44.510 also do the same thing, but backwards. If 00:24:40.880 --> 00:24:47.930 I do capital F, w, I can find the W that's 00:24:44.510 --> 00:24:49.760 before it. Capital F, s: find the s that's 00:24:47.930 --> 00:24:53.450 before that. And then, there's a variant 00:24:49.760 --> 00:24:56.690 of f, for find: t for to, so I can jump to 00:24:53.450 --> 00:24:58.520 O, and it jumps, like, until it's found o. 00:24:56.690 --> 00:25:03.110 But not on top of it, right before it. And 00:24:58.520 --> 00:25:04.820 capital T say, t, jumps backwards to the t 00:25:03.110 --> 00:25:07.190 except not all the way on top of it, one 00:25:04.820 --> 00:25:09.770 character before. And, so, you can already 00:25:07.190 --> 00:25:10.970 see that idea I talked about, of like, Vim 00:25:09.770 --> 00:25:13.160 is a programming language; you can, like, 00:25:10.970 --> 00:25:15.050 compose these commands. "F", and "T", are 00:25:13.160 --> 00:25:16.790 "find", and "to", and you can say "find" a 00:25:15.050 --> 00:25:20.180 particular character, or jump "to" a 00:25:16.790 --> 00:25:22.400 particular character. So, those are a 00:25:20.180 --> 00:25:26.660 couple of Vim movement commands. So, any 00:25:22.400 --> 00:25:32.050 questions about those so far? So this is - 00:25:26.660 --> 00:25:33.980 yeah, question? Or... no? Okay, cool. So, 00:25:32.050 --> 00:25:35.540 those are Vim movement commands. 00:25:33.980 --> 00:25:37.880 This is how you can navigate around a 00:25:35.540 --> 00:25:40.070 file quickly in normal mode. Now, another 00:25:37.880 --> 00:25:42.770 category of useful commands are editing 00:25:40.070 --> 00:25:44.480 commands. So, one we kind of already 00:25:42.770 --> 00:25:46.520 talked about is the "i" command 00:25:44.480 --> 00:25:48.500 for moving from "normal" mode to "insert" 00:25:46.520 --> 00:25:50.690 mode, where you can start just writing 00:25:48.500 --> 00:25:52.490 text. So, suppose I go up here and I press 00:25:50.690 --> 00:25:57.020 "i". Now I can type in whatever text I want 00:25:52.490 --> 00:25:58.370 "Hello world", "enter". Then, press 00:25:57.020 --> 00:26:00.890 "escape" to go back to normal mode, and 00:25:58.370 --> 00:26:01.640 I've made a change to my buffer. But, 00:26:00.890 --> 00:26:03.740 there are a whole bunch of other 00:26:01.640 --> 00:26:05.540 commands for making efficient edits 00:26:03.740 --> 00:26:07.760 that makes sense for when you're dealing 00:26:05.540 --> 00:26:09.410 with programming languages. So, one useful 00:26:07.760 --> 00:26:10.670 command that I accidentally used earlier, 00:26:09.410 --> 00:26:13.280 before teaching you about it, is the "o" 00:26:10.670 --> 00:26:16.130 command. So, suppose my cursor is, like, 00:26:13.280 --> 00:26:18.410 over here, and if I press "o", from normal 00:26:16.130 --> 00:26:19.490 mode, what it does, is it opens a new line 00:26:18.410 --> 00:26:22.040 below where my cursor is. 00:26:19.490 --> 00:26:23.420 That's what "o" stands for. And it, so it 00:26:22.040 --> 00:26:24.980 creates a new line, and it put me into 00:26:23.420 --> 00:26:27.290 insert mode. So, now I can start typing in 00:26:24.980 --> 00:26:29.600 some text, press escape, and go back to 00:26:27.290 --> 00:26:32.240 normal mode. And then, just like the "o" 00:26:29.600 --> 00:26:35.540 command, there's a capital "O" command, so 00:26:32.240 --> 00:26:37.850 if I'm here and I do capital "O", it puts 00:26:35.540 --> 00:26:41.690 me into insert mode above where I 00:26:37.850 --> 00:26:44.240 currently am. There's another Vim command 00:26:41.690 --> 00:26:47.690 for deleting things. So, suppose my cursor 00:26:44.240 --> 00:26:51.560 is, like, on top of this word right here, 00:26:47.690 --> 00:26:54.350 and I press the D key. "D" for delete. Oh, 00:26:51.560 --> 00:26:55.970 nothing happens; turns out that the D key 00:26:54.350 --> 00:26:57.860 needs to be combined with a movement 00:26:55.970 --> 00:26:59.630 command. So, remember we just talked about 00:26:57.860 --> 00:27:02.870 different movement commands, like hjkl, 00:26:59.630 --> 00:27:03.530 and, like, word, and backward word, and 00:27:02.870 --> 00:27:07.670 things like that. 00:27:03.530 --> 00:27:11.600 So, I press D. Whoops. I press D and I can 00:27:07.670 --> 00:27:13.970 press W, and it's deleted a word. So, let 00:27:11.600 --> 00:27:16.820 me undo that. Undoing in Vim is just u for 00:27:13.970 --> 00:27:19.940 undo. So, notice my cursor's right here. I 00:27:16.820 --> 00:27:21.770 do "dw": it's deleted a word. I can move 00:27:19.940 --> 00:27:25.100 around, and then delete another word. 00:27:21.770 --> 00:27:27.620 Suppose I'm - uh, keeps getting in the way 00:27:25.100 --> 00:27:29.420 Suppose I'm, like, somewhere in the middle 00:27:27.620 --> 00:27:31.130 of a word, and I want to delete to the end 00:27:29.420 --> 00:27:35.630 of a word. Any guesses for what 00:27:31.130 --> 00:27:39.320 combination of keys I'd use for that? "d" 00:27:35.630 --> 00:27:43.790 and what? de, exactly. Delete to the end of 00:27:39.320 --> 00:27:46.790 the word. Another useful editing command 00:27:43.790 --> 00:27:48.800 is the c command. c stands for change. So, 00:27:46.790 --> 00:27:50.840 change is really similar to delete, 00:27:48.800 --> 00:27:52.220 except change puts you in insert mode, 00:27:50.840 --> 00:27:54.500 because, like, I want to delete a thing, 00:27:52.220 --> 00:27:56.960 but change it to something else. So, if 00:27:54.500 --> 00:27:59.810 I'm here, and I do "ce", it's like, change 00:27:56.960 --> 00:28:00.950 to the end of the word. And, it gets rid 00:27:59.810 --> 00:28:02.630 of the contents until the end of the 00:28:00.950 --> 00:28:04.460 word, and notice it put me in insert mode. 00:28:02.630 --> 00:28:06.740 So now, whatever characters I type go 00:28:04.460 --> 00:28:11.270 into the buffer. If I press "escape", I go 00:28:06.740 --> 00:28:13.250 back into normal mode. And so, c and d are 00:28:11.270 --> 00:28:15.650 analogs: they both take motions as 00:28:13.250 --> 00:28:17.290 arguments. And, they will either delete 00:28:15.650 --> 00:28:20.950 that motion, or change 00:28:17.290 --> 00:28:24.370 that motion. So, for example, if you press 00:28:20.950 --> 00:28:25.990 the c key, there's also this pattern that, 00:28:24.370 --> 00:28:27.880 if you press a particular editing key 00:28:25.990 --> 00:28:30.400 twice, it'll have that effect on the 00:28:27.880 --> 00:28:32.980 given line. So, if I press "dd", that 00:28:30.400 --> 00:28:34.360 deletes the line. If I press "cc", that 00:28:32.980 --> 00:28:35.560 deletes the given line, but puts me in 00:28:34.360 --> 00:28:39.760 insert mode, so I can replace it with 00:28:35.560 --> 00:28:43.360 some other line. We'll cover a couple 00:28:39.760 --> 00:28:44.290 other, uh, editing commands, because then 00:28:43.360 --> 00:28:46.720 later we'll see how all these things 00:28:44.290 --> 00:28:48.700 interact together. So, another useful one 00:28:46.720 --> 00:28:50.290 is the x command. So, suppose my cursor is 00:28:48.700 --> 00:28:52.120 over some particular character. If I 00:28:50.290 --> 00:28:57.880 press "x", it just deletes that 00:28:52.120 --> 00:29:00.310 character. There's another command called 00:28:57.880 --> 00:29:02.260 r. If I'm over a particular character, and 00:29:00.310 --> 00:29:03.940 I press "r", it takes another character as 00:29:02.260 --> 00:29:05.440 an argument, and it replaces that 00:29:03.940 --> 00:29:12.550 particular character with some other 00:29:05.440 --> 00:29:14.110 character. And, I'll cover a couple more 00:29:12.550 --> 00:29:16.390 editing commands. So, I think one I 00:29:14.110 --> 00:29:17.980 talked about a moment ago - but, of course 00:29:16.390 --> 00:29:19.360 you can undo changes you've made in Vim. 00:29:17.980 --> 00:29:21.520 And the way you do that is by pressing 00:29:19.360 --> 00:29:23.230 "u" while you're in normal mode. So, u for 00:29:21.520 --> 00:29:24.850 undo is pretty easy to remember. So, I 00:29:23.230 --> 00:29:26.310 press "u" a whole bunch of times; it's 00:29:24.850 --> 00:29:28.750 undone all the changes I've made. And 00:29:26.310 --> 00:29:31.000 then, the opposite of undo is, of course, 00:29:28.750 --> 00:29:40.960 redo. And, the binding for that in Vim is 00:29:31.000 --> 00:29:42.310 control + R. All right, one other editing 00:29:40.960 --> 00:29:55.090 command I'm going to talk about is copy 00:29:42.310 --> 00:29:56.290 and paste because-oh yes, question? That's 00:29:55.090 --> 00:29:58.150 a - that's a great question! So, the 00:29:56.290 --> 00:29:59.500 question is, "Does 'undo' undo everything 00:29:58.150 --> 00:30:00.970 you've done since you've gone into 00:29:59.500 --> 00:30:02.380 insert mode, or just the last character?" 00:30:00.970 --> 00:30:03.280 It's - it's actually a little bit more 00:30:02.380 --> 00:30:05.860 complicated than that. 00:30:03.280 --> 00:30:07.540 "Undo" does, like, undoes the last change 00:30:05.860 --> 00:30:08.800 you've made. So, if you went into insert 00:30:07.540 --> 00:30:10.480 mode, and typed in some stuff, and went 00:30:08.800 --> 00:30:12.520 back into normal mode, and then press "u" 00:30:10.480 --> 00:30:14.560 for "undo", it'll undo all you've done in 00:30:12.520 --> 00:30:16.090 insert mode. But, if you've done some 00:30:14.560 --> 00:30:18.280 other type of editing command, like, say I 00:30:16.090 --> 00:30:20.140 press "x" to delete a character... If I do 00:30:18.280 --> 00:30:24.280 "u" for undo, it'll just undo that change 00:30:20.140 --> 00:30:26.440 that that editing command made. Now, does 00:30:24.280 --> 00:30:28.780 that answer the question? (Yeah) Great any 00:30:26.440 --> 00:30:32.780 other questions? 00:30:28.780 --> 00:30:35.480 Cool. So, I'll talk about copy and paste 00:30:32.780 --> 00:30:37.580 as well, because that's a popular one. The 00:30:35.480 --> 00:30:39.710 y command stands for copying, and the p 00:30:37.580 --> 00:30:41.810 command stands for pasting. y for "copy", 00:30:39.710 --> 00:30:43.370 because, yank. Like, that's the word they- 00:30:41.810 --> 00:30:46.310 that's the terminology that 00:30:43.370 --> 00:30:49.220 Vim uses for copying. And, these commands 00:30:46.310 --> 00:30:52.580 are- y also takes a motion as an argument. 00:30:49.220 --> 00:30:54.350 So if I do like, yy, it copies the current 00:30:52.580 --> 00:30:56.090 line. And, if I press "p" for "paste", 00:30:54.350 --> 00:30:57.260 notice that now these two lines are 00:30:56.090 --> 00:31:00.110 identical, because I've just pasted a 00:30:57.260 --> 00:31:02.330 line below. "u" for "undo". But if I do 00:31:00.110 --> 00:31:04.910 something like "yw", it's copied the word. 00:31:02.330 --> 00:31:05.450 And then I can do "p", and it just pasted 00:31:04.910 --> 00:31:08.930 that word again, 00:31:05.450 --> 00:31:10.700 right where my cursor was. One useful 00:31:08.930 --> 00:31:12.530 thing, especially in the context of copy 00:31:10.700 --> 00:31:14.150 and paste, is to be able to select a 00:31:12.530 --> 00:31:15.650 block of stuff and copy it, right? Like, 00:31:14.150 --> 00:31:16.940 this is probably how you used copy and 00:31:15.650 --> 00:31:19.220 paste in whatever editor you were using 00:31:16.940 --> 00:31:21.440 before. And so, that's where we get into 00:31:19.220 --> 00:31:23.210 the visual modes. So, these are another 00:31:21.440 --> 00:31:24.590 set of modes that are all related to 00:31:23.210 --> 00:31:26.030 each other, and that can be reached from 00:31:24.590 --> 00:31:28.790 normal mode, and they're used for 00:31:26.030 --> 00:31:31.040 selecting chunks of text. So, one mode is, 00:31:28.790 --> 00:31:33.140 just, regular visual mode. You can enter 00:31:31.040 --> 00:31:34.820 that by pressing v. And then, once you're 00:31:33.140 --> 00:31:36.650 in this mode, you can use most of the 00:31:34.820 --> 00:31:38.450 regular normal mode commands to move 00:31:36.650 --> 00:31:39.980 your pointer around. And it selects 00:31:38.450 --> 00:31:42.050 everything in between. So I can use, like, 00:31:39.980 --> 00:31:44.030 hjkl just to move the cursor, or I can 00:31:42.050 --> 00:31:45.890 use "w" to move by words, or different 00:31:44.030 --> 00:31:48.080 things like that, and it will select a 00:31:45.890 --> 00:31:49.490 block of text. And, once I've selected 00:31:48.080 --> 00:31:50.900 this block of text there are a whole bunch 00:31:49.490 --> 00:31:52.610 of different types of useful things you 00:31:50.900 --> 00:31:54.770 could do with it. One of the most popular 00:31:52.610 --> 00:31:57.320 things to do is copying this. So, once 00:31:54.770 --> 00:31:59.630 I've selected, I can do y to copy, and it 00:31:57.320 --> 00:32:01.280 puts me back into normal mode. And now, 00:31:59.630 --> 00:32:02.810 it's copied this to the - to the paste 00:32:01.280 --> 00:32:04.850 buffer. And then if I go somewhere else, 00:32:02.810 --> 00:32:07.670 and press "p", it pastes in that whole 00:32:04.850 --> 00:32:10.520 chunk of text I copied. And it's similar 00:32:07.670 --> 00:32:13.610 to visual mode, which selects kind of a 00:32:10.520 --> 00:32:15.560 contiguous stream of text. There's visual 00:32:13.610 --> 00:32:17.720 line mode: that can be reached by 00:32:15.560 --> 00:32:19.760 pressing capital V, and that selects 00:32:17.720 --> 00:32:21.470 whole lines at a time. And then there's 00:32:19.760 --> 00:32:23.150 VISUAL BLOCK mode, which can be selected 00:32:21.470 --> 00:32:24.890 by pressing "control" + " V", and that can 00:32:23.150 --> 00:32:26.240 select rectangular blocks of text. So 00:32:24.890 --> 00:32:31.670 this is something your old editor 00:32:26.240 --> 00:32:33.320 couldn't do. Alright, so, there's a lot 00:32:31.670 --> 00:32:35.120 more Vim editing commands to learn. 00:32:33.320 --> 00:32:36.710 There's lots of, like, really weird and 00:32:35.120 --> 00:32:38.420 fancy things. Like, for example, the tilde 00:32:36.710 --> 00:32:40.220 command changes the case of the 00:32:38.420 --> 00:32:41.690 character, or the selection that you've 00:32:40.220 --> 00:32:43.640 currently selected. So for example, 00:32:41.690 --> 00:32:45.620 I can take this, like, Visual Studio Code, 00:32:43.640 --> 00:32:48.260 and flip the case on the whole thing, by 00:32:45.620 --> 00:32:49.430 selecting it and pressing tilde. And, 00:32:48.260 --> 00:32:50.480 there's a whole bunch of other things 00:32:49.430 --> 00:32:52.160 like that; they get more and more 00:32:50.480 --> 00:32:54.050 esoteric as you go. So, we're not going to 00:32:52.160 --> 00:32:56.630 cover all of those, but you'll get to 00:32:54.050 --> 00:32:58.490 those in the exercises. So, those are Vim 00:32:56.630 --> 00:33:00.620 editing commands, and a lot of them can 00:32:58.490 --> 00:33:02.120 be composed with movement commands. So, 00:33:00.620 --> 00:33:09.260 any questions about either of those so 00:33:02.120 --> 00:33:12.680 far? Cool. So, moving along, another 00:33:09.260 --> 00:33:14.240 category of things -of commands- that are 00:33:12.680 --> 00:33:16.880 mostly relevant to normal mode are 00:33:14.240 --> 00:33:18.530 counts. So, you can give them a number, to 00:33:16.880 --> 00:33:22.100 do a particular thing, some number of 00:33:18.530 --> 00:33:25.430 times. So suppose my cursor is here, and I 00:33:22.100 --> 00:33:26.960 want to move down, like 1 2 3 4 lines. One 00:33:25.430 --> 00:33:29.390 way I can do that is by pressing "j" four 00:33:26.960 --> 00:33:32.570 times - go down four times. "kkkk" goes 00:33:29.390 --> 00:33:34.010 up four times. But, rather than pressing a 00:33:32.570 --> 00:33:37.430 particular key again, and again, I can use 00:33:34.010 --> 00:33:38.960 a count. So if I press "4", "j", it does j 00:33:37.430 --> 00:33:40.130 four times, right? 00:33:38.960 --> 00:33:42.290 Vim's interface is a programming 00:33:40.130 --> 00:33:45.890 language. If I do "4k", it moves up four 00:33:42.290 --> 00:33:47.600 times. If I am here, and I press "v" to go 00:33:45.890 --> 00:33:49.040 into visual mode... Okay so now I can move 00:33:47.600 --> 00:33:51.680 my cursor around, and select blocks of 00:33:49.040 --> 00:33:53.660 text. I can do, like, "eee" to select a 00:33:51.680 --> 00:33:56.600 couple of words, but, I could also go back 00:33:53.660 --> 00:33:59.720 here -v for visual mode- and press three e 00:33:56.600 --> 00:34:03.080 to select, like, three "ends of words" 00:33:59.720 --> 00:34:05.060 forward. And then of course these can also 00:34:03.080 --> 00:34:08.000 be combined with editing commands. So, 00:34:05.060 --> 00:34:10.910 like, suppose I want to delete seven 00:34:08.000 --> 00:34:13.970 words. I can do that by moving my cursor 00:34:10.910 --> 00:34:17.660 somewhere, and doing "7dw". Seven delete 00:34:13.970 --> 00:34:19.490 words. And so, this is particularly useful 00:34:17.660 --> 00:34:21.260 for things like, suppose my cursor is 00:34:19.490 --> 00:34:22.460 somewhere on the screen, and I'm looking 00:34:21.260 --> 00:34:24.020 somewhere else on the screen, or, I want 00:34:22.460 --> 00:34:26.240 my cursor to go to that particular line. 00:34:24.020 --> 00:34:28.400 Notice that I've set up relative line 00:34:26.240 --> 00:34:29.750 numbering on the left. So, wherever my 00:34:28.400 --> 00:34:31.580 cursor is, it shows the current line 00:34:29.750 --> 00:34:33.830 number, but everywhere else, it's just the 00:34:31.580 --> 00:34:35.870 offset from where I am. Now, suppose my 00:34:33.830 --> 00:34:38.480 cursor is here, but I want to move down 00:34:35.870 --> 00:34:40.160 to the like "Microsoft Word" down here, so 00:34:38.480 --> 00:34:41.810 that's eight lines down. So, what 00:34:40.160 --> 00:34:44.020 combination of keys would I press, to do 00:34:41.810 --> 00:34:45.560 that? Like, what's the most efficient way? 00:34:44.020 --> 00:34:47.810 Yeah, exactly! 00:34:45.560 --> 00:34:50.440 Let's try that out-8j-and my cursor moved 00:34:47.810 --> 00:34:50.440 down to this line. 00:34:51.270 --> 00:34:57.880 Okay. And then, one, final category of key 00:34:56.110 --> 00:34:59.920 meanings in Vim is something called 00:34:57.880 --> 00:35:02.200 modifiers. So we have, so far, movement, 00:34:59.920 --> 00:35:04.900 edits, counts, and, finally, we have 00:35:02.200 --> 00:35:06.520 modifiers. So, modifiers kind of change 00:35:04.900 --> 00:35:08.830 the meaning of a movement command a 00:35:06.520 --> 00:35:11.530 little bit. And, a couple modifiers that 00:35:08.830 --> 00:35:15.190 are especially useful are the "a" and "i" 00:35:11.530 --> 00:35:18.010 modifier. So, a stands for like around and 00:35:15.190 --> 00:35:19.900 "i" stands for inside. And, to see where 00:35:18.010 --> 00:35:21.760 this is really useful, I can move my 00:35:19.900 --> 00:35:22.480 cursor to somewhere like here, for 00:35:21.760 --> 00:35:24.670 example. 00:35:22.480 --> 00:35:26.320 So, hopefully, most of you are familiar 00:35:24.670 --> 00:35:28.240 with markdown syntax - and if not it 00:35:26.320 --> 00:35:30.490 doesn't matter too much. Uh, this is a 00:35:28.240 --> 00:35:31.780 link in markdown; it's a text rendered in 00:35:30.490 --> 00:35:33.610 square brackets, and then the link in 00:35:31.780 --> 00:35:35.500 parentheses. Suppose my cursor is inside 00:35:33.610 --> 00:35:38.350 here, and I want to change the text 00:35:35.500 --> 00:35:40.150 corresponding to this link. Well, one way 00:35:38.350 --> 00:35:43.480 I could do that is, like, move back here 00:35:40.150 --> 00:35:45.130 with b, and, like, 2dw, and then "i" to go 00:35:43.480 --> 00:35:46.450 into insert mode. That's one of the 00:35:45.130 --> 00:35:47.950 many ways I can make this change, and I 00:35:46.450 --> 00:35:51.070 can type in whatever other thing I want - 00:35:47.950 --> 00:35:53.410 u to undo, u to undo. Another way I could 00:35:51.070 --> 00:35:58.030 have done that is change two words - "c2w" 00:35:53.410 --> 00:35:59.950 - and then type in some other text. But, 00:35:58.030 --> 00:36:03.280 one final way I could do the same change 00:35:59.950 --> 00:36:05.380 is using the modifier commands to talk 00:36:03.280 --> 00:36:07.120 about how I want to interact with these 00:36:05.380 --> 00:36:09.490 different types of grouping things like 00:36:07.120 --> 00:36:12.070 parentheses and square brackets. So, one 00:36:09.490 --> 00:36:15.610 final way of doing this is change inside 00:36:12.070 --> 00:36:17.440 square brackets-"c" "i" "["-and that puts 00:36:15.610 --> 00:36:20.230 me into insert mode, after deleting the 00:36:17.440 --> 00:36:21.400 contents that are inside the brackets. So, 00:36:20.230 --> 00:36:22.690 do you see how we can take all these 00:36:21.400 --> 00:36:24.310 different ingredients, like we talked 00:36:22.690 --> 00:36:25.570 about "change", and we could combine that 00:36:24.310 --> 00:36:27.460 with different movement commands. We 00:36:25.570 --> 00:36:30.100 talked about inside, how it's a modifier. 00:36:27.460 --> 00:36:32.770 And then we talked about, uh... we didn't 00:36:30.100 --> 00:36:34.230 talk about parentheses. But, if your 00:36:32.770 --> 00:36:36.070 cursor is hovering over a different, uh, 00:36:34.230 --> 00:36:37.810 different types of grouping things like 00:36:36.070 --> 00:36:39.880 parentheses, or square brackets, you can 00:36:37.810 --> 00:36:40.990 press the percent movement key to jump 00:36:39.880 --> 00:36:45.340 back and forth between matching 00:36:40.990 --> 00:36:49.510 parentheses. If I go over here and I do d, 00:36:45.340 --> 00:36:52.480 i, (, I can delete the contents 00:36:49.510 --> 00:36:55.780 inside these parentheses. And so, those 00:36:52.480 --> 00:36:57.550 are Vim, uh, modifiers. I guess we talked 00:36:55.780 --> 00:37:00.310 about i, but we didn't talk about a. If I 00:36:57.550 --> 00:37:02.080 do "da(", it deletes a whole, 00:37:00.310 --> 00:37:04.460 like parenthesized group including the 00:37:02.080 --> 00:37:10.730 parentheses so I is inside 00:37:04.460 --> 00:37:11.839 is around or including all right so 00:37:10.730 --> 00:37:13.670 those are basically the different 00:37:11.839 --> 00:37:15.890 categories of things you can combine 00:37:13.670 --> 00:37:18.050 together, when interacting with Vim's 00:37:15.890 --> 00:37:20.330 interface. So, any questions about that or 00:37:18.050 --> 00:37:28.820 the overall idea of this interface being 00:37:20.330 --> 00:37:31.580 a programming language? Cool. So, let's do 00:37:28.820 --> 00:37:33.859 a quick demo, to kind of demonstrate the 00:37:31.580 --> 00:37:36.290 power of this editor. And, it will kind of 00:37:33.859 --> 00:37:38.240 help us see how this tool can work 00:37:36.290 --> 00:37:41.260 really fast and kind of match the speed 00:37:38.240 --> 00:37:43.760 at which we think. So, over here is a very 00:37:41.260 --> 00:37:44.780 broken "fizzbuzz" implementation that 00:37:43.760 --> 00:37:46.640 doesn't actually print anything. 00:37:44.780 --> 00:37:48.680 Uh, hopefully, most of you have heard of 00:37:46.640 --> 00:37:51.080 "fizzbuzz" - if not, I'll explain it super 00:37:48.680 --> 00:37:52.730 briefly. Uh, "fizzbuzz" is a programming 00:37:51.080 --> 00:37:54.290 exercise where you print the numbers 1 00:37:52.730 --> 00:37:56.540 through n, but when the number is 00:37:54.290 --> 00:37:58.700 divisible by 3, you print fizz - when it's 00:37:56.540 --> 00:38:00.859 divisible by 5, you print buzz. And, when 00:37:58.700 --> 00:38:02.839 it's divisible by both 3, and 5. you print 00:38:00.859 --> 00:38:05.089 fizzbuzz. And, if none of those apply, you 00:38:02.839 --> 00:38:09.290 just print the number. So, you should 00:38:05.089 --> 00:38:13.460 print like 1, 2, fizz, 4, buzz, and so on. 00:38:09.290 --> 00:38:16.550 But, if I run this program, it doesn't 00:38:13.460 --> 00:38:20.089 print anything here I have them on the 00:38:16.550 --> 00:38:21.530 left in just a terminal on the right ok 00:38:20.089 --> 00:38:23.750 so there's a bunch of issues with this 00:38:21.530 --> 00:38:26.470 one is that main is never called so 00:38:23.750 --> 00:38:29.450 let's start off with fixing that so 00:38:26.470 --> 00:38:31.960 here's how I would make this change and 00:38:29.450 --> 00:38:34.250 notice how few keystrokes this requires 00:38:31.960 --> 00:38:37.609 capital G means go to the bottom of the 00:38:34.250 --> 00:38:39.650 file o opens a new line below and now I 00:38:37.609 --> 00:38:45.380 can just type in stuff so I'm an insert 00:38:39.650 --> 00:38:47.210 mode okay so I've typed in whatever 00:38:45.380 --> 00:38:50.480 change I want to make escape to go back 00:38:47.210 --> 00:38:53.540 to normal mode if I do : W so command 00:38:50.480 --> 00:38:54.650 mode right let me go back here okay now 00:38:53.540 --> 00:38:56.690 at least my program prints something 00:38:54.650 --> 00:38:58.940 when I run it another issue with this 00:38:56.690 --> 00:39:02.750 program is that it starts at 0 instead 00:38:58.940 --> 00:39:05.030 of 1 so let's go fix that so I want to 00:39:02.750 --> 00:39:06.950 go over to this range whoops this range 00:39:05.030 --> 00:39:08.480 thing and it shouldn't be going from 0 00:39:06.950 --> 00:39:11.270 to limit it should be going from 1 to 00:39:08.480 --> 00:39:12.650 limit plus 1 1 command which I didn't 00:39:11.270 --> 00:39:16.060 show you about is how you search in vim 00:39:12.650 --> 00:39:16.060 so you press forward slash 00:39:17.010 --> 00:39:21.930 to close this and restart it if you 00:39:19.080 --> 00:39:24.840 press forward slash it starts search so 00:39:21.930 --> 00:39:26.220 if I type in range enter my cursor goes 00:39:24.840 --> 00:39:27.810 from wherever it was before to the first 00:39:26.220 --> 00:39:28.920 instance of range it found so it's a 00:39:27.810 --> 00:39:31.680 really efficient way of moving where I 00:39:28.920 --> 00:39:33.990 want to move WW to move forward two 00:39:31.680 --> 00:39:36.330 words I to go into insert mode add the 00:39:33.990 --> 00:39:38.310 one comma space escape I'm back in 00:39:36.330 --> 00:39:40.080 normal mode this is a very common 00:39:38.310 --> 00:39:41.850 pattern in vim you stay in normal mode 00:39:40.080 --> 00:39:43.260 you go somewhere you go into insert mode 00:39:41.850 --> 00:39:44.880 you make a tiny change and you jump 00:39:43.260 --> 00:39:45.900 right back to normal mode like normal 00:39:44.880 --> 00:39:48.810 mode is home and that's where you should 00:39:45.900 --> 00:39:51.030 be most of the time I also want to add a 00:39:48.810 --> 00:39:55.430 plus one so e to go to the end of this 00:39:51.030 --> 00:39:58.140 word a for a pend plus one escape 00:39:55.430 --> 00:40:00.810 alright fix that problem and other issue 00:39:58.140 --> 00:40:02.940 is that this program prints fizz for 00:40:00.810 --> 00:40:05.970 both divisible by three and five so 00:40:02.940 --> 00:40:07.920 let's fix that slash fizz searches for 00:40:05.970 --> 00:40:11.790 fizz been oppressed and it goes to the 00:40:07.920 --> 00:40:13.710 next match see I press E I quote changes 00:40:11.790 --> 00:40:15.660 what's inside the quote so it's deleted 00:40:13.710 --> 00:40:17.460 the fizz and put me in insert mode right 00:40:15.660 --> 00:40:18.510 in between those two quotes and I can 00:40:17.460 --> 00:40:23.460 type in whatever I want 00:40:18.510 --> 00:40:26.630 escape to go back to normal mode so 00:40:23.460 --> 00:40:28.890 great I've fixed that particular problem 00:40:26.630 --> 00:40:31.710 another problem with this program is 00:40:28.890 --> 00:40:37.710 that it prints fizz and Buzz on separate 00:40:31.710 --> 00:40:42.150 lines for multiples of 15 so let's let's 00:40:37.710 --> 00:40:42.870 go and fix that let me go down to this 00:40:42.150 --> 00:40:44.580 line here 00:40:42.870 --> 00:40:46.350 one way I can don't actually worry about 00:40:44.580 --> 00:40:47.430 like the actual contents of this program 00:40:46.350 --> 00:40:48.690 like this some stupid program that 00:40:47.430 --> 00:40:51.000 doesn't matter pay attention to what 00:40:48.690 --> 00:40:52.170 keys I'm pressing in vim that allow me 00:40:51.000 --> 00:40:54.960 to make changes to this program really 00:40:52.170 --> 00:40:56.790 efficiently so my cursor is on this line 00:40:54.960 --> 00:40:59.460 i press dollar to go to the end of this 00:40:56.790 --> 00:41:01.170 line i for insert mode okay and i'm 00:40:59.460 --> 00:41:03.330 typing some stuff escape to go back to 00:41:01.170 --> 00:41:07.050 normal mode now I want to make the same 00:41:03.330 --> 00:41:11.610 change the print below look at this JJ 00:41:07.050 --> 00:41:13.260 dot so what dot dozen vim is it repeats 00:41:11.610 --> 00:41:15.990 the previous editing command that was 00:41:13.260 --> 00:41:17.880 made and so this is a really nice way of 00:41:15.990 --> 00:41:19.890 doing repetitive tasks without typing 00:41:17.880 --> 00:41:21.630 the same thing over and over again so in 00:41:19.890 --> 00:41:24.630 that particular case that inserted comma 00:41:21.630 --> 00:41:27.110 end quote and so it applied the same 00:41:24.630 --> 00:41:29.580 thing on this line when I press dot and 00:41:27.110 --> 00:41:30.690 then when I guess one final part of this 00:41:29.580 --> 00:41:32.930 demo is 00:41:30.690 --> 00:41:34.620 we will fix the issue that this program 00:41:32.930 --> 00:41:35.670 maybe should take a command-line 00:41:34.620 --> 00:41:38.520 argument instead of having this 00:41:35.670 --> 00:41:40.440 hard-coded 10 down here so how do we do 00:41:38.520 --> 00:41:43.170 that I'll press GG to go to the top 00:41:40.440 --> 00:41:44.490 capital o so now I've opened a line 00:41:43.170 --> 00:41:47.220 above and I'm going to type in some text 00:41:44.490 --> 00:41:49.710 like imports this enter escape to go 00:41:47.220 --> 00:41:52.110 back to normal mode and then I want to 00:41:49.710 --> 00:41:54.870 go down to where this 10 is so slash 10 00:41:52.110 --> 00:41:57.540 makes me jump straight down there CI 00:41:54.870 --> 00:41:59.760 pren to edit what's inside the 00:41:57.540 --> 00:42:02.150 parentheses and now I can type in like 00:41:59.760 --> 00:42:07.080 whatever thing I need to type in here 00:42:02.150 --> 00:42:09.840 and then once I've done this my program 00:42:07.080 --> 00:42:10.920 does fizzbuzz correctly I think I missed 00:42:09.840 --> 00:42:12.390 one change I wanted to make but it 00:42:10.920 --> 00:42:14.540 doesn't matter this demonstrates that 00:42:12.390 --> 00:42:17.250 you can make lots of changes really fast 00:42:14.540 --> 00:42:23.400 so any questions about this demo or the 00:42:17.250 --> 00:42:27.960 overall idea we've been talking about ok 00:42:23.400 --> 00:42:29.550 so this will be covered Tuesday so the 00:42:27.960 --> 00:42:31.710 kind of outside environment I'm running 00:42:29.550 --> 00:42:33.630 vim on the left and my shell on the 00:42:31.710 --> 00:42:38.910 right and then this is team ox on the 00:42:33.630 --> 00:42:39.900 outside one variant of that question 00:42:38.910 --> 00:42:41.670 might be like how do you switch between 00:42:39.900 --> 00:42:42.840 different vim windows and you can see 00:42:41.670 --> 00:42:44.250 the lecture notes for that but there's a 00:42:42.840 --> 00:42:45.720 key binding for that so if you have the 00:42:44.250 --> 00:42:50.240 same window open or multiple things open 00:42:45.720 --> 00:42:50.240 there's a way of doing that question ah 00:42:50.840 --> 00:42:56.520 good question so delete takes a motion 00:42:54.570 --> 00:42:58.110 and then removes those contents but 00:42:56.520 --> 00:43:00.120 keeps you in normal mode so you can keep 00:42:58.110 --> 00:43:02.430 just moving around in a file what change 00:43:00.120 --> 00:43:03.900 does is very similar to delete it takes 00:43:02.430 --> 00:43:06.150 motions and treats them in the same way 00:43:03.900 --> 00:43:07.980 deletes those contents but then puts you 00:43:06.150 --> 00:43:11.280 in insert mode and so it saves you from 00:43:07.980 --> 00:43:13.290 typing one extra keystroke so if I'm 00:43:11.280 --> 00:43:16.380 here for example I want to delete main 00:43:13.290 --> 00:43:18.240 DW deletes a word but now if I press 00:43:16.380 --> 00:43:21.720 whatever key likes I press J it just 00:43:18.240 --> 00:43:23.490 moved me down if I undo that do cw4 00:43:21.720 --> 00:43:24.810 change a word now it's actually put me 00:43:23.490 --> 00:43:28.640 into insert mode and I can type in 00:43:24.810 --> 00:43:31.890 whatever I want it to insert so DWI is 00:43:28.640 --> 00:43:33.810 the same thing as CW but it saves a 00:43:31.890 --> 00:43:35.280 keystroke one thing we've linked in the 00:43:33.810 --> 00:43:37.140 resources is something called vim golf 00:43:35.280 --> 00:43:39.840 basically people have set up a game 00:43:37.140 --> 00:43:41.400 online where you can get an editing task 00:43:39.840 --> 00:43:43.590 and try to figure out the minimal number 00:43:41.400 --> 00:43:44.490 of keystrokes necessary to complete that 00:43:43.590 --> 00:43:46.020 editing 00:43:44.490 --> 00:43:47.340 it's actually really addictive so I'd 00:43:46.020 --> 00:43:52.680 only suggest going on their chest and 00:43:47.340 --> 00:44:00.450 script time I think I saw a hand for 00:43:52.680 --> 00:44:02.070 another question yeah uh period yeah one 00:44:00.450 --> 00:44:05.750 of the most useful of em commands good 00:44:02.070 --> 00:44:05.750 question any other questions 00:44:06.740 --> 00:44:13.260 cool so I think we have about five 00:44:10.800 --> 00:44:14.760 minutes left and I'm gonna briefly talk 00:44:13.260 --> 00:44:15.990 about a thing that's also covered in 00:44:14.760 --> 00:44:19.470 detail in the notes so make sure you 00:44:15.990 --> 00:44:22.349 look at the notes for this so vim is a 00:44:19.470 --> 00:44:24.420 programmers text editor and so of course 00:44:22.349 --> 00:44:25.740 it's highly programmable not only 00:44:24.420 --> 00:44:27.720 through its interface that's a 00:44:25.740 --> 00:44:29.099 programming language but also a couple 00:44:27.720 --> 00:44:31.050 of different ways there's lots of 00:44:29.099 --> 00:44:32.970 settings that you can tweak to match 00:44:31.050 --> 00:44:34.740 your preferences and you can also 00:44:32.970 --> 00:44:37.590 install plugins for them that do all 00:44:34.740 --> 00:44:40.380 sorts of useful stuff so the way vim is 00:44:37.590 --> 00:44:42.930 configured is through a file on disk 00:44:40.380 --> 00:44:45.480 called vim RC and you'll see this is a 00:44:42.930 --> 00:44:47.340 common pattern in a lot of shell based 00:44:45.480 --> 00:44:49.349 tools there'll be a plain text file that 00:44:47.340 --> 00:44:50.880 configures how the Tool Works and so if 00:44:49.349 --> 00:44:53.670 I edit this file and it may or may not 00:44:50.880 --> 00:44:56.310 exist on your machine yet but I've 00:44:53.670 --> 00:44:58.170 downloaded the we've created a kind of 00:44:56.310 --> 00:44:59.430 default vim RC for you and linked it on 00:44:58.170 --> 00:45:02.190 the course website so you can start with 00:44:59.430 --> 00:45:04.859 that one if I do vim tilde slash boom RC 00:45:02.190 --> 00:45:07.080 I can see here a bunch of comments and 00:45:04.859 --> 00:45:09.060 then particular commands like by default 00:45:07.080 --> 00:45:11.280 we want syntax highlighting on and we 00:45:09.060 --> 00:45:12.750 want line numbers if we didn't do some 00:45:11.280 --> 00:45:14.880 of these things like let me remove the 00:45:12.750 --> 00:45:16.500 stuff that sets line numbers if I remove 00:45:14.880 --> 00:45:17.790 those configurations and relaunch vim 00:45:16.500 --> 00:45:21.270 notice that I no longer have line 00:45:17.790 --> 00:45:23.099 numbers on the left but yeah so in short 00:45:21.270 --> 00:45:26.099 there's a lot of stuff you can configure 00:45:23.099 --> 00:45:28.589 with them we've given you a very basic 00:45:26.099 --> 00:45:29.880 configuration that tries to like remove 00:45:28.589 --> 00:45:32.160 some of the kind of weird behavior 00:45:29.880 --> 00:45:33.480 that's on by default in vim but we don't 00:45:32.160 --> 00:45:35.550 really try to enforce too many of our 00:45:33.480 --> 00:45:37.080 other opinions on you but of course like 00:45:35.550 --> 00:45:39.210 the three of us used them a lot and we 00:45:37.080 --> 00:45:41.310 have heavily customized VMR C's so we've 00:45:39.210 --> 00:45:42.480 linked to our personal configurations 00:45:41.310 --> 00:45:44.550 too if you want to take anything from 00:45:42.480 --> 00:45:46.050 that and also like thousands or like 00:45:44.550 --> 00:45:47.640 millions of people share their var C's 00:45:46.050 --> 00:45:48.450 on github so there's lots of places to 00:45:47.640 --> 00:45:49.920 look for inspiration 00:45:48.450 --> 00:45:53.040 there's also cool blog posts on this 00:45:49.920 --> 00:45:54.810 topic another thing you can do in vim is 00:45:53.040 --> 00:45:56.820 you can extend it with plugins that do 00:45:54.810 --> 00:45:58.080 all sorts of useful things this lets you 00:45:56.820 --> 00:45:59.730 do things like fuzzy file 00:45:58.080 --> 00:46:00.960 finding which a lot of text editors come 00:45:59.730 --> 00:46:02.790 with by default so you can get like a 00:46:00.960 --> 00:46:04.710 pop-up window you can type in a name of 00:46:02.790 --> 00:46:07.020 a file or approximately the name of a 00:46:04.710 --> 00:46:08.480 file and find it very quickly or there 00:46:07.020 --> 00:46:10.920 are things that show you like 00:46:08.480 --> 00:46:14.970 visualizations of undo history there are 00:46:10.920 --> 00:46:16.350 things that show you like file explorers 00:46:14.970 --> 00:46:18.360 things like that so we've linked to a 00:46:16.350 --> 00:46:20.520 couple of our favorite plugins on the 00:46:18.360 --> 00:46:22.230 course website and so I highly recommend 00:46:20.520 --> 00:46:23.340 becoming familiar with how to install a 00:46:22.230 --> 00:46:24.840 plug-in because it takes like three 00:46:23.340 --> 00:46:29.580 seconds and some of them are really cool 00:46:24.840 --> 00:46:32.130 and then finally the last topic I'll 00:46:29.580 --> 00:46:34.680 briefly mention before we finish today's 00:46:32.130 --> 00:46:37.170 lecture is vim mode and other programs 00:46:34.680 --> 00:46:38.760 so turns out that a lot of programmers 00:46:37.170 --> 00:46:40.650 we're really excited about VIMS 00:46:38.760 --> 00:46:42.780 interface and so they've implemented 00:46:40.650 --> 00:46:44.730 similar functionality and other tools 00:46:42.780 --> 00:46:47.730 for example like I've configured my 00:46:44.730 --> 00:46:49.530 Python repple to run in vim mode so I 00:46:47.730 --> 00:46:51.720 can like type in stuff here and if I 00:46:49.530 --> 00:46:53.250 press escape now I'm in normal mode in 00:46:51.720 --> 00:46:55.230 my Python repple and I can like move 00:46:53.250 --> 00:46:58.190 back and forth and like press X here 00:46:55.230 --> 00:47:01.530 delete a thing like CW change a word and 00:46:58.190 --> 00:47:03.210 do all those good things and it's not 00:47:01.530 --> 00:47:05.910 just the Python repple like I have my 00:47:03.210 --> 00:47:07.890 terminal behaving this way too so like I 00:47:05.910 --> 00:47:10.050 can type in whatever I want here and 00:47:07.890 --> 00:47:11.430 like escape and I'm in normal mode I can 00:47:10.050 --> 00:47:13.320 go here and like go into visual mode 00:47:11.430 --> 00:47:15.570 inside my terminal and like select 00:47:13.320 --> 00:47:19.680 blocks of text press tilde to change the 00:47:15.570 --> 00:47:22.080 case whatever so we've linked sir like 00:47:19.680 --> 00:47:25.800 how exactly you can enable vim mode for 00:47:22.080 --> 00:47:27.510 like bash z shell fish a lot of read 00:47:25.800 --> 00:47:28.710 line based programs like jupiter 00:47:27.510 --> 00:47:30.330 notebook a whole bunch of other things 00:47:28.710 --> 00:47:32.130 and if it's not another place you can 00:47:30.330 --> 00:47:33.840 probably find it by googling it because 00:47:32.130 --> 00:47:36.030 a lot of people like to have this sort 00:47:33.840 --> 00:47:37.380 of functionality and if you're really 00:47:36.030 --> 00:47:39.270 gonna like commit to learning them I 00:47:37.380 --> 00:47:41.490 think it's valuable to enable this sort 00:47:39.270 --> 00:47:43.080 of like vim emulation mode in every tool 00:47:41.490 --> 00:47:44.970 you use is like one or like make you 00:47:43.080 --> 00:47:46.800 learn the tool a lot better and to once 00:47:44.970 --> 00:47:47.970 you become good at vim like those skills 00:47:46.800 --> 00:47:53.130 will now transfer to all your other 00:47:47.970 --> 00:47:54.840 tools you use okay so I think that's it 00:47:53.130 --> 00:47:57.060 for our rapid introduction to them 00:47:54.840 --> 00:47:58.320 there's some other neat material that we 00:47:57.060 --> 00:47:59.790 weren't able to fit in today's lecture 00:47:58.320 --> 00:48:01.140 but it's in the lecture notes and then 00:47:59.790 --> 00:48:02.880 finally I highly recommend going through 00:48:01.140 --> 00:48:05.220 the exercises for today like at least 00:48:02.880 --> 00:48:07.440 for me personally I think spending time 00:48:05.220 --> 00:48:08.910 learning my text editor has been like 00:48:07.440 --> 00:48:10.140 the most beneficial thing out of like 00:48:08.910 --> 00:48:11.580 the kinds of things we're teaching in 00:48:10.140 --> 00:48:14.020 this class 00:48:11.580 --> 00:48:15.540 so yeah that's it for today's lecture 00:48:14.020 --> 00:48:17.530 and we'll see you tomorrow 00:48:15.540 --> 00:48:20.320 note that we've changed tomorrow's 00:48:17.530 --> 00:48:22.060 lecture to data wrangling Thursday and 00:48:20.320 --> 00:48:23.500 Tuesday lectures are now switched this 00:48:22.060 --> 00:48:25.000 is reflected on the course website in 00:48:23.500 --> 00:48:27.510 case anybody was going to come to one 00:48:25.000 --> 00:48:27.510 but not the other