Back to Index

Live 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

Transcript

All right, I will start recording. I wanted to start with an issue which I can't remember. Mark or Matt, somebody pointed out that their paper spaces were broken. Yeah, so anybody else who's been following along probably found the same thing that they couldn't see their notebooks anymore, which is a bit of an issue.

So let me start an instance and we can see it create. Oh, and I should share my screen, I suppose. Share screen, advanced, portion of screen. Okay. Let's go there. And. Right, you guys can see my paper space window now. Cool. All right, so I'll delete the workspace URL as we do.

Start. Okay, while that's starting up, I'll show you the other thing, which is I mentioned the other day when we were talking about how do we create bash scripts. For example, we created that bash script run. And I said, oh, you know, you can use the Jupyter text editor if you want.

But that's not how I would do it myself. And I said, I would show you how I would do it myself. And the way I would do it myself would be using a program called Vim. And Vim's a text editor, which has a somewhat deserved reputation for being a bit obscure and challenging, but also for being powerful.

And all of those things are true. And it's kind of something I wouldn't normally cover in a beginner's guide, but in a guide of the things that are going to make your life better, I would certainly say, yeah, we do need to include it because it's actually really quite terrific.

But I don't want you to take my word for it. I wanted to give you an example of how it works and why it's terrific. And so I thought a good example was one of the folks who's been following along on these. Let me just try to make this bigger.

So I can see more faces. There we go. One of the folks who's been watching these courses, Daniel has been kind enough to create these timelines, which I think are actually really useful to remind yourself of what we covered. And they're useful for me because I can use them to create timestamps in YouTube.

So timestamps in YouTube, if I'll just show you an example. You see how at the bottom here, those little chapter markers appear? And to make them appear, you basically have to have times in a particular format in the description. So I actually used Vim to turn Daniel's thing into those timestamps.

And I thought that might be just a good example of how Vim's a bit different to your average editor. By the way, you might have noticed when I selected this, I actually selected it quite quickly. And the reason I did that was with the keyboard. Most things I use have good keyboard bindings and the forums have good keyboard bindings.

If you just hit question mark, you'll see them. But they tend to be pretty consistent across programs. And you'll see that J and K move the selection up and down. So if I press K, it moves the selection up. And if I press J, it moves it down. And it kind of selects it.

And then if I hit A, it edits it. So now I can hit Apple A to select all, Apple C to copy. And you'll see that these keyboard shortcuts have a lot of overlap with Vim. And so it's kind of nice that as you do more stuff with the keyboard, you start to realize you don't have to relearn everything from scratch.

So I only just set up this Mac. And so I just installed Vim literally before we started this session by typing "brew install vim." Because I'm trying to use a Mac a little bit. And you need to set up Homebrew, which you can do from their website. And so when Vim opens, this is what it looks like.

It's going to be pre-installed. I assume this is now running. It should be pre-installed on PaperSpace. So we should be able to use it straight away there as well. It's taking a while to start for some reason. >> Hello, I suppose it's sitting at the end of this session.

>> It's taking a while for me to... >> Yeah. That's okay. I don't have to watch it doing that. So while we're waiting, I'm just going to go back to this one on my Mac. Okay. So here's Vim. So the first thing you'll notice if you start Vim... So if you're on...

Actually, let's talk about different options. So on Linux, to run Vim, you would type "sudo apt..." Actually, let me do it in the Vim window because otherwise it's going to autocomplete things in annoying ways. So in Linux to install Vim, if you don't have it already, you would type "sudo apt install vim." On Mac, you would type "brew install vim" after you've Googled for Mac, Brew, and installed Homebrew.

Windows is going to be the same as Linux, of course, because it is Linux and WSL. And so once it's installed, you can just type Vim at the command line. And yeah, the window appears. And one thing you'll notice is if you start typing, nothing happens. Text doesn't appear.

So that seems like a problem, a text editor where when you type, it doesn't put text on the screen. What on earth is going on? Well, it's exactly actually the same as Jupyter Notebook, which is in Jupyter Notebook when it appears. So if I create a notebook... If I start typing, nothing happens either, right?

And that's because in a notebook, you know, you have to click inside a cell or press enter to go into edit mode. And then if I press escape, I'm now in command mode and buttons do things rather than type. So for example, x cuts. Vim is the same. It's modal.

