List of content you will read in this article:
Vim, a sophisticated and highly customizable command-line program, is a text editor that enables quicker text editing. Vim was invented by Bram Moolenaar. Depending on our needs, we may make use of the different plugins available in Vim. As in macOS and most of the best Linux distros, VI Editor comes Preinstalled. One of the most common tasks for everyone is Finding/Searching a text in Vim/VI Editor while working with files. As this is very basic information, So working and boosting your productivity with such basic Vi commands will help you. this article gives you a brief about Vim Search/Vim Find/Vi Search/Vi Find.
VIM, or Visual Editor for Unix-like Operating Systems, provides the greatest command-line text file editing experience for Unix. Vim is a revamped version of recent operating systems' popular vi text editor. This is a text editor with a lot of options.
How to Search in Vim Editor?[Different Ways]
1. Simple Vim Search
Users must be in normal mode to search in Vim. When you open the Vim editor, you're in this mode and hit the Esc key to return to regular mode from any other mode.
You can quickly discover text using the Vim's//forward slash and?' question mark. Press '/' to search for the forward searches, and click '?' for backward searches. Input the search pattern and click Enter to search.
The following are the fundamental stages for searching in Vim:
- Press the button of / key.
- In the box, type the criteria for the scan.
- Click Enter to commence the search.
- Press N to identify the next incident, then press N to discover the previous incident.
Open file1 in the vim editor
$ vim /file1
Search for a word named "Hotel" in the forward direction:
- Press ESC key
- Type /Hotel
- Hit n to search forwards for the next occurrence of a word named "Simran". You can press N to search backward.
2. Look for the Entire Word
To find out the complete word, start your search by pressing / or ?, type \< to mark the starting of a required word, enter the search pattern, type \> to mark the endpoint of the word, and hit Enter to perform the search.
For example, to find "Linux," you might type /\<Linux\>:
3. Specify a Word to Open a File at That Word
Vim/Vi can open files at a certain word, allowing you to skip a step and get straight to the phrase you're looking for.
Use the following mentioned command for Vim find.
vim +/word [filename]
For example, to access the /d1/f1 file where the phrase "xyz" appears for the first time, run the command:
vim +/xyz /d1/f1
4. Find in Vim Without Regarding for Case Sensitivity
When looking inside a file, Vim is case-sensitive by definition. For example, when you search for the word /Linux, no results with the uppercase L appear as "Linux".
There are several techniques to accomplish case insensitivity in Vim.
Use the following Linux command to search for a specific term using the case insensitive attribute:
5. Results from Your Search Should be Highlighted
Vim provides a handy function that emphasizes the file's search results. In the text editor, run the following command to activate highlighting:
: set hlsearch
6. Vim Search History
Vim maintains track of all the searches you've done so far in this session. Use the arrow keys to discover a prior search operation, hit / or? and move through the search history. Hit Enter to start the search. Before executing the procedure, you may also change the search pattern.
7. Look up the Current Word
You may also find a full word by dragging the cursor over it and hitting * (asterisk) to search forwards or # (hash) to look backward. Press * or # once more to discover the next matches.
Let's say you open the following file:
$ cat file.txt
Place the cursor on any word in normal mode, such as 168. To search for the next occurrence of the word 168, press * or # to search backward.
Hence in this article, we look at how to search in Vim using the forward Slash '/' and question mark '?'. Also, various other search techniques may help us easily find the specific search criteria or pattern in our document. Hence using these methods, you can easily find in Vim editor and get what you want. Vim is really user-friendly and very easy to use for the developers, and the search command can accelerate the search tasks that have to be performed in the Vim editor. Hence, this tutorial helped you understand the Vim editor's search functionality.
People Are Also Reading: