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.

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:

Press n (in small letter) to search for next occurrences Press 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

Conclusion

In this tutorial, you have learned about searching in vim/vi text editor in Linux command line.

How to Search in Vim   Vi   TecAdmin - 42How to Search in Vim   Vi   TecAdmin - 96