Search multiple terms in Vim

 

Vim has support for extended regular expressions in its search. So, it is possible to search for multiple terms at the same time. This support for alternation using extended regular expressions is not present in Vi.

The operator that is suitable for this is \|. For example, to search for either NewWidth or NewHeight in the source:

/NewWidth\|NewHeight

Thanks to Edward for this tip! :-)

Note that if you have highlighting enabled, which is a very useful feature, all the matches will be highlighted with the same color. If you would like each term to be highlighted with a different color, try a plugin like multisearch.

Tried with: Vim 7.3

Agent Ransack: Search inside Office, PDF and other files

Windows 7 has a good search engine that can be used to search for text inside files. However, it requires indexing to be turned on for this feature. I do not like the indexing happening in the background nor do I like indexed information to be stored before I search for something.

If you are in the same boat as me, then give Agent Ransack a try. It can search for files that contain a certain text. It builds the index on the fly and does not store it for future use. It includes support for searching inside popular binary file formats like Microsoft Office, Libre Office and PDF.

Tried with: Agent Ransack (Release Build 762 – 2010.03.29.47911)

Firefox: Search from address bar using DuckDuckGo

The Firefox address bar can be used to type in keywords to query a search engine directly (see here). By default, the search engine used is Google. This can be changed to any search engine already installed in Firefox (see here). If you have fallen in love with the simplicity and security of searching using DuckDuckGo, then using it right from the address bar is worth the effort.

As of this writing, the DuckDuckGo search engine does not come pre-installed with Google. So, to be able to search from the address bar using DuckDuckGo requires 2 simple steps:

  1. Install the DuckDuckGo search engine into Firefox. There are a few variants of the search engine available here. I like to use the HTTP SSL version.
  2. Follow the same steps as for setting the default search engine (see here). The name string of this search engine (as of this writing) is DuckDuckGo, so type this in as the value for browser.search.defaultenginename

That is it, type in keywords in the address bar and let DuckDuckGo deliver the results for you! :-)

Tried with: Firefox 9.0.1

Firefox: Search from address bar

The address bar in Firefox is typically used to enter the correct URL of a website. However, if you type in keywords (not a URL) there, Firefox feeds them to a search engine and displays the results page. By default, the search engine it uses for this search is Google.

Since the address bar can be easily accessed using keyboard shortcuts, this is a quick way to search! And this is just as easy to use as the search bar. The real advantage is that you can remove the search bar while losing none of its functionality and thus save some precious horizontal space in the Firefox toolbar.

Tried with: Firefox 9.0.1

Search multiple terms with multiple colors in Vim

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:

:Msearch

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.

Eclipse: Find and Search

Eclipse is a strange beast. To search for a string, I was using the common Ctrl+F keyboard shortcut. This would pop up the familiar Find/Replace dialog. But soon, I was looking for a way to search through the entire project or workspace and could not find any way to do that using the Find/Replace dialog.

It turns out that there a larger, more complex Search feature in Eclipse! Why they would keep both Find and Search instead of combining them (like Visual Studio), that I cannot fathom. Ctrl+H is the default keyboard shortcut for this Search and indeed it shows up with custom searches for all the languages supported by Eclipse. (I use the PyDev Search, since I use Eclipse for Python code.)

The editor does not show the first matching search result (like in Find/Replace), but shows the Search results in a new Search window at the bottom. All in all, very odd business. But, at least I can now search through the entire project/workspace.