You're either in a mode where you're entering and editing text, or you're in a command mode. So by default, just like in Jupyter, you're in a command mode. So to go into edit mode, you press I. I stands for insert. So I can start if I press I, and it says down at the bottom here, insert.

So now in insert mode, now if I type, it types. And then if I want to go back into command mode, I press escape. And if you don't see a mode, that means you're in command mode. My arrows keys work as usual. And up and down work as usual.

But one thing you might notice is in command mode, the same buttons that we use in discord for up and down J and K also work for going up and down. And it's not just J and K, it's actually all the letters in a row there are all movement.

So J and K go up and down, and L and H go left and right. It's totally fine to use the arrow keys in your keyboard as well. And I would say honestly, probably for the first couple of years of using VM, I always use the arrow keys. At some point, I started using HJKL all the time instead.

I guess my fingers noticed they were a bit closer and I didn't have to move. And they decided that they liked doing that better. That's fine. So yeah, so you can move around. And so at this point, we can run VIM, we can enter text. And then the one thing we don't yet know how to do is to exit and save.

So I almost never just type VIM. I almost always VIM something. I want to VIM a file. So for example, let's say I wanted to VIM my .Z profile file, which is one of the startup scripts that's run automatically when you start the terminal, I would type VIM space .ZP tab.

And there it is. Okay. And so this is something that Bruce installed for me. So if I wanted to now edit this, maybe I wanted to put a comment above here, I want to go into edit mode. And I'll show you like the slow way to do this. I could press I for insert, I could press enter, I could press up, and I could start typing.

So that'd be one way so I could type my comment. Okay. And then press escape. Now, I want to show you a different way. So I want to undo all that. So to undo the last thing you did, it's press U for undo, and U again. I is not the only way to go into edit mode.

There's lots of ways to go into edit mode, to go into edit mode in different places. And one of them is to press O, which opens a new line underneath. So that puts a new line underneath edit mode. And I want a new line above, which is shift O.

Shift O is a new line above. So it's pretty common that like a letter and the capitalized version of the letter in VIM are kind of related versions of similar things. So if I could put a comma here, shift O, auto added by homebrew installer, for example. Okay, that's good.

So now I want to save and close. So there's actually a third mode. There's not just command mode and edit mode. There's also a mode they call EX mode, which is where you hit colon. Now, when you hit colon, our cursor moves to the bottom, and you can enter various different commands here.

So one of the commands you can enter is W for right. And so that will save. So by default, it saves it to whatever I loaded it as. So it saved it back to .Z profile. I could save it to something else by going W, you know, backup profile or something.

And that would save it to that file name. Another useful EX command is Q, which quits. So colon Q quits. So if I now decide I don't want to capitalize that, so I'll change that to a small a, you can combine EX commands together. So to save and quit, you would type colon WQ right and quit.

And so when people say how do I exit VIM, you'll normally hear people say colon WQ. That's why. And so by the way, what I just did there when I changed the big A to a small a, I did that in a single button press. And that's because the tilde command changes case and moves one to the right.

Okay. So this is an example of, you know, when you've got the whole keyboard available and shifted versions available, like there's a lot of things you can add, right? And then hit you a few times. So if I wanted to change the case of the next 10 letters, I could hit tilde 10 times.

One, two, three, four, five, six, seven, eight, nine, ten. Okay. But I wouldn't do that because in VIM, you can always say before you do a, call it a verb, before you do like one of these, you know, letter command, single letter commands, you can type a number, which is how many times do you want to do it?

So if I type 10, so if I type 10 tilde, it runs at 10 times. And so this is where things start getting interesting, right? Because every single, you know, verb you can run in VIM, you can also say how many times to do it. So for example, to delete a line, let me just create, oops, I've accidentally created far too many lines.

So to delete a line, you press DD. To delete five lines, you just press 5DD. Okay. So it's important to remember like everything you can do. You can put a number after it. But actually, it's even more powerful. Because after most commands, you can also say, you can add something called a motion.

A motion, for example, is right arrow moves right one, left arrow moves down one. Shift G goes to the bottom of a file. Motions are things that move your cursor around. Now, that doesn't sound very exciting. Unless I tell you after a command, you can type a motion and the command will apply to the region that that motion covers.

So for example, I'm currently on line three. And if I press shift G, shift G is the motion to go to the end of the file. D is the command to delete. So I can combine these together. D, shift G will delete to the end of a file. D, shift G.

Right? So that's pretty interesting. So GG takes you to the start of a file. So to delete from here to the start of a file, D, G, G. Right? Or, you know, there's some really interesting motions. For example, let's create two bits. Right? There's a concept of a paragraph.

So right curly bracket takes you to the end of a paragraph. It takes you to the end to the next empty line. Right? Press it again. So that means if I want to delete everything from here to the end of the paragraph, I would kiss D, right curly bracket.

Okay? Or if I want to do that twice, so delete from here to the end of the paragraph and also delete the next paragraph. Actually, so let me show you. I want to copy this whole second bit and make a copy of it. So in VIM, copying something, it's not control or command C, it's called yanking.

So you press Y. So I want to copy the next paragraph. So to copy this paragraph, I would press Y, right curly bracket. Okay? And then to paste its P, and by default, it pastes it to the line underneath. To paste it to the line 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 next paragraph and change that to third bit. So I'll press right curly bracket. And I now want to delete this word and replace it with a different one. Deleting and replacing in VIM is called changing. And that's C.

And so like everything else, that can be combined with a motion. So the motion to move to the next word is W. W goes to the next word, right? B goes back a word. So to delete this word and let me start typing in a new one, it would be change word, C, W, third bit.

Okay? So if I want to delete from here to the end of the paragraph and the paragraph underneath, I can just delete two paragraphs. So that would be 2D, right curly bracket. Okay? So I would describe this as being highly compositional, right? You can kind of combine numbers, motions, and commands together.

And then we haven't even touched on EX, right? So let's talk about EX. So I'm going to delete to the end of the file, D, shift G, and delete this line, DD, and colon WQ to exit. So I mentioned that we wanted to change this into something suitable to put in a YouTube video.

So I press E, Apple A, Apple C, cancel, and then I'll go VIM, I don't know, temporary, insert, Apple V, GG. Okay. So here I've just pasted in this text, right? And I want to clean this up. So I want to clean up the title. So I'll just press DD.

And I want to do the same thing to the next line. So to do the same thing you just did again, press dot. So that's going to delete the line again. Now, where this gets interesting is that will redo the entire, like, number, command, motion that you just did.

So for example, if I press 4DW to delete four words, 4DW to delete four words, and then press dot, that deletes another four words. And so that can get pretty interesting. So for example, oh, okay, I'll show you a really cool example. To search in VIM, you use slash, which is pretty common in a lot of different tools.

And so if I want to search, I don't know how many of you are familiar with regular expressions, but you can put any regular expression here. If I wanted to search for the next timestamp that Daniel created, I'd want to find a digit at the start of the line, right?

So to go to the next place where there's a digit at the start of the line, regular expressions use caret for start of line and backslash D for digit. So this is going to search, there you go, and selects the next digit at the start of the line. To search again, press N, N, right?

So this is kind of cool, right? Because what we could do now is if I want to delete everything up to the next digit at the start of the line, well, slash is a motion. So I could type D slash caret backslash D, and that searches for the next digit at the start of the line and deletes to it.

And so now I want to do it again, I press down, I'll just press dot. So now I'm removing everything that's not a chapter header. So that's pretty interesting. And then I could just delete to the end of the line with D shift G and delete the first line, and I'm just about done, right?

Of course, there's more than one way to do it. So let's look at a few different ways. Another way we could do it is we could delete all the lines that start with a hyphen. So there's a really useful EX command, which is the command G. G is, I think it stands for grep, it searches for things, and it does an action to anything, any line that it finds.

So with any EX command, you first of all have to say, what lines do you want to apply it to? And nearly always, you want to apply it to all lines, which is percent. So generally speaking, for most EX commands, you'll start with percent. And then you say, what command do you want to run?

So I want to run G, which is I'm searching for something. And then in EX, the different parts, the kind of the different parameters are generally separated by slash. So the next thing is, what do you want to search for? I want to search for, at the start of a line, a hyphen.

Okay, and then another slash. Okay, what do you want to do? And now I can put in any vim command. And so remember the command to delete in vim is D. So this is going to search for anything with a hyphen at the start of the line and delete it.

