back to indexLive coding 5
Chapters
0:0 Intro
2:10 Demo of text file manipulation using Vim
19:30 Creating Youtube video markers using Vim
25:55 Control + Z and fg for job management
27:57 split vim into multiple windows
28:30 Control + W to move between windows
28:40 Fixing the pre-run.sh script in Paperspace
32:48 Tips for learning Vim
41:9 Configuring Vim with a vimrc file
45:0 Using ctags to navigate a repository
00:00:02.640 |
I wanted to start with an issue which I can't remember. Mark or Matt, somebody pointed out that 00:00:19.200 |
their paper spaces were broken. Yeah, so anybody else who's been following along probably found 00:00:29.200 |
the same thing that they couldn't see their notebooks anymore, which is a bit of an issue. 00:00:38.000 |
So let me start an instance and we can see it create. 00:00:49.440 |
Oh, and I should share my screen, I suppose. Share screen, advanced, portion of screen. 00:01:29.120 |
Right, you guys can see my paper space window now. Cool. 00:01:35.600 |
All right, so I'll delete the workspace URL as we do. 00:01:55.040 |
Start. Okay, while that's starting up, I'll show you the other thing, which is 00:02:06.080 |
I mentioned the other day when we were talking about how do we create bash scripts. 00:02:16.320 |
For example, we created that bash script run. And I said, oh, you know, you can 00:02:22.160 |
use the Jupyter text editor if you want. But that's not how I would do it myself. 00:02:28.320 |
And I said, I would show you how I would do it myself. 00:02:31.040 |
And the way I would do it myself would be using a program called Vim. And Vim's a text editor, 00:02:42.960 |
which has a somewhat deserved reputation for being a bit obscure and challenging, 00:02:54.320 |
but also for being powerful. And all of those things are true. And it's kind of something I 00:02:59.760 |
wouldn't normally cover in a beginner's guide, but in a guide of the things that are going to 00:03:06.480 |
make your life better, I would certainly say, yeah, we do need to include it because it's actually 00:03:12.160 |
really quite terrific. But I don't want you to take my word for it. I wanted to 00:03:18.400 |
give you an example of how it works and why it's terrific. And so I thought a good example 00:03:28.400 |
was one of the folks who's been following along on these. Let me just try to make this bigger. 00:03:39.840 |
So I can see more faces. There we go. One of the folks who's been watching these courses, 00:03:44.880 |
Daniel has been kind enough to create these timelines, which I think are actually really 00:03:53.360 |
useful to remind yourself of what we covered. And they're useful for me because I can 00:04:06.560 |
use them to create timestamps in YouTube. So timestamps in YouTube, if I'll just show you an 00:04:14.240 |
example. You see how at the bottom here, those little chapter markers appear? 00:04:25.280 |
And to make them appear, you basically have to have times in a particular 00:04:35.520 |
format in the description. So I actually used Vim to turn Daniel's 00:04:41.360 |
thing into those timestamps. And I thought that might be just a good example 00:04:49.040 |
of how Vim's a bit different to your average editor. By the way, you might have noticed when 00:04:56.320 |
I selected this, I actually selected it quite quickly. And the reason I did that was with 00:05:01.520 |
the keyboard. Most things I use have good keyboard bindings and 00:05:06.640 |
the forums have good keyboard bindings. If you just hit question mark, you'll see them. 00:05:13.840 |
But they tend to be pretty consistent across programs. And you'll see that 00:05:20.080 |
J and K move the selection up and down. So if I press K, it moves the selection up. 00:05:30.720 |
And if I press J, it moves it down. And it kind of selects it. And then if I hit A, it edits it. 00:05:38.800 |
So now I can hit Apple A to select all, Apple C to copy. And you'll see that these keyboard 00:05:49.280 |
shortcuts have a lot of overlap with Vim. And so it's kind of nice that as you do more stuff with 00:05:55.280 |
the keyboard, you start to realize you don't have to relearn everything from scratch. 00:05:58.560 |
So I only just set up this Mac. And so I just installed Vim literally before 00:06:09.760 |
we started this session by typing "brew install vim." Because I'm trying to use a Mac a little bit. 00:06:18.080 |
And you need to set up Homebrew, which you can do from their website. And so when Vim opens, 00:06:27.840 |
this is what it looks like. It's going to be pre-installed. I assume this is now running. 00:06:34.640 |
It should be pre-installed on PaperSpace. So we should be able to use it straight away there as well. 00:06:45.920 |
It's taking a while to start for some reason. 00:06:56.400 |
>> Hello, I suppose it's sitting at the end of this session. 00:07:19.760 |
>> Yeah. That's okay. I don't have to watch it doing that. So while we're waiting, 00:07:31.280 |
I'm just going to go back to this one on my Mac. Okay. So here's Vim. So the first thing you'll 00:07:35.360 |
notice if you start Vim... So if you're on... Actually, let's talk about different options. 00:07:42.720 |
So on Linux, to run Vim, you would type "sudo apt..." Actually, let me do it in the Vim window 00:07:55.920 |
because otherwise it's going to autocomplete things in annoying ways. So in Linux to install Vim, 00:08:00.640 |
if you don't have it already, you would type "sudo apt install vim." On Mac, you would type 00:08:07.440 |
"brew install vim" after you've Googled for Mac, Brew, and installed Homebrew. Windows is going to 00:08:15.760 |
be the same as Linux, of course, because it is Linux and WSL. And so once it's installed, 00:08:25.120 |
you can just type Vim at the command line. And yeah, the window appears. And one thing you'll 00:08:33.520 |
notice is if you start typing, nothing happens. Text doesn't appear. So that seems like a problem, 00:08:38.960 |
a text editor where when you type, it doesn't put text on the screen. What on earth is going on? 00:08:43.600 |
Well, it's exactly actually the same as Jupyter Notebook, which is in Jupyter Notebook 00:08:48.960 |
when it appears. So if I create a notebook... 00:08:55.440 |
If I start typing, nothing happens either, right? And that's because in a notebook, you know, 00:09:03.120 |
you have to click inside a cell or press enter to go into edit mode. And then if I press escape, 00:09:09.360 |
I'm now in command mode and buttons do things rather than type. So for example, x cuts. 00:09:14.800 |
Vim is the same. It's modal. You're either in a mode where you're entering and editing text, 00:09:21.200 |
or you're in a command mode. So by default, just like in Jupyter, you're in a command mode. 00:09:26.320 |
So to go into edit mode, you press I. I stands for insert. So I can start if I press I, and it says 00:09:33.360 |
down at the bottom here, insert. So now in insert mode, now if I type, it types. And then if I want 00:09:40.080 |
to go back into command mode, I press escape. And if you don't see a mode, that means you're in 00:09:46.160 |
command mode. My arrows keys work as usual. And up and down work as usual. But one thing you might 00:09:56.560 |
notice is in command mode, the same buttons that we use in discord for up and down J and K also 00:10:02.080 |
work for going up and down. And it's not just J and K, it's actually all the letters in a row 00:10:07.680 |
there are all movement. So J and K go up and down, and L and H go left and right. It's totally fine 00:10:15.200 |
to use the arrow keys in your keyboard as well. And I would say honestly, probably for the first 00:10:20.480 |
couple of years of using VM, I always use the arrow keys. At some point, I started using 00:10:26.480 |
HJKL all the time instead. I guess my fingers noticed they were a bit closer and I didn't have 00:10:32.800 |
to move. And they decided that they liked doing that better. That's fine. So yeah, so you can move 00:10:40.960 |
around. And so at this point, we can run VIM, we can enter text. And then the one thing we don't 00:10:49.120 |
yet know how to do is to exit and save. So I almost never just type VIM. I almost always VIM 00:10:57.680 |
something. I want to VIM a file. So for example, let's say I wanted to VIM my .Z profile file, 00:11:07.440 |
which is one of the startup scripts that's run automatically when you start the terminal, 00:11:11.840 |
I would type VIM space .ZP tab. And there it is. Okay. And so this is something that 00:11:19.680 |
Bruce installed for me. So if I wanted to now edit this, maybe I wanted to put a comment above here, 00:11:24.960 |
I want to go into edit mode. And I'll show you like the slow way to do this. I could press 00:11:30.000 |
I for insert, I could press enter, I could press up, and I could start typing. So that'd be one way 00:11:37.360 |
so I could type my comment. Okay. And then press escape. Now, I want to show you a different way. 00:11:45.680 |
So I want to undo all that. So to undo the last thing you did, it's press U for undo, and U again. 00:11:52.160 |
I is not the only way to go into edit mode. There's lots of ways to go into edit mode, 00:11:57.840 |
to go into edit mode in different places. And one of them is to press O, which opens a new 00:12:04.960 |
line underneath. So that puts a new line underneath edit mode. And I want a new line above, 00:12:10.560 |
which is shift O. Shift O is a new line above. So it's pretty common that like a letter and 00:12:15.680 |
the capitalized version of the letter in VIM are kind of related versions of similar things. 00:12:25.280 |
So if I could put a comma here, shift O, auto added by homebrew installer, for example. Okay, 00:12:34.640 |
that's good. So now I want to save and close. So there's actually a third mode. There's not just 00:12:41.680 |
command mode and edit mode. There's also a mode they call EX mode, which is where you hit colon. 00:12:48.160 |
Now, when you hit colon, our cursor moves to the bottom, and you can enter various different 00:12:53.520 |
commands here. So one of the commands you can enter is W for right. And so that will save. 00:12:59.440 |
So by default, it saves it to whatever I loaded it as. So it saved it back to .Z profile. I could 00:13:06.640 |
save it to something else by going W, you know, backup profile or something. And that would save 00:13:13.360 |
it to that file name. Another useful EX command is Q, which quits. So colon Q quits. So if I now 00:13:26.400 |
decide I don't want to capitalize that, so I'll change that to a small a, 00:13:31.520 |
you can combine EX commands together. So to save and quit, you would type colon WQ right and quit. 00:13:42.560 |
And so when people say how do I exit VIM, you'll normally hear people say colon WQ. 00:13:49.040 |
That's why. And so by the way, what I just did there when I changed the big A to a small a, 00:13:55.520 |
I did that in a single button press. And that's because the tilde command changes case 00:14:04.080 |
and moves one to the right. Okay. So this is an example of, you know, when you've got the whole 00:14:10.240 |
keyboard available and shifted versions available, like there's a lot of things you can add, right? 00:14:16.560 |
And then hit you a few times. So if I wanted to change the case of the next 10 letters, 00:14:25.440 |
I could hit tilde 10 times. One, two, three, four, five, six, seven, eight, nine, ten. Okay. 00:14:32.480 |
But I wouldn't do that because in VIM, you can always say before you do a, call it a verb, 00:14:45.040 |
before you do like one of these, you know, letter command, single letter commands, you can type a 00:14:50.080 |
number, which is how many times do you want to do it? So if I type 10, so if I type 10 tilde, 00:14:56.800 |
it runs at 10 times. And so this is where things start getting interesting, right? Because every 00:15:06.720 |
single, you know, verb you can run in VIM, you can also say how many times to do it. 00:15:20.960 |
So for example, to delete a line, let me just create, oops, I've accidentally created far 00:15:28.320 |
too many lines. So to delete a line, you press DD. To delete five lines, you just press 5DD. 00:15:34.800 |
Okay. So it's important to remember like everything you can do. You can put a number after it. 00:15:44.640 |
But actually, it's even more powerful. Because after most commands, you can also say, you can 00:15:53.840 |
add something called a motion. A motion, for example, is right arrow moves right one, left arrow moves 00:16:00.320 |
down one. Shift G goes to the bottom of a file. Motions are things that move your cursor around. 00:16:06.560 |
Now, that doesn't sound very exciting. Unless I tell you after a command, you can type a motion 00:16:13.920 |
and the command will apply to the region that that motion covers. So for example, 00:16:18.960 |
I'm currently on line three. And if I press shift G, shift G is the motion to go to the end of the 00:16:24.160 |
file. D is the command to delete. So I can combine these together. D, shift G will delete to the end 00:16:32.080 |
of a file. D, shift G. Right? So that's pretty interesting. So GG takes you to the start of a 00:16:43.200 |
file. So to delete from here to the start of a file, D, G, G. Right? Or, you know, there's some 00:16:49.760 |
really interesting motions. For example, let's create two bits. Right? There's a concept of a 00:16:59.520 |
paragraph. So right curly bracket takes you to the end of a paragraph. It takes you to the end to the 00:17:05.120 |
next empty line. Right? Press it again. So that means if I want to delete everything from here 00:17:12.800 |
to the end of the paragraph, I would kiss D, right curly bracket. Okay? Or if I want to do that twice, 00:17:21.280 |
so delete from here to the end of the paragraph and also delete the next paragraph. Actually, 00:17:27.600 |
so let me show you. I want to copy this whole second bit and make a copy of it. So in VIM, 00:17:35.280 |
copying something, it's not control or command C, it's called yanking. So you press Y. So I want to 00:17:41.760 |
copy the next paragraph. So to copy this paragraph, I would press Y, right curly bracket. Okay? And 00:17:48.080 |
then to paste its P, and by default, it pastes it to the line underneath. To paste it to the line 00:17:54.080 |
above, you won't be surprised to hear it's shift P. So there's a copy. Now I want to go down to the 00:18:00.000 |
next paragraph and change that to third bit. So I'll press right curly bracket. And I now want to 00:18:07.840 |
delete this word and replace it with a different one. Deleting and replacing in VIM is called 00:18:13.360 |
changing. And that's C. And so like everything else, that can be combined with a motion. 00:18:18.960 |
So the motion to move to the next word is W. W goes to the next word, right? B goes back a word. 00:18:27.040 |
So to delete this word and let me start typing in a new one, it would be change word, C, W, third bit. 00:18:36.880 |
Okay? So if I want to delete from here to the end of the paragraph and the paragraph underneath, 00:18:44.240 |
I can just delete two paragraphs. So that would be 2D, right curly bracket. 00:18:50.000 |
Okay? So I would describe this as being highly compositional, right? You can kind of combine 00:18:59.680 |
numbers, motions, and commands together. And then we haven't even touched on 00:19:10.000 |
EX, right? So let's talk about EX. So I'm going to delete to the end of the file, 00:19:16.320 |
D, shift G, and delete this line, DD, and colon WQ to exit. So I mentioned that we wanted to 00:19:30.720 |
change this into something suitable to put in a YouTube video. So I press E, Apple A, Apple C, 00:19:40.480 |
cancel, and then I'll go VIM, I don't know, temporary, insert, Apple V, 00:19:51.040 |
GG. Okay. So here I've just pasted in this text, right? And I want to clean this up. So 00:20:01.360 |
I want to clean up the title. So I'll just press DD. And I want to do the same thing to the next 00:20:08.640 |
line. So to do the same thing you just did again, press dot. So that's going to delete the line 00:20:15.680 |
again. Now, where this gets interesting is that will redo the entire, like, number, command, 00:20:26.000 |
motion that you just did. So for example, if I press 4DW to delete four words, 4DW to delete 00:20:32.240 |
four words, and then press dot, that deletes another four words. And so that can get 00:20:38.560 |
pretty interesting. So for example, oh, okay, I'll show you a really cool example. 00:20:44.640 |
To search in VIM, you use slash, which is pretty common in a lot of different tools. And so if I 00:20:57.680 |
want to search, I don't know how many of you are familiar with regular expressions, 00:21:01.280 |
but you can put any regular expression here. If I wanted to search for the next timestamp that 00:21:06.080 |
Daniel created, I'd want to find a digit at the start of the line, right? So to go to the next 00:21:12.160 |
place where there's a digit at the start of the line, regular expressions use caret for start of 00:21:16.480 |
line and backslash D for digit. So this is going to search, there you go, and selects the next 00:21:22.400 |
digit at the start of the line. To search again, press N, N, right? So this is kind of cool, right? 00:21:31.040 |
Because what we could do now is if I want to delete everything up to the next digit at the 00:21:37.280 |
start of the line, well, slash is a motion. So I could type D slash caret backslash D, 00:21:45.520 |
and that searches for the next digit at the start of the line and deletes to it. 00:21:50.320 |
And so now I want to do it again, I press down, I'll just press dot. 00:21:56.880 |
So now I'm removing everything that's not a chapter header. So that's pretty interesting. 00:22:06.640 |
And then I could just delete to the end of the line with D shift G and delete the first line, 00:22:12.400 |
and I'm just about done, right? Of course, there's more than one way to do it. So let's 00:22:17.520 |
look at a few different ways. Another way we could do it is we could delete all the lines 00:22:25.680 |
that start with a hyphen. So there's a really useful EX command, which is the command 00:22:31.680 |
G. G is, I think it stands for grep, it searches for things, and it does an action 00:22:41.280 |
to anything, any line that it finds. So with any EX command, you first of all have to say, 00:22:48.640 |
what lines do you want to apply it to? And nearly always, you want to apply it to all lines, 00:22:54.000 |
which is percent. So generally speaking, for most EX commands, you'll start with percent. 00:22:59.760 |
And then you say, what command do you want to run? So I want to run G, which is I'm searching for 00:23:04.720 |
something. And then in EX, the different parts, the kind of the different parameters are generally 00:23:10.000 |
separated by slash. So the next thing is, what do you want to search for? I want to search for, 00:23:17.360 |
at the start of a line, a hyphen. Okay, and then another slash. Okay, what do you want to do? 00:23:22.880 |
And now I can put in any vim command. And so remember the command to delete in vim is D. 00:23:27.920 |
So this is going to search for anything with a hyphen at the start of the line and delete it. 00:23:33.840 |
There we go. Okay, so we could now do a similar thing to delete all the empty lines. 00:23:40.800 |
So to delete all the empty lines, I would do percent G slash. Okay, I want to do any time 00:23:46.160 |
you've got the start of a line, followed by zero or more spaces, followed by the end of a line. 00:23:53.120 |
That's an empty line. What do I want to do? Delete it. Okay, so. And then finally, I want to put a dash 00:24:03.200 |
between that first space and the thing after it. So that's a search and replace. So again, 00:24:09.920 |
we do colon percent to apply some ex command to the whole file. S for search and replace. 00:24:15.760 |
Then the slash to put in our different parameters. So first, what are we searching for? A space. 00:24:21.520 |
And then what are we replacing it with? Space hyphen space. 00:24:25.120 |
And then enter. And so this will just apply it by default to the first time it finds it. 00:24:31.680 |
Okay, so that's like an overview of like why VIM is cool. Like when people say VIM is cool, 00:24:40.880 |
they're not saying like, oh, you should use it because it's retro and interesting. 00:24:44.160 |
They're saying you should use it because it's powerful. And specifically, data scientists 00:24:48.720 |
should learn VIM because this interactive text munging is what we do with input data files and 00:24:56.800 |
output data files all the time. And something we can look at later if we want to is it's 00:25:03.120 |
super easy to create macros in VIM, which is where like literally it will just record 00:25:08.320 |
each button you press. And then you can just rerun that macro. So if you want to rerun the 00:25:13.520 |
same process on six different files, you just run the macro six times. Now, in this case, 00:25:22.800 |
I want to close without saving. So normally if I go colon Q and it says, no, you haven't 00:25:27.680 |
saved. So it's kind of careful to help you there. It says add exclamation mark to override. So I'll 00:25:32.560 |
do that Q exclamation mark. Okay. So we can use that in 00:25:49.280 |
in Jupyter. And so now we're going to fix the problem, which we talked about earlier, 00:26:01.280 |
which is how come our files disappeared? And to fix it, we need to edit prerun.sh. So if I type 00:26:12.880 |
vim prerun.sh. So here we've got this. And the reason that the files disappeared 00:26:19.920 |
is that at the start of our script, we typed CD, and that changed to our home directory. And we 00:26:27.600 |
never went back to where we were. And so that meant when it ran Jupyter, it ran it from our 00:26:31.680 |
home directory. This is actually currently showing the contents of our home directory. 00:26:35.680 |
Now, okay. I want to show you now how we know this by looking at run.sh. I want to switch to editing 00:26:43.760 |
run.sh without saving where I'm up to. And I want to show you a really neat thing in Linux that 00:26:51.600 |
lets you do this, which is control Z. Control Z does something really interesting. It stops the 00:27:00.000 |
process I was running, and it puts it in the background. So if I type jobs, I can see what's 00:27:04.640 |
running in the background. Vim is running in the background. I can do anything I like. And then 00:27:09.600 |
any time I want, I can type fg for foreground, and it comes back to where I was. So I can hit 00:27:17.600 |
control Z, and then I can type vim slash run.sh, which is actually what I was going to show you. 00:27:25.440 |
This is the thing that they run for us when we start an instance. And you can see here it runs 00:27:31.680 |
our script, and then it runs Jupyter. So our script was CDing to our home directory, and then 00:27:37.680 |
running Jupyter. And so Jupyter was in our home directory when it ran. So I go to colon queue to 00:27:44.080 |
exit that, and I'll go fg. There we go. Now, optional power user thing, which I use a lot, 00:27:54.000 |
is I would not -- that's not how personally I would have looked at the run.sh file. To look at the run.sh 00:28:01.600 |
file, what I would do in Vim was I would type colon sp, which stands for split, slash run.sh. 00:28:07.680 |
And as you can see, vim actually allows me to have multiple windows open at once. Okay. Kind of like 00:28:16.640 |
tmux, actually. tmux and vim has very similar functionality. And so then I can, you know, 00:28:22.240 |
scroll around here. And then in vim, instead of pressing control B and an arrow to go to a different 00:28:29.520 |
window, which is tmux, in vim it's control W. So except that control W closes a tab in Chrome, 00:28:38.320 |
so that's possibly not going to work. Okay. So there's a couple of ways we could solve this. 00:28:51.200 |
The probably the best way in a script is to use that trick I showed you last time, push D. 00:28:57.520 |
Tilde is our home directory. So that's the same as CD, changes to our home directory, 00:29:03.040 |
but it remembers where we were. And then pop D puts us back to where we were before. 00:29:08.480 |
So that should fix our problem. Okay. So this untitled.ipynb, we'll probably find that -- yeah, 00:29:21.520 |
see here it's in our -- here it is in our home directory, which was not what we intended. 00:29:34.320 |
And then we'll create another instance just to check that worked. 00:29:49.760 |
Okay. So while we're waiting for that to get started, does anybody have any 00:29:56.960 |
Hi, Jeremy. That is very good. That took me back to a previous life where I used to install 00:30:05.440 |
WordPerfect on Unix boxes and is working in a legal firm and said, what do you use for a 00:30:10.960 |
word processor today before I put on WordPerfect? And this person, you know, legal secretary said, 00:30:18.480 |
I use VI, which is like, vim is VI improved or VI improved. But it's just amazing, the power of it, 00:30:27.200 |
if you know everything it can do, it's a perfect word processor. 00:30:33.360 |
Yeah, it's great. I mean, I don't use it as a word processor, to be clear. I use, you know, 00:30:40.240 |
Microsoft Word or Google Docs as a word processor, because I think they're very good word processes. 00:30:45.200 |
But for a text editor, I use it a lot. If I've got, you know, a CSV file, I, you know, 00:30:51.520 |
want to do some quick cleanup to or something like that. Or a log file. I'll use it. Yeah, 00:31:01.280 |
pretty much any time I'm editing a quick script or something on a terminal. It's that's great. 00:31:10.400 |
You know, I will say Visual Studio Code is also excellent. And I wouldn't say like vim is 00:31:19.280 |
better or worse than Visual Studio Code. I use both of them. I use vim more often 00:31:24.720 |
than Visual Studio Code, but I do use both of them. And in fact, there is a button here, 00:31:28.800 |
I thought somewhere. I thought there was like an open Visual Studio Code button, 00:31:39.200 |
but maybe I'm imagining things. Or maybe it has to wait until it's finished opening the server. 00:31:50.240 |
Oh, here it is. Yeah. So there's an access remote kernel actually lets you connect Visual Studio 00:31:58.320 |
on your machine to the remote machine. So you can even use Visual Studio remotely. You can also 00:32:06.000 |
use it in WSL on Windows. Don't install Visual Studio Code into the Linux box, install it into 00:32:13.280 |
the Windows box, because it's got a WSL connector built in. So it uses it treats WSL, you know, 00:32:21.040 |
just as if it's a local Windows directory. You can also connect to any SSH instance using the 00:32:27.200 |
VS Code remote connector or yeah, this remote kernel thing. So, you know, you showed a lot 00:32:38.240 |
of keyboard shortcuts for them, right? So how can someone approach learning it? Because it feels a 00:32:44.320 |
bit intimidating when you're a beginner. Yeah. Yeah. So I mean, the trick with 00:32:51.520 |
learning something new is to try and like do it in small chunks, right? So don't expect to learn 00:32:59.440 |
all of them. Like, so at this point, I would say learn I just start inserting things, arrow keys 00:33:07.200 |
to move around, escape to go back to command mode, colon WQ to close and save. And at that point, 00:33:14.160 |
you can now use Vim to edit your shell scripts and stuff. And then like try and learn maybe one 00:33:22.880 |
or two new commands each day. So, you know, one useful one, you know, or emotion each day. So, 00:33:30.160 |
you know, W and B are useful to know to move forward and backward a word. 00:33:35.040 |
And yeah, there's a lot of Vim tutorials and things out there. So, for example, here's 00:33:42.800 |
OpenVim.com, which is going to introduce you by saying, oh, hit the enter key. Like, okay, 00:33:50.080 |
I'll hit the enter key. And so you could work through a tutorial like this. Yeah, it's 00:33:55.360 |
we all get intimidated, honestly, Kurian, when we see an expert working with something that we 00:34:04.880 |
don't know yet. And at first, it's like, wow, that's powerful. I wish I could do that. But my god, 00:34:10.240 |
you know, how would I ever get to that point? And the goal is not to be an expert at Vim. The goal 00:34:16.080 |
is to like be able to do Vim to like slowly do something that you want to be able to do. 00:34:21.040 |
And this is one of the things I, you know, really had to practice to myself in my late teens and 00:34:26.240 |
early 20s was to repeatedly put myself in a position where I was intentionally doing things 00:34:34.400 |
slowly by using a tool that I wanted to know. And I was pretty sure at some point would be useful, 00:34:40.000 |
but I didn't know well enough to do it faster than with other than some other tool. So I've always, 00:34:45.360 |
you know, since since like 16 been pretty good at using Lotus one, two, three and Excel spreadsheets. 00:34:51.760 |
And I tended to turn to them for everything. And then I wanted to learn SQL databases. So I kind 00:34:59.040 |
of forced myself to do things involving lists with databases for a while, even though I got 00:35:03.440 |
slower. And then I was like, okay, well, I'm going to stop using, you know, I got to start doing more 00:35:09.200 |
stuff with VBA macros and stop doing stuff manually. And again, it was kind of slower for a while. 00:35:14.080 |
And particularly like, you know, things like cleaning up that YouTube timestamp thing, 00:35:23.520 |
I could have done that manually, you know, and the first 10 times it would be faster to do it 00:35:29.840 |
manually. But don't do it manually, right? Because each time you do it manually, you know, you're 00:35:35.680 |
missing out on the opportunity to get better at the thing that's going to make you faster. And the 00:35:39.760 |
thing about practicing what you think might eventually be the fast way is that those fast 00:35:46.880 |
ways accumulate together in kind of these multiplicative ways. And so, you know, I've been 00:35:54.160 |
kind of using this approach of always trying to do things the way I suspect would be the fastest if 00:36:01.920 |
I was an expert at it. I've been doing that for like 30 years. And now, most people who watch me 00:36:08.560 |
work go, wow, you're very fast at doing stuff. You must be really smart. You know, I'm like, 00:36:13.680 |
no, I'm not really smart. Like, you should have seen me when I started. I was terrible. But now 00:36:17.600 |
these things have all accumulated, right? So, yeah. And if anybody finds, you know, good tutorials, 00:36:26.000 |
let me know. Honestly, it's been a long time since I've run a VIM tutorial. So I don't know 00:36:29.600 |
if this one's good or bad. This is the first one that came up in Google. But the VIM tutorial is 00:36:35.360 |
good. The best tutorial is on Linux in the terminal. If you just type in VIM tutorial 00:36:43.840 |
in the terminal, it should pop up a very nice tutorial. And I just wanted to say, Jeremy, 00:36:48.720 |
you know, a few minutes of speech that you just gave. It was absolutely wonderful and very, very 00:36:56.720 |
useful. Okay, yeah. So here is what happens if you type VIM tutor. And it will teach you exiting VIM. 00:37:03.920 |
So lesson one, moving the cursor, lesson two, exiting VIM. So that's a good start. Make sure 00:37:10.320 |
caps lock is not depressed. Impress J enough times so that lesson 1.1 fills the screen. J, 00:37:15.280 |
J, J, J, J. Okay. So because the VIM tutor is in VIM, it forces you to use VIM, which is good. 00:37:25.600 |
And the nice thing about this is, you know, move the cursor to the line below marked blah, blah, 00:37:30.400 |
blah. Here it is. Fix the errors. Move the cursor. Okay. So here's a useful one to know. X to cross 00:37:37.920 |
out something. So X. There we go. Thanks for that reminder. And the first time you do, you go 00:37:47.280 |
through the VIM tutor, it will feel overwhelming. It did to me only after, you know, on like third, 00:37:55.520 |
fourth try, does it start to make sense and are able to complete the entire thing. But also, 00:38:00.960 |
when I was learning the basics of VIM, I realized that it has a steep learning curve. 00:38:08.720 |
And I like to make things appealing, attractive, and simple for me. So I think Dimitri also mentioned 00:38:15.920 |
this in the chat here a second ago. There is a game called VIM Adventures, which is in your browser. 00:38:22.160 |
And it's another way that you can get exposed to them. That's how I learned it. So I would 00:38:30.640 |
dive into a call when I had my corporate job. And instead of, you know, whatever people do on calls, 00:38:39.680 |
which is just, I don't know, browser edit, I would do this. And that was my time. 00:38:49.680 |
Okay. Now I just tried pressing the arrow keys and VIM to see what the VIM Adventures, 00:38:54.720 |
and it says, don't use the arrow keys. I don't agree with that, by the way. A lot of people are 00:39:02.160 |
overly purists about, like, you have to do things the VIM way. So, okay, yes, you can use H, J, K, 00:39:10.320 |
and L. But seriously, it doesn't matter. Anyway. By the way, I see there's actually just a few 00:39:17.120 |
things in the Zoom chat. If you can, please say it out loud. There's a couple of reasons why. The 00:39:24.800 |
first is I really enjoy social interaction. Otherwise, I'm kind of sitting in my little 00:39:31.120 |
office, you know. And then the second is, of course, for the video, people can hear the 00:39:35.520 |
questions. Now, I know sometimes people just can't really talk because they're in some environment, 00:39:39.200 |
they can't do it. In that case, if you see somebody asking something in the chat, could you say, oh, 00:39:43.600 |
Mike M asked, what key are you pressing to undo, Jeremy? Rather than just answering it in the chat, 00:39:48.320 |
and that way I could, like, say that anyway. It looks like, so, yes, somebody said, how did you 00:39:54.320 |
do undo? So, the answer is you to undo. Can I suggest one last resource that is quite amazing 00:40:00.800 |
for VIM? It's the VIM book, editing at the speed of light. Editing, I don't know that one. Speed. 00:40:10.400 |
Speed of thought? Of thought, yes, yes, yes. Practical VIM. That's really, you know, 00:40:18.720 |
really well written. And there's a similar book for tmux. So, that's how I 00:40:26.080 |
start the books that made the really big difference for me. Now, let me tell you something not to do, 00:40:31.920 |
which is don't install lots of plugins. There's lots of plugins you can install. 00:40:37.600 |
And, you know, after using VIM for well over 20 years, I don't use any plugins at all. 00:40:45.600 |
It's not to say that there are none that are any use. But, like, they're not that useful, honestly. 00:40:58.080 |
And you can get lost in that whole, like, customizing things thing. And I just wanted 00:41:04.320 |
to make it clear to say, like, actually, out of the box VIM works extremely well. 00:41:09.520 |
Now, having said that, I customize it using a VMRC. So, an RC file in Linux and stuff is like, 00:41:19.440 |
you know, the normal kind of suffix for configuration files. And I do do some customization 00:41:26.640 |
of it. And I actually put all my configuration files in a GitHub repository. 00:41:37.920 |
Or .files. And you'll see here there's a VMRC. But it's only 99 lines. And there's things like, 00:41:50.080 |
for example, remember, I mentioned that you can jump to the next -- you can jump around Windows 00:41:54.800 |
by pressing Ctrl + W. I made it so you can also press backslash W and backslash up and backslash 00:42:04.960 |
down. So, just really minor things like that. And also some little things like -- oh, I guess 00:42:15.360 |
I do have some things installed. I don't use them anymore. Also some things like Python syntax 00:42:23.280 |
highlighting. And also, to be able to see things clearly when you've got a black background with 00:42:34.400 |
light text, you have to say set background equals dark. So, I don't know. Little things like that. 00:42:38.880 |
It comes with some nice defaults. You can just actually do this source command to get some nice 00:42:43.280 |
defaults. >> Quick question, please. Is this one public or private? 00:42:50.720 |
>> Everything of mine is public. >> Fantastic. Thank you. 00:42:54.160 |
>> Pretty much, I think. >> I have a question. What are your thoughts 00:42:59.600 |
about Visual Studio Code to edit files? >> They're great. I just talked about it. 00:43:05.600 |
Yeah, I said it's really good. Yep. I like Visual Studio Code. 00:43:09.760 |
>> Hi, Jeremy. Do you suggest using Vim key bindings for Jupyter and VS Code as well? 00:43:19.280 |
>> I don't. Because I find it's not about the key bindings. It's about the numbers and the 00:43:26.400 |
motions and the dots and the macros and like that stuff. And I don't find that there are other 00:43:33.280 |
editors that Vim as well as Vim do. So, when I use VS Code, I rather, you know, like fully inhabit 00:43:41.760 |
the VS Code world. And so, I use the normal VS Code key bindings and try to learn to use VS Code 00:43:47.200 |
as well as I can. So, yeah, I don't do that. Sometimes I've tried. And I'm always disappointed. 00:43:58.720 |
It's always like, yeah, it's not really. So, VS Code is great at being VS Code. And I would use that 00:44:09.040 |
for editing a big markdown file maybe. I don't use it much. But I guess if I was working with HTML 00:44:26.080 |
or CSS or something, I feel like the way it kind of handles those kind of file formats is really 00:44:31.520 |
nice. You can set up Vim to be really nice as well. But VS Code works a bit better, more out of 00:44:38.400 |
the box, I suppose. Yeah, and also for like navigating through a large repository, VS Code 00:44:46.000 |
can be a bit easier to use maybe. To ask whether you could use a fairly large project with 00:44:56.160 |
multiple files and whether it was doable via Vim. Yeah, it's definitely doable via Vim. 00:45:06.240 |
Yeah, I mean, we can take a look if you're interested. So, yeah, let's take a look. 00:45:11.040 |
Actually, it is useful to know how to do this. So, let's take, for example, the fast AI repo. 00:45:23.600 |
And so, let's do it all in paper space. Now, in paper space, 00:45:34.080 |
the /notebooks directory is persistent across machines. So, it probably makes sense to clone 00:45:46.000 |
this into the /notebooks directory. So, if I open up my terminal, so it's persistent within a machine 00:45:54.640 |
and it's persistent across restart. So, if I get clone here, it'll still be on this machine. 00:46:03.120 |
Next time I open it, because that's what /notebooks is. It's persistent across restarts on one machine. 00:46:08.800 |
Quick question, Jeremy. Yeah, actually, just before you do, I'm just going to cancel this and mention 00:46:15.440 |
some a little shortcut if that's okay. Did you see that was taking a really long time to clone? 00:46:20.560 |
The reason why is it's cloning every single version of fast AI that's ever existed. And since I don't 00:46:27.840 |
need every single version, if you type --depth1, it'll just give you the most recent version that 00:46:35.440 |
will save some time. So, yeah. So, go ahead. One of the other scripts you had, you were bringing 00:46:42.720 |
in /notebooks from storage, like storage somewhere. Is that a change? Yeah, I didn't really understand 00:46:51.440 |
how /notebooks persistence worked at that point. I hadn't spent enough time reading the docs. 00:46:56.880 |
Yeah. So, let's pretend that never happened. Okay. So, now that I've cloned this into /notebooks, 00:47:02.720 |
you can see it's appeared, right? Because this is where Jupyter is running from. 00:47:06.080 |
So, fast AI is what's called an nb-dev project, which means it's all developed in notebooks. So, 00:47:14.160 |
these are the notebooks which create fast AI. And then those all get exported as Python modules 00:47:23.280 |
into here. It's not a very interesting one. And as you can see, it says, "Oh, don't edit me. 00:47:33.120 |
Edit the notebook." That's fine. Okay. Now, if you want to explore through a code base, 00:47:45.120 |
it's really helpful to be able to, like, click on symbols and jump to their definitions and then 00:47:50.560 |
jump back again to kind of see how it all works. And so, you can actually do that on GitHub, 00:47:57.680 |
by the way. I don't know if you've noticed this, but it's quite neat. 00:48:11.680 |
Oh, it's interesting. It doesn't know how to find that one. It's not perfect. 00:48:19.520 |
That one's actually from PyTorch. That must be something it knows how to find. 00:48:31.360 |
Yeah, it's a popular model. Okay. Well, this is very strange. 00:48:37.840 |
In theory, it would. Finally, it found one. Okay. So, one problem with doing it in GitHub is it's 00:48:49.600 |
not particularly good at it. But, yeah. So, Vim can also do that, as can VS Code. And VS Code and Vim 00:49:00.000 |
both rely on something called C tags to do that. C tags is a project to create an index 00:49:28.240 |
I actually haven't bothered Googling it for like 20 years, so I didn't realize that 00:49:36.480 |
the thing I am used to using has been updated to this new thing. 00:49:43.360 |
I guess I should try using it. So, Ubuntu, install, universal C tags. 00:50:04.240 |
Actually, I tell you what I normally do for installing things is I like to find out if 00:50:08.880 |
there's a Conda installer. Because that makes life very easy. And there is. There's a universal C 00:50:15.360 |
tags. Okay. That's handy. Universal C tags. So, Mamba, install, universal C tags. 00:50:26.320 |
And this is one of the really cool things about Conda and Mamba is that I can install. 00:50:31.840 |
Ah, well, we don't have Mamba installed. That's fine. 00:50:39.840 |
Conda, install, minus C, defaults, minus C, Conda, forge, Mamba. 00:50:50.960 |
And so, in some future lesson, we'll talk about how to get these Conda and Mamba installed things 00:50:57.840 |
working persistently in paper space. There's probably some way to do it in snap as well. 00:51:10.960 |
I've never bothered checking. I don't know if anybody knows Ubuntu, snap, install, home directory. 00:51:16.560 |
I wonder if that's possible. This thing that Jeremy is going to show us, 00:51:23.840 |
this will give us superpowers. This is one of my favorite features of them and of 00:51:32.000 |
just jumping into them whenever I'm browsing through any code on the next, in a team like Spain. 00:51:39.200 |
And this is the way that professional developers interact with code. And it's not even all the 00:51:47.360 |
professional developers. So, like, you know, the ones who, like, limited view. Very few people 00:51:55.360 |
can navigate around code that quickly. And I think that really makes an enormous difference. 00:52:01.520 |
So, whenever Jeremy covers this, I become excited. And, you know. 00:52:06.480 |
That's great. We're lucky getting excited, Radek. 00:52:13.120 |
Okay. So, there's Mamba. So, we can never remember. Install. 00:52:20.960 |
Oh, I'll just press up here a couple of times. Universal C tags. 00:52:25.840 |
Oh, and we don't. Okay. So, we're not using Mamba Forge here. We should probably, I might 00:52:32.880 |
ask paper space if they can switch to using Mamba Forge so we don't have to worry about 00:52:36.880 |
this in the future. But for now, we'll have to put, it's from the Conda Forge channel. 00:52:42.240 |
Because the one that they've got installed does not use Conda Forge by default. 00:52:50.080 |
I might also talk to them about making it so that Python 3.9 is the default, 00:53:09.120 |
since it's still using 3.7, as we saw last time. 00:53:12.720 |
All right. So, if we CD into the first AI directory, there's a bunch of Python code we 00:53:28.560 |
want to look through. So, if you type C tags, that's the program that creates the index that 00:53:36.640 |
we want. And to run it recursively on the current folder, most things in Linux and stuff for capital 00:53:45.280 |
R for recursive and then dot means the current folder. So, that's indexed the current folder 00:53:52.000 |
and it's created. I expected it to create a file called C tags. I wonder if it's changed how this 00:54:03.360 |
works. Sorry, it's created a file called tags. So, it's created this file here called tags. 00:54:10.400 |
And if you look at it, you're basically, it's just a whole list of like symbols that it found in my 00:54:16.480 |
code and regexes to find where they are and what file it came from. You don't ever have to look at 00:54:21.360 |
that. The key thing to know is now we can jump straight to a tag. So, for example, if we want to 00:54:29.200 |
open up the array mask, whatever file defines array mask and put it in the right place, I can type 00:54:38.560 |
vim minus t for vim jump to a tag and type array mask and that will jump straight to the definition. 00:54:46.080 |
Okay. So, that's one way to do it. Another way to do it would be, let's say we were looking 00:54:53.040 |
at something else like layers.py, is you can type tag jump and then type ar tab and then it'll list 00:55:06.560 |
all the things that match and then I can hit enter and that will jump to that tag. 00:55:12.640 |
Another thing that you can do is you can notice, for example, this is inheriting from array image 00:55:22.640 |
base to jump to the definition of array image base. It's control right square bracket and so 00:55:30.720 |
when I hit that, it jumps to that definition and then to go back to the previous tag, it's control 00:55:36.080 |
t for tag. Okay. So, they're the key ways to jump around. Okay. So, for example, if we wanted to find 00:55:44.960 |
out some tabular class, I could go tab, tag jump, now start typing tabular and hit tab and here's 00:55:51.280 |
my various tabular classes. Go to tabular colab. Okay. So, tabular colab is defined in two places. 00:56:00.240 |
Now, that's annoying. One is it's in an ipy check points, which is the backups. So, this is where 00:56:07.360 |
you would actually create a c tags config file telling it to ignore anything inside ipy'd nb 00:56:15.280 |
check points because you never want to go to the backup version. So, for now, it's confused about 00:56:19.040 |
which one I want. So, I'll hit two to go to the non-confusing one and there you go. 00:56:24.160 |
Any other tricks you know with tags, Radik? >> Yeah. Just wanted to mention one and this is 00:56:39.120 |
what I did only once or twice because I'm always too lazy to set it up. But there is some way, 00:56:46.400 |
like with the fastai code here. So, you know that it's using PyTorch a lot. And sometimes you would 00:56:55.600 |
be editing a fastai file, but you would like to jump to the definition of some functionality 00:57:02.640 |
in the PyTorch code base. >> Oh, yes. That's a good one. 00:57:06.880 |
>> That's very helpful, especially for, you know, if you're just starting with PyTorch, 00:57:14.320 |
starting out, it's so much nicer than using their documentation on their website, which is slow and, 00:57:21.840 |
you know, you have to still search for it. But, yeah. 00:57:24.960 |
>> Yeah. So, you know, maybe in the future we can try setting that up as well. So, yeah, 00:57:30.800 |
you can set it up so that these tag jumps can jump into the PyTorch source code as well as the fastai 00:57:38.000 |
source code. I'll just show you one more trick, which is if I wanted to look up to find out how 00:57:42.080 |
data loaders worked, but I want to be able to see Colab data loaders at the same time, then 00:57:47.360 |
hitting write square bracket isn't quite ideal because I've now lost what I was looking at. 00:57:54.160 |
So, instead, if you type s tag, that means split tag, and I can start typing data loaders, 00:58:04.160 |
then that will split the window and jump to the tag so I can now see the two things that I'm doing. 00:58:12.560 |
Which I find handy. Anyway, there's a lot more stuff you can do with this, 00:58:16.240 |
but hopefully you've got a sense of, like, yeah, this seems worth investing time in because 00:58:22.000 |
here are some things that I didn't know how to do before and might be helpful. 00:58:25.680 |
>> Just on the split again, Jeremy, my tab closed down when I pressed command W. 00:58:35.040 |
>> To move around. How did you -- how would you do that within the Chrome browser again? 00:58:44.160 |
>> On a Mac it's fine because control and command are different, so you can just control W does work. 00:58:53.840 |
>> On the Mac. On Windows, if you use my .files, maybe we can, in some future one, 00:59:02.480 |
we'll learn about my .files, but in my .files I set up, and so if you make this your Vmrc, 00:59:09.600 |
then basically you can hit backslash up and backslash down to go up and down a split. 00:59:14.560 |
Because I think this C W -- this means control W will be sent to Vm rather than the browser, 00:59:23.120 |
so I think that should work fine. Great. All right. 00:59:37.840 |
Tell us if you find any cool tricks on the forum. And I'll see you next time.