Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Search multiple terms in Vim using multisearch plugin

📅 2010-Apr-15 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ plugin, search, vim ⬩ 📚 Archive


Today I was trying to look up the occurrence of either of 3 terms in a huge log file. I had the text file open in Vim and wanted to hop to the occurrences of either term. I could have grepped the file, but highlighting of the search terms and having the ability to peek around the occurrence of these terms was important to me.

I was able to do this using the multisearch plugin. This is the latest in a series of Vim plugins written for this purpose by several authors over the years. The multisearch plugin is offered as a vimball file and can be downloaded from the bottom of the plugin page. There are 2 versions available, pick the Unix version if you are on Linux, pick the other one if you are on Windows. For help with installing a vimball, see this post.

Once multisearch is installed, open up the text file you want to search. To search for the occurrence of 3 terms, say Amar, Akbar and Anthony use:

:Msearch add /Amar/
:Msearch add /Akbar/
:Msearch add /Anthony/

You will find each of these search terms highlighted with different colors across your text file. Very nice!

To hop to the next occurrence of any of these terms in sequence use repeatedly:


Note that if you do not mind your multiple search terms being highlighted with the same color, then you need no plugin. Such a search capability is built into Vim. See this post for more information.

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