There we go. Okay, so we could now do a similar thing to delete all the empty lines. So to delete all the empty lines, I would do percent G slash. Okay, I want to do any time you've got the start of a line, followed by zero or more spaces, followed by the end of a line.

That's an empty line. What do I want to do? Delete it. Okay, so. And then finally, I want to put a dash between that first space and the thing after it. So that's a search and replace. So again, we do colon percent to apply some ex command to the whole file.

S for search and replace. Then the slash to put in our different parameters. So first, what are we searching for? A space. And then what are we replacing it with? Space hyphen space. And then enter. And so this will just apply it by default to the first time it finds it.

Okay, so that's like an overview of like why VIM is cool. Like when people say VIM is cool, they're not saying like, oh, you should use it because it's retro and interesting. They're saying you should use it because it's powerful. And specifically, data scientists should learn VIM because this interactive text munging is what we do with input data files and output data files all the time.

And something we can look at later if we want to is it's super easy to create macros in VIM, which is where like literally it will just record each button you press. And then you can just rerun that macro. So if you want to rerun the same process on six different files, you just run the macro six times.

Now, in this case, I want to close without saving. So normally if I go colon Q and it says, no, you haven't saved. So it's kind of careful to help you there. It says add exclamation mark to override. So I'll do that Q exclamation mark. Okay. So we can use that in in Jupyter.

And so now we're going to fix the problem, which we talked about earlier, which is how come our files disappeared? And to fix it, we need to edit prerun.sh. So if I type vim prerun.sh. So here we've got this. And the reason that the files disappeared is that at the start of our script, we typed CD, and that changed to our home directory.

And we never went back to where we were. And so that meant when it ran Jupyter, it ran it from our home directory. This is actually currently showing the contents of our home directory. Now, okay. I want to show you now how we know this by looking at run.sh.

I want to switch to editing run.sh without saving where I'm up to. And I want to show you a really neat thing in Linux that lets you do this, which is control Z. Control Z does something really interesting. It stops the process I was running, and it puts it in the background.

So if I type jobs, I can see what's running in the background. Vim is running in the background. I can do anything I like. And then any time I want, I can type fg for foreground, and it comes back to where I was. So I can hit control Z, and then I can type vim slash run.sh, which is actually what I was going to show you.

This is the thing that they run for us when we start an instance. And you can see here it runs our script, and then it runs Jupyter. So our script was CDing to our home directory, and then running Jupyter. And so Jupyter was in our home directory when it ran.

So I go to colon queue to exit that, and I'll go fg. There we go. Now, optional power user thing, which I use a lot, is I would not -- that's not how personally I would have looked at the run.sh file. To look at the run.sh file, what I would do in Vim was I would type colon sp, which stands for split, slash run.sh.

And as you can see, vim actually allows me to have multiple windows open at once. Okay. Kind of like tmux, actually. tmux and vim has very similar functionality. And so then I can, you know, scroll around here. And then in vim, instead of pressing control B and an arrow to go to a different window, which is tmux, in vim it's control W.

So except that control W closes a tab in Chrome, so that's possibly not going to work. Okay. So there's a couple of ways we could solve this. The probably the best way in a script is to use that trick I showed you last time, push D. Tilde is our home directory.

So that's the same as CD, changes to our home directory, but it remembers where we were. And then pop D puts us back to where we were before. So that should fix our problem. Okay. So this untitled.ipynb, we'll probably find that -- yeah, see here it's in our -- here it is in our home directory, which was not what we intended.

So let's delete it. And we'll shut this down. And then we'll create another instance just to check that worked. Okay. So while we're waiting for that to get started, does anybody have any questions or comments about vim? Hi, Jeremy. That is very good. That took me back to a previous life where I used to install WordPerfect on Unix boxes and is working in a legal firm and said, what do you use for a word processor today before I put on WordPerfect?

And this person, you know, legal secretary said, I use VI, which is like, vim is VI improved or VI improved. But it's just amazing, the power of it, if you know everything it can do, it's a perfect word processor. Yeah, it's great. I mean, I don't use it as a word processor, to be clear.

I use, you know, Microsoft Word or Google Docs as a word processor, because I think they're very good word processes. But for a text editor, I use it a lot. If I've got, you know, a CSV file, I, you know, want to do some quick cleanup to or something like that.

