:vimgrep + :copen == :-)
As some people are already aware, for some time now I've been working on a new publishing framework for Guru Labs training materials. One of the major benefits of the change is that we can now use the world's most efficient text editor (Vim) to create our courseware.
While reviewing an import of our Sendmail and Postfix coverage, I noticed that the capitalization of each was inconsistent. Happily, scanning thousands of pages and fixing everything was faster than writing this blog entry.
Taking Postfix as an example, here's the problem: sometimes lower case is correct, sometimes uppercase is correct. When referring to a configuration file, service or RPM, lower case is correct. When referring to the project or collection of tools, upper case is correct. Sadly, no sed magic could get me through this one quickly.
My boss, Bryan Croft, is the local Vim guru. He showed me how to use :vimgrep to get a list of files containing a certain pattern. I wanted to find every instance of lower case "postfix" without a "." before it or a "/" after. In other words:
:vimgrep |[^.]postfix[^/]|g *
The results of a :vimgrep search are stored in the "quickfix" list. This list can be displayed in a second Vim window by
:copen
The nice thing about this list is that it shows each match in context. Instances that are obviously correct can be ignored. Pressing enter on an instance that looks incorrect will open the file in the original Vim window and move the cursor to the exact match. Because this is seperate from the highlighting done by a /sendmail I can concentrate on Postfix but have an active highlight to draw attention to Sendmail references nearby.
People insterested in learning more should also read:
:help quickfix :help lvimgrep :help lopen