 Now I don't think it would come as a surprise to anyone who watches the channel to know that Vim is one of my favorite tools. I use it extensively throughout the day for my day job, for my hobbies. I'm pretty much always doing something in Vim. With that being said, I can understand why some people are reluctant to get into Vim. And that's because it can be very overwhelming. There's multiple ways of doing things. It's keyboard based. So you have to learn a lot of key bindings. The configuration file is confusing to say the least. You have to learn basically an entire language in order to configure it. Now, while I personally don't think it's hard, I can understand why it could be overwhelming for brand new users. Even if you've gone through the process of using VimTutor to learn the basics, there's still a ton more that you need to learn or could possibly learn in order to be proficient at them. Personally, I don't think I'm proficient at them. I've been using it now for three or four years. And the stuff that I do makes me seem like I'm really good at it. But then I watch other YouTubers and they make them look like they're magicians, they're wizards. And like, I want to be that person when I grow up, right? The thing is, is that we all start somewhere. So when you're first starting out at Vim, you have to learn the basics. You have to learn how to move around. You have to learn how to get into the certain modes and so on and so forth. One of the things that can be kind of tricky to learn is how to search. So what I thought I'd do today is talk about how to search in Vim. Now, this is not a comprehensive guide. One of the things you'll learn in Vim as you go along is that there are multiple ways of doing things in Vim. There's actually many, many ways of doing things in Vim. And that pretty much holds true for everything you can do in Vim. Now, some people will call that bloated. Some people will say that it's not that big of a deal. What side of that argument you've fallen doesn't really matter. But for the purposes of this video, I'm going to show you the simplest ways to search in Vim. I'm also going to cover a little bit, a little tiny bit of search and replace at the end so that you can kind of get an idea of what search and replace kind of looks like. So let's go ahead and jump in. So what I have here is just my PyCon configuration. I just brought up a random file so that we can play around in it for a little while. The absolute simplest way to search in Vim is by using the slash key. Now, this key right here and this sequence right here that I'm going to be typing is something that you can use pretty much no matter where you're in Vim. And it's always done in normal mode. You can't do this obviously inside of insert mode, but you can sometimes do it inside of visual block mode, but that's outside of the scope of this video. So in order to search for something, let's just say we wanted to search for the word back end. So you do slash, so we do slash like that back end. And so the word that you're searching for. And then you will see that it's highlighted at least one result. Now, one thing I should make clear here is that highlighting in Vim is going to be very specific to the configuration that you're using. So it's possible that yours will be an underline. It's possible that it will have a background similar to what mine does, only maybe a different color. It's going to depend on what configuration you're using. So just know that the way that it highlights stuff might be a little bit different. Now, let's just say you are done searching for this word, but you want to kind of filter through every single result that it's found. So once you've done typing the word hit enter, once you're done typing the word hit enter, that will will remove the cursor from the search field. And then you can use the N key to go forward and search results. So hit N, and it will go forward. Now, unfortunately, there's only one search result here that actually meets that. So you can see how many times it's found that word that you're searching for down here underneath my face. See where it says one on one, that means it's only found at one time. Let's search for something else that there's multiple instances of. So class and enter, and then we can use again the N key to search, go through the document for every single result. So you'll see the cursor moving on to each instance that it found. In this case, it found six instances of the word class. Now, let's just say you wanted to go back. So you'll notice that small n goes forward and cycles forward through the results. If you use capital N, it goes backwards. Like that. Okay. So that is the absolute basic way of searching. Now this works with multiple words as well. So if you want to find two words that are right by one another, you can do slash and then the term you are searching for. So in this case blur, and we see that it's highlighted the one instance of set blur that's up there. It doesn't really matter that there's a space. If you wanted to also search for the next word, you can do that as well. So if you were just looking for something specific and you knew exactly those three words are appearing together, you can search for them and then hit enter. It'll actually put the cursor where that search result is so that you can start doing your business there. Now let's actually search for class again, because I know that there's multiple instances of that. Once you've searched for something, let's just say you wanted to remove the highlighting. Now, like I said, highlighting is going to be very dependent on what configuration you're using. It might look different, but it will highlight in some way. Let's just say you want to remove the highlighting because that won't go away forever. Like it will actually, if I close this out and open it back up, you can see the highlighting is actually still there. So for me personally, I have a key binding controls S in order to get rid of that. But if for you, what you're going to do is colon and OH, that just basically means no highlighting hit enter and that goes away. Now the next thing I want to show you is let's just say you don't want to, you don't want to type out the word. Let's just say you found the word. So in this place, we're going to use class again, and you want to search for that word, but you don't want to do slash class and so on and so forth. You don't want to do that. Instead, what you can do is just use the asterisks and the hash symbols in order to search. So if we use the asterisks like this, it will find all those. And then we can actually keep using asterisks to continue to cycle through those. Now in this case and also works. So once you've searched for that using the asterisks the first time, so let's just clear out of that search and find a different word here. Let's use the word borders. So if we use again use asterisks, we'll see that there's actually only one instance of the word borders in this file, which is let's use background instead. We know there's a couple of those will do asterisks. So if it's found all the instances of background in there and then we can use either end to circle through them or asterisks again. Okay, now let's just say you wanted to go backwards in the document. So if you have a really long document and you're like three quarters of the way down, but you know whatever you're searching for is above where you are, you can use the hash symbol. So let's get rid of that search. So in this case, it is an OH again, in my case, control S that's something that I set up. So it won't be for everybody. So we're down here at this instance of background. We know that this is the absolute last one in the document. So if we do shift three, which is the hash mark, it'll do the exact same thing that we saw with the asterisks only it's going backwards. So again, hashtag over and over again, it goes backwards. You can also do shift N oddly in this situation, instead of it being intuitive that the capital N will go through and go backwards just like you would expect because in normal search, capital N goes backwards in the search. But in this case, it actually goes the other way around. The small N is the backwards in the search and the big N is forward in the search. I don't know why that is. It's really weird because it actually works. So if we go back to asterisks again, and we hit small N, that goes forward just like you'd expect. Big N goes backwards just like you'd expect. But if we do the hash symbol again, just like that, small N goes backwards, big N goes forwards. It's confusing and I don't know why it's like that. So that's just, it's a quirk of them. Maybe they'll switch those around like I'd expect them to, but it's still really weird. Okay, now let's say that you want to search for something and ignore the case. So what I mean by that is that you want to search for all instances of word, no matter whether it has any capitalized letters or not. So in this case, you'll notice that I've added a couple words to this document probably. And in order to do that, you can set a mode for this. Now you can do this in your VMRC or you can just do it by instance. So just in this buffer, you can do that by doing colon, set IC and this just means ignore case, hit enter. Now when we search for the word background, it will search for all instances of the word background no matter what the case happens to be. So that is ignore case. Now the next thing I wanted to show you and I like I said at the beginning, I wanted to show you just a little bit of search and replace because this the search and replace functionality is complicated. And it requires the knowledge of quite a bit of syntax in order to actually get a hand a handle on. But for basic search and replace is actually fairly easy. So in order to do this, you want to do colon percent s, then slash, and then the word that you want to replace. So in this case, we're going to replace background. Now this is not case sensitive. So it will replace all instances of background, whether it has a capital B or not. And then the word that you want to replace it with. So in this case, we want to replace it with foreground, just to mess with pi calm just a little bit and then do slash and then G. Now, if you just want to replace the first instance that it finds, leave the G off. If you want to replace every instance, do the G part. That just basically means go globally to enter. And it will replace every single instance of background with the word foreground that's search and replace. So those are the absolute basics when it comes to search. There's actually a ton more that you can learn. If you really want to get deep into search and replace, you can start learning about regex and search patterns and all this stuff. The rabbit hole can be very deep when it comes to almost every single part of them. So that's the reason why we didn't cover everything. But if you're just looking for a very brief way of learning how to search, hopefully this video helped you. If you have any questions, you can leave those in the comments section below. If you want to follow me on Twitter, you can do so at the Linuxcast. You can support me on patreon at patreon.com slash Linuxcast before I go. I'd like to take a moment to thank my current patrons.