Or a log file. I'll use it. Yeah, pretty much any time I'm editing a quick script or something on a terminal. It's that's great. You know, I will say Visual Studio Code is also excellent. And I wouldn't say like vim is better or worse than Visual Studio Code. I use both of them.

I use vim more often than Visual Studio Code, but I do use both of them. And in fact, there is a button here, I thought somewhere. I thought there was like an open Visual Studio Code button, but maybe I'm imagining things. Or maybe it has to wait until it's finished opening the server.

Oh, here it is. Yeah. So there's an access remote kernel actually lets you connect Visual Studio on your machine to the remote machine. So you can even use Visual Studio remotely. You can also use it in WSL on Windows. Don't install Visual Studio Code into the Linux box, install it into the Windows box, because it's got a WSL connector built in.

So it uses it treats WSL, you know, just as if it's a local Windows directory. You can also connect to any SSH instance using the VS Code remote connector or yeah, this remote kernel thing. So, you know, you showed a lot of keyboard shortcuts for them, right? So how can someone approach learning it?

Because it feels a bit intimidating when you're a beginner. Yeah. Yeah. So I mean, the trick with learning something new is to try and like do it in small chunks, right? So don't expect to learn all of them. Like, so at this point, I would say learn I just start inserting things, arrow keys to move around, escape to go back to command mode, colon WQ to close and save.

And at that point, you can now use Vim to edit your shell scripts and stuff. And then like try and learn maybe one or two new commands each day. So, you know, one useful one, you know, or emotion each day. So, you know, W and B are useful to know to move forward and backward a word.

And yeah, there's a lot of Vim tutorials and things out there. So, for example, here's OpenVim.com, which is going to introduce you by saying, oh, hit the enter key. Like, okay, I'll hit the enter key. And so you could work through a tutorial like this. Yeah, it's we all get intimidated, honestly, Kurian, when we see an expert working with something that we don't know yet.

And at first, it's like, wow, that's powerful. I wish I could do that. But my god, you know, how would I ever get to that point? And the goal is not to be an expert at Vim. The goal is to like be able to do Vim to like slowly do something that you want to be able to do.

And this is one of the things I, you know, really had to practice to myself in my late teens and early 20s was to repeatedly put myself in a position where I was intentionally doing things slowly by using a tool that I wanted to know. And I was pretty sure at some point would be useful, but I didn't know well enough to do it faster than with other than some other tool.

So I've always, you know, since since like 16 been pretty good at using Lotus one, two, three and Excel spreadsheets. And I tended to turn to them for everything. And then I wanted to learn SQL databases. So I kind of forced myself to do things involving lists with databases for a while, even though I got slower.

And then I was like, okay, well, I'm going to stop using, you know, I got to start doing more stuff with VBA macros and stop doing stuff manually. And again, it was kind of slower for a while. And particularly like, you know, things like cleaning up that YouTube timestamp thing, I could have done that manually, you know, and the first 10 times it would be faster to do it manually.

But don't do it manually, right? Because each time you do it manually, you know, you're missing out on the opportunity to get better at the thing that's going to make you faster. And the thing about practicing what you think might eventually be the fast way is that those fast ways accumulate together in kind of these multiplicative ways.

And so, you know, I've been kind of using this approach of always trying to do things the way I suspect would be the fastest if I was an expert at it. I've been doing that for like 30 years. And now, most people who watch me work go, wow, you're very fast at doing stuff.

You must be really smart. You know, I'm like, no, I'm not really smart. Like, you should have seen me when I started. I was terrible. But now these things have all accumulated, right? So, yeah. And if anybody finds, you know, good tutorials, let me know. Honestly, it's been a long time since I've run a VIM tutorial.

So I don't know if this one's good or bad. This is the first one that came up in Google. But the VIM tutorial is good. The best tutorial is on Linux in the terminal. If you just type in VIM tutorial in the terminal, it should pop up a very nice tutorial.

And I just wanted to say, Jeremy, you know, a few minutes of speech that you just gave. It was absolutely wonderful and very, very useful. Okay, yeah. So here is what happens if you type VIM tutor. And it will teach you exiting VIM. So lesson one, moving the cursor, lesson two, exiting VIM.

So that's a good start. Make sure caps lock is not depressed. Impress J enough times so that lesson 1.1 fills the screen. J, J, J, J, J. Okay. So because the VIM tutor is in VIM, it forces you to use VIM, which is good. And the nice thing about this is, you know, move the cursor to the line below marked blah, blah, blah.

