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

ThePrimeagen demonstrates how to search for, create, and navigate a quickfix list using ripgrep and fzf. How to search for and create a quickfix list with grep is also covered in this segment.

Get Unlimited Access Now

Transcript from the "Quickfix" Lesson

>> So I feel like we're making them pretty good at this point, yes, FZF is pretty awesome, because it works in both in the Neovim, so I use telescope like I said, that's a Neovim only one, but FZF is pretty darn awesome. Quickfix is something that I never really tried to learn about, honestly, I'd use like, say ripgrep,if you're familiar with ripgrep, it is an incredible utility to be able to search like a bajillion files, and just what feels like instantaneous.

[00:00:29] It's fantastic, it's written rust by the way, so you can tell people it's rust, really easy to brag on people in plus, you get to have the three circles like so if you're using vim with ripgrep on Arch Linux, you are the actual coolest person that has ever existed.

[00:00:45] So just remember that it's available, you can use it, so ripgrep is awesome, but here's the problem, when i was using rip grep, I didn't realize that FZF would pipe ripgrep's results into a quickfix list. So I'ld always search it, and then i'd close the quickfix list, and then I couldn't go back to it, I didn't understand what it was, I never really read into it.

[00:01:06] And it's kind like the cycle that I have for three months as I can, this feels funny, like it never really clicked in my head like, why is this happening? What is this list that keeps popping up? And when I close it, it goes away, this just doesn't feel right, and so let me show you, if you have ripgrep installed, and you have FZF, you can also use Rg, so this is ripgrep, right?

[00:01:27] So I can search up the word SOCK, right? And it will actually show you, now we have a ripgrep result, piped into an FZF result, so now I can start doing things, I can start typing and get a single solution out, awesome. But if I press Enter, it's gone, right?

[00:01:43] So I want to say, send all four results, to a quicktfix list, one thing you can do with say FZF, is you can press tab, notice that I get that little extra item. I can go tab, prev tab, prev, and I can go through and do them all, you can actually select them all at once, but I forgot I don't use this utility anymore, but I forgot what it is.

[00:02:01] And if I hit Enter, I now have what is referred to as a quickfix list, you can tell it's a quickfix list, by this light text down here, that says the word quickfix. We'll go over more of this soon, it's available in FZF, but let's do it without FZF, sounds good?

[00:02:18] So let's use grep instead, so vim does come with grep, it's gonna use grep underneath the hood, and we're gonna find it, so let's go into a command. So this will work on any system by the way, so if you remote into a system, and it doesn't have any plugins installed, this just works, we're gonna type in grep.

[00:02:34] Then what do we want to find? Let's do the same thing SOCKET, right? We're inside of the vim nap playground, and we wanna search every single file, and everything that starts with say .c, right? So every single folder all that, it's gonna return to us three results, awesome, when I hit Enter, it navigates us to a result, if you didn't wanna navigate to that result, you could use bang and it would silence it, but right now we've now navigated to a result.

[00:02:59] What do we do here? How do we get those other three results? I don't know, well, they're in a quickfix list, you can do copen, so if you type the command copen, I keep playing this way, if you type the command copen, and press Enter, it will open it back up, and it'll even highlight what command or what quickfix item you're currently looking at.

[00:03:22] So if I type in cnext, by the way c is for quick, I know, mnemonics, right? Cnext it will move to the next one, notice that my highlighted line has moved forward, and I've changed files, if I do it again it will go to the next one, if I do it again it's gonna say hey, there's no more items in here.

[00:03:41] I bet you can guess what goes backwards, see prev, right? Awesome, we can walk back and forth on this quickfix list, and the best part, is I can close that quick fix window, and I can walk through it and you can see, 3 of 3, 2 of 3, 1 of 3, you can actually watch yourself walk through this quick fix list.

[00:04:00] This is awesome, but do you want to have to press all these buttons to be able to open up a navigated quickfix window? No, you don't, so what do we do? If I say remap it one more time, I swear, so let's remap it one more time, let's open up our vimrc, now notice we're going a lot faster, I'm assuming everyone's starting to have a lot more knowledge.

[00:04:21] I'm not explaining as much as I was, so if you're having trouble following along, you might be missing some context from earlier, I'm sorry, but we're gonna try pick up the pace so we can cover a lot of content. Right, so I'm gonna go all the way down to the bottom, you could have pressed j to get all the way down to the bottom, I'm gonna highlight this, and let's use Ctrl j.

[00:04:43] I want Ctrl j + k, to be able to go back and forth on cnext cprev, you can choose what you want, whatever works for you remember, this is about you, what works for you think about it. Maybe you wanna use space cn for quickfixed next, right? That actually kind of is numerically equivalent to Colin cnext, you can choose what you want, I'm just gonna choose Ctrl j + k, because for me, it's on these two fingers, and it's right next to Ctrl, so I literally just do this.

[00:05:09] It's very convenient for me, cuz I use Dvorak, by the way, used Dvorak remember, it's not on this list, but it should be, all right, so I'm going to do cnext, right? This might be backwards, I can't remember, and then let's use sk for this, let's do prev, there we go, so now I can navigate back and forth of that.

[00:05:29] So I'm gonna close this, I'm gonna reopen up then here, we are gonna do the same grep search, I'm gonna type in gr press Up, it will autofill my last command that looks like it. When I press Enter, get that information, it's gonna navigate me to the first one, so I should be able to press, okay good, okay got them perfectly backwards.

[00:05:48] K goes, the way I didn't want it to go, so I can go j, j to go forward, k, k to go backwards, and just walk forwards and back through them. So if you're doing a large set of actions or looking at a large set of changes, this is a really awesome thing, to start getting used to cuz you can do quite a bit of stuff here.

[00:06:04] And on top of that, it can get way more powerful even though we're not going to do it, there's something called cdo, cdo allows you to execute a command, across all of your quickfix list. So you could theoretically do a Find and Replace, you could do a macro, you could delete a line, you could do whatever you want, across the set of quickfix lists, or a set of quickfix results, and then have them all saved by executing say write all.

[00:06:33] And now you'd write all your changes, and so this is like, this kind of the way that vim does, kind of larger project wide, Find and Replaces and things like that, as you can pipe things to these lists, and work with them. You can do macros, regex search and replaces, it's very awesome, I am a huge fan of quickfix list, and the best part is that, I didn't really use them that much until just recently, and now I'm just trying to find a way to pipe everything to a quickfix list.

[00:07:01] They are incredible, absolutely incredible.