VIM Fundamentals VIM Fundamentals

Alternate File & Jumplist

Check out a free preview of the full VIM Fundamentals course:
The "Alternate File & Jumplist" Lesson is part of the full, VIM Fundamentals course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen does a brief recap of files and navigation, demonstrates how to quick switch to an alternate file, and how to use a jumplist. The jumplist displays a sequential list of previously accessed files that can be navigated through using Ctrl + o to go backwards and Ctrl + i to go forwards.

Get Unlimited Access Now

Transcript from the "Alternate File & Jumplist" Lesson

[00:00:00]
>> Wow man marks I actually was so excited when I first got these. When I first found them out I thought this is gonna be the greatest thing ever. And then like a week into it, I'm like, my mental overhead is just way too high. I like was breathing deeply at neck pain.

[00:00:12] It was crazy. Anyways, okay, I didn't really have neck pain, come on. So let's keep on going. Let's kind of talk about what we've done so far. So we've used edit or colon a you could also type in colon edit. Showed how you can do a fuzzy find over your root directory that you opened up and by using a bunch of stars, there's a way for you to actually set an option to say what your base finding pattern is.

[00:00:37] And so that way e every single time is a fuzzy find, but it's only an ok fuzzy find. And I also showed you telescope, like how much nicer telescope actually is, or a fuzzy finder in general, and we're gonna install a fuzzy finder here shortly. I also showed you how to use Ctrl C or Ctrl N, Ctrl P to navigate pop up menus, tab autocompletes, whereas Ctrl D will show you all your possible options.

[00:00:59] There's a lot here, but let me show you a couple quick things. These are like the fun things now these I use all the time. Alright, these are like staples. Now here's the deal. I made this edit last night at like one in the morning. So if I accidently mentioned this elsewhere I'm gonna say sorry now but it felt like the right place to say, like sometimes you get that feeling and this is the moment.

[00:01:21] So here we go. All right, so let's go back to this file. So now I have those two marks set right, I have tick capital A or sorry single quote capital A single quote capital B, I can go between those. Now there is something else. that is always available to you.

[00:01:38] So the first thing I wanna do is I'm gonna actually do registers, right? And if you go all the way down your registers, you'll notice these two right here, the percent sign, and the pound sign. The percent sign is my current file, it's always that, remember when we did the so percent sign to source our vimrc, that's because it's always pointing at your current file.

[00:02:00] It is also stored in a register for you automatically, but there is also the pound sign. What does that pound sign? What does it look like? It looks like my previous file. So it always stores one previous file, whatever your most recent previous file is n the pound sign.

[00:02:17] And how you access it is Ctrl carrot now I believe it works Ctrl six on Qwerty keyboards I can't tell you completely, but I believe it's Ctrl six on Qwerty keyboards and that should make the jump for you. But I can press Ctrl carrot and jump back and forth.

[00:02:32] This is really nice when you're doing like two file editing, you're in one file, you do some edits. You take it you go and you jump back to the other one. My goodness, I got it right, jump back over here we go in here we make an edit, we write it, we jump back, and we're kind of like hopping back and forth and doing these edits really fast.

[00:02:48] It actually is pretty nice. As you can see right there did those two edits really easily I could go back and forth between the files. Alternate file also is available in ems. The less superior editor and that one is it's the same notion and I know my co workers, we talk about it all the time.

[00:03:03] Alternate file is by far, one of the most useful commands in any editor, just the ability to hop back and forth really quickly, is super-duper. I use it all the time for testing. Like if I have a file that always breaks and the follow up on the test file, you can just sit there going back and forth and develop on it really quickly.

[00:03:20] It's quite a nice feature. And then the other thing I was gonna show you is called jump list. Now your jump list, it's unique, it's fantastic, but it's weird. Okay, so it's not quite file navigation but it's also not not file navigation. Alright, so that's probably a little bit hard for that to make much sense but let me show you the first thing you can do, you can always do help jump list right now how the jump list effectively works is that there are some movement commands that get added to it.

[00:03:49] And there are file changes that get added to it. You can see all the things that actually happened somewhere in this list. I forget where it is. It will tell you all about which things get added. I think it's under jumps, help jumps. And it's right below it.

[00:04:03] I thought, gosh, I can't even remember. Anyways, you'll notice you see Ctrl I and control O everywhere. What this is, is that's how you use your jump list. So I can go like this colon jumps. And you can see right here that as I go down the empty spot marks where I'm at, or the globe or sorry, the carrot marks where I'm at.

[00:04:23] I don't know I said I'm spot there you go. So if I want to jump backwards, I will jump to twitch dot c back to my current file, twitch dot c back to my current file, twitch dot c twice and then actually go all the way back to vim nav playground directory.

[00:04:38] So let's do that. I'm going to go control O, O, O, O, O, O, boom, right, there we go. So I hopped back up my jump list. And certain keys allow for that. You can also use Ctrl I to go forward. And so this can be very handy when you're navigating a couple files.

[00:04:55] But it can also be a little bit annoying in the sense that if you have a bunch of movements that you use that add to the jump list. You'll watch yourself jump up and down. I use it often to get back to where I was in a file, like LGG to jump to the top, add an import statement really quickly, hit control low I'm right back to where I was.

[00:05:11] Right.