Here it is. Fix the errors. Move the cursor. Okay. So here's a useful one to know. X to cross out something. So X. There we go. Thanks for that reminder. And the first time you do, you go through the VIM tutor, it will feel overwhelming. It did to me only after, you know, on like third, fourth try, does it start to make sense and are able to complete the entire thing.

But also, when I was learning the basics of VIM, I realized that it has a steep learning curve. And I like to make things appealing, attractive, and simple for me. So I think Dimitri also mentioned this in the chat here a second ago. There is a game called VIM Adventures, which is in your browser.

And it's another way that you can get exposed to them. That's how I learned it. So I would dive into a call when I had my corporate job. And instead of, you know, whatever people do on calls, which is just, I don't know, browser edit, I would do this.

And that was my time. Okay. Now I just tried pressing the arrow keys and VIM to see what the VIM Adventures, and it says, don't use the arrow keys. I don't agree with that, by the way. A lot of people are overly purists about, like, you have to do things the VIM way.

So, okay, yes, you can use H, J, K, and L. But seriously, it doesn't matter. Anyway. By the way, I see there's actually just a few things in the Zoom chat. If you can, please say it out loud. There's a couple of reasons why. The first is I really enjoy social interaction.

Otherwise, I'm kind of sitting in my little office, you know. And then the second is, of course, for the video, people can hear the questions. Now, I know sometimes people just can't really talk because they're in some environment, they can't do it. In that case, if you see somebody asking something in the chat, could you say, oh, Mike M asked, what key are you pressing to undo, Jeremy?

Rather than just answering it in the chat, and that way I could, like, say that anyway. It looks like, so, yes, somebody said, how did you do undo? So, the answer is you to undo. Can I suggest one last resource that is quite amazing for VIM? It's the VIM book, editing at the speed of light.

Editing, I don't know that one. Speed. Speed of thought? Of thought, yes, yes, yes. Practical VIM. That's really, you know, really well written. And there's a similar book for tmux. So, that's how I start the books that made the really big difference for me. Now, let me tell you something not to do, which is don't install lots of plugins.

There's lots of plugins you can install. And, you know, after using VIM for well over 20 years, I don't use any plugins at all. It's not to say that there are none that are any use. But, like, they're not that useful, honestly. And you can get lost in that whole, like, customizing things thing.

And I just wanted to make it clear to say, like, actually, out of the box VIM works extremely well. Now, having said that, I customize it using a VMRC. So, an RC file in Linux and stuff is like, you know, the normal kind of suffix for configuration files. And I do do some customization of it.

And I actually put all my configuration files in a GitHub repository. Or .files. And you'll see here there's a VMRC. But it's only 99 lines. And there's things like, for example, remember, I mentioned that you can jump to the next -- you can jump around Windows by pressing Ctrl + W.

I made it so you can also press backslash W and backslash up and backslash down. So, just really minor things like that. And also some little things like -- oh, I guess I do have some things installed. I don't use them anymore. Also some things like Python syntax highlighting.

And also, to be able to see things clearly when you've got a black background with light text, you have to say set background equals dark. So, I don't know. Little things like that. It comes with some nice defaults. You can just actually do this source command to get some nice defaults.

>> Quick question, please. Is this one public or private? >> Everything of mine is public. >> Fantastic. Thank you. >> Pretty much, I think. >> I have a question. What are your thoughts about Visual Studio Code to edit files? >> They're great. I just talked about it. Yeah, I said it's really good.

Yep. I like Visual Studio Code. >> Hi, Jeremy. Do you suggest using Vim key bindings for Jupyter and VS Code as well? >> I don't. Because I find it's not about the key bindings. It's about the numbers and the motions and the dots and the macros and like that stuff.

And I don't find that there are other editors that Vim as well as Vim do. So, when I use VS Code, I rather, you know, like fully inhabit the VS Code world. And so, I use the normal VS Code key bindings and try to learn to use VS Code as well as I can.

So, yeah, I don't do that. Sometimes I've tried. And I'm always disappointed. It's always like, yeah, it's not really. So, VS Code is great at being VS Code. And I would use that for editing a big markdown file maybe. I don't use it much. But I guess if I was working with HTML or CSS or something, I feel like the way it kind of handles those kind of file formats is really nice.

You can set up Vim to be really nice as well. But VS Code works a bit better, more out of the box, I suppose. Yeah, and also for like navigating through a large repository, VS Code can be a bit easier to use maybe. To ask whether you could use a fairly large project with multiple files and whether it was doable via Vim.

Yeah, it's definitely doable via Vim. Yeah, I mean, we can take a look if you're interested. So, yeah, let's take a look. Actually, it is useful to know how to do this. So, let's take, for example, the fast AI repo. Okay. So, let's clone it. And so, let's do it all in paper space.

Now, in paper space, the /notebooks directory is persistent across machines. So, it probably makes sense to clone this into the /notebooks directory. So, if I open up my terminal, so it's persistent within a machine and it's persistent across restart. So, if I get clone here, it'll still be on this machine.

Next time I open it, because that's what /notebooks is. It's persistent across restarts on one machine. Quick question, Jeremy. Yeah, actually, just before you do, I'm just going to cancel this and mention some a little shortcut if that's okay. Did you see that was taking a really long time to clone?

The reason why is it's cloning every single version of fast AI that's ever existed. And since I don't need every single version, if you type --depth1, it'll just give you the most recent version that will save some time. So, yeah. So, go ahead. One of the other scripts you had, you were bringing in /notebooks from storage, like storage somewhere.

Is that a change? Yeah, I didn't really understand how /notebooks persistence worked at that point. I hadn't spent enough time reading the docs. Yeah. So, let's pretend that never happened. Okay. So, now that I've cloned this into /notebooks, you can see it's appeared, right? Because this is where Jupyter is running from.

So, fast AI is what's called an nb-dev project, which means it's all developed in notebooks. So, these are the notebooks which create fast AI. And then those all get exported as Python modules into here. It's not a very interesting one. And as you can see, it says, "Oh, don't edit me.

Edit the notebook." That's fine. Okay. Now, if you want to explore through a code base, it's really helpful to be able to, like, click on symbols and jump to their definitions and then jump back again to kind of see how it all works. And so, you can actually do that on GitHub, by the way.

I don't know if you've noticed this, but it's quite neat. So, for example, to detach, if I click on it. Oh, it's interesting. It doesn't know how to find that one. It's not perfect. That one's actually from PyTorch. That must be something it knows how to find. What about this one?

A popular model, maybe? Well, it's fine. Yeah, it's a popular model. Okay. Well, this is very strange. In theory, it would. Finally, it found one. Okay. So, one problem with doing it in GitHub is it's not particularly good at it. But, yeah. So, Vim can also do that, as can VS Code.

And VS Code and Vim both rely on something called C tags to do that. C tags is a project to create an index of the symbols that are in your program. So, we want to install that. I actually haven't bothered Googling it for like 20 years, so I didn't realize that the thing I am used to using has been updated to this new thing.

So, that's interesting. I guess I should try using it. So, Ubuntu, install, universal C tags. Oh, God, snap. I don't like snap. Well, I guess I can if I have to. Actually, I tell you what I normally do for installing things is I like to find out if there's a Conda installer.

Because that makes life very easy. And there is. There's a universal C tags. Okay. That's handy. Universal C tags. So, Mamba, install, universal C tags. And this is one of the really cool things about Conda and Mamba is that I can install. Ah, well, we don't have Mamba installed.

That's fine. We can set that up. Conda, install, minus C, defaults, minus C, Conda, forge, Mamba. And so, in some future lesson, we'll talk about how to get these Conda and Mamba installed things working persistently in paper space. There's probably some way to do it in snap as well.

I've never bothered checking. I don't know if anybody knows Ubuntu, snap, install, home directory. I wonder if that's possible. This thing that Jeremy is going to show us, this will give us superpowers. This is one of my favorite features of them and of just jumping into them whenever I'm browsing through any code on the next, in a team like Spain.

And this is the way that professional developers interact with code. And it's not even all the professional developers. So, like, you know, the ones who, like, limited view. Very few people can navigate around code that quickly. And I think that really makes an enormous difference. So, whenever Jeremy covers this, I become excited.

And, you know. That's great. We're lucky getting excited, Radek. Okay. So, there's Mamba. So, we can never remember. Install. Oh, I'll just press up here a couple of times. Universal C tags. Oh, and we don't. Okay. So, we're not using Mamba Forge here. We should probably, I might ask paper space if they can switch to using Mamba Forge so we don't have to worry about this in the future.

