YouTube Icon

Code Playground.

How to Search in Vim / Vi

CFG

How to Search in Vim / Vi

This article depicts how to perform search tasks in Vim/Vi. 

Vim or its antecedent Vi comes preinstalled on macOS and most Linux conveyances. Looking through content is one of the most well-known errands when working with records. Knowing Vim's essentials may be valuable when you experience a circumstance where your preferred proofreader isn't accessible. 

Basic Search

To look in Vim you should be in typical mode. At the point when you dispatch the Vim editorial manager, you're in this mode. To return to ordinary mode from some other mode, simply press the Esc key. 

Vim permits you to rapidly discover text utilizing the/(forward cut) and ? (question mark) orders. 

To look forward, press/and to look through in reverse press ?, type the inquiry example and press Enter to run the pursuit: 

Note that the hunt order searches for the example as a string, not an entire word. On the off chance that, for instance, you were looking for "gnu", the pursuit discover matches where "gnu" is implanted in bigger words, for example, "cygnus" or "magnum". 

Press n to look for the following event or capitalized N to look the other way. 

The fundamental strides to play out a pursuit in Vim are as per the following: 

Press/. 

Type the inquiry design. 

Press Enter to play out the inquiry. 

Press n to locate the following event or N to locate the past event. 

Search for Whole Word

To look for an entire word, start the pursuit by squeezing/or ?, type \< to stamp the start of a word, enter the inquiry design, type \> to check the finish of a word, and hit Enter to play out the hunt. 

For instance, to look for "gnu" you would utilize/\<work\>: 

Search the Current Word 

You can likewise look for an entire word by moving the cursor to the word and squeezing * (reference mark) to look through advances or # (hash) to look in reverse. To locate the following match press * or # once more. 

Search History 

Vim monitors all the pursuit activities you made in the current meeting. To peruse the pursuit history, press/or ? also, go through the bolt/down keys to locate a past pursuit activity. To run the inquiry, essentially press Enter. You can likewise alter the hunt design before playing out the activity. 

Case affectability 

Naturally, the item is case delicate; looking for "GNU" won't coordinate "Gnu". 

To disregard case type :set ignorecase or :set ic in the Vim order line. You can likewise set the overlook case to be a default choice by including the order in your ~/.vimrc record. 

To change back to case coordinate mode, type :set noignorecase or :set noic. 

Another approach to compel overlook case is to affix \c after the inquiry design. For instance/Linux\c performs disregard case search. Capitalized \C after the example powers case coordinate pursuit. 

Conclusion

To look in Vim/Vi type/or ?, enter the inquiry example and hit Enter. 

Don't hesitate to leave a remark in the event that you have any inquiries.




CFG