vi (visual editor) is the best command line text file editor for Unix-like operating systems. Vim is an improved version of the vi text editor used on modern systems. This is a highly configurable text editor.
This tutorial will help you search for text, string or pattern in Vi(m) text editor.
How to Search in Vi(m) Editor
To start searching in the Vi(m) editor, first press the ESC key to switch to command mode in the editor. Then press “/” and then press the search text.
- Press ESC
- Type “/”
- Type the search pattern
- Press Enter or Return key perform search
This will move the cursor to the first match of the searched string. Then use the shortcut keys to navigate to the previous or next search string, as shown below:
n(in small letter) to search for next occurrences
N(in capital letter) to search for previous occurrences
Case Insensitive Search in Vim
Default vim searches for case sensitive matches. To search for pattern in all cases, you need to disable case using set command in vim.
Type the following command in vim to disable case sensitive searches.
Next, again do search for some text, you will find that search selection is ignoring the case.
You can revert the above changes by using
noignorecase with set command.
Now, vim will again do the case sensitive searches.
Search Whole World Only
You can also search for pattern matches whole world only. Which means the search do not matches substring of string.
View Search History
Vim keeps all the search history performed in current session. To view the previous searches, press / and use up and down keys
In this tutorial, you have learned about searching in vim/vi text editor in Linux command line.