But for now, we'll have to put, it's from the Conda Forge channel. Because the one that they've got installed does not use Conda Forge by default. I might also talk to them about making it so that Python 3.9 is the default, since it's still using 3.7, as we saw last time.

All right. So, if we CD into the first AI directory, there's a bunch of Python code we want to look through. So, if you type C tags, that's the program that creates the index that we want. And to run it recursively on the current folder, most things in Linux and stuff for capital R for recursive and then dot means the current folder.

So, that's indexed the current folder and it's created. I expected it to create a file called C tags. I wonder if it's changed how this works. Sorry, it's created a file called tags. So, it's created this file here called tags. And if you look at it, you're basically, it's just a whole list of like symbols that it found in my code and regexes to find where they are and what file it came from.

You don't ever have to look at that. The key thing to know is now we can jump straight to a tag. So, for example, if we want to open up the array mask, whatever file defines array mask and put it in the right place, I can type vim minus t for vim jump to a tag and type array mask and that will jump straight to the definition.

Okay. So, that's one way to do it. Another way to do it would be, let's say we were looking at something else like layers.py, is you can type tag jump and then type ar tab and then it'll list all the things that match and then I can hit enter and that will jump to that tag.

Another thing that you can do is you can notice, for example, this is inheriting from array image base to jump to the definition of array image base. It's control right square bracket and so when I hit that, it jumps to that definition and then to go back to the previous tag, it's control t for tag.

Okay. So, they're the key ways to jump around. Okay. So, for example, if we wanted to find out some tabular class, I could go tab, tag jump, now start typing tabular and hit tab and here's my various tabular classes. Go to tabular colab. Okay. So, tabular colab is defined in two places.

Now, that's annoying. One is it's in an ipy check points, which is the backups. So, this is where you would actually create a c tags config file telling it to ignore anything inside ipy'd nb check points because you never want to go to the backup version. So, for now, it's confused about which one I want.

So, I'll hit two to go to the non-confusing one and there you go. Any other tricks you know with tags, Radik? >> Yeah. Just wanted to mention one and this is what I did only once or twice because I'm always too lazy to set it up. But there is some way, like with the fastai code here.

So, you know that it's using PyTorch a lot. And sometimes you would be editing a fastai file, but you would like to jump to the definition of some functionality in the PyTorch code base. >> Oh, yes. That's a good one. >> That's very helpful, especially for, you know, if you're just starting with PyTorch, starting out, it's so much nicer than using their documentation on their website, which is slow and, you know, you have to still search for it.

But, yeah. >> Yeah. So, you know, maybe in the future we can try setting that up as well. So, yeah, you can set it up so that these tag jumps can jump into the PyTorch source code as well as the fastai source code. I'll just show you one more trick, which is if I wanted to look up to find out how data loaders worked, but I want to be able to see Colab data loaders at the same time, then hitting write square bracket isn't quite ideal because I've now lost what I was looking at.

So, instead, if you type s tag, that means split tag, and I can start typing data loaders, then that will split the window and jump to the tag so I can now see the two things that I'm doing. Which I find handy. Anyway, there's a lot more stuff you can do with this, but hopefully you've got a sense of, like, yeah, this seems worth investing time in because here are some things that I didn't know how to do before and might be helpful.

>> Just on the split again, Jeremy, my tab closed down when I pressed command W. >> Yes. >> To move around. How did you -- how would you do that within the Chrome browser again? >> So -- >> Between Windows. >> On a Mac it's fine because control and command are different, so you can just control W does work.

>> I already do. On the Mac. >> On the Mac. On Windows, if you use my .files, maybe we can, in some future one, we'll learn about my .files, but in my .files I set up, and so if you make this your Vmrc, then basically you can hit backslash up and backslash down to go up and down a split.

Because I think this C W -- this means control W will be sent to Vm rather than the browser, so I think that should work fine. Great. All right. Nice to see you all again. Have fun with Vm. Tell us if you find any cool tricks on the forum.

And I'll see you next time. >> Cool. Thanks, Jeremy. >> Thanks, Jeremy. >> Thank you. Thanks, Jeremy. Bye, everyone. >> Thanks a lot. >> Thank you.