Tuesday, February 17, 2015

How to use :helpgrep in Vim

Vim’s quickfix mode, in case you weren’t already familiar with it, is meant to assist error correction in a situation involving compilers and error messages. You can save compiler errors to a file and have Vim list each one, with line numbers, the easier to jump to it. Errors show up in the quickfix window (a horizontal split below whatever you were already working on).

Vim also has :grep (and :vimgrep) commands. These use the OS’s grep or grep equivalent (or Vim’s own “internal grep”) to find patterns (search patterns) in a file. They can make use of the same window:

Related to these commands is a cool one, :helpgrep, which is (as its name might suggest) a grep dedicated to searching Vim’s help. It’s simple to use—unlike other grep commands, it doesn’t require a filename, and instead searches all of the various Vim help files for whatever pattern you give it.

The cpoptions option can be (is) a tad mysterious. It’s one of the option strings (like concealcursor, which we discuss in the book), and each character in the string stands for a bit of vi behavior which Vim will support. To see each time that cpoptions is referred to in a help entry, we could run this:

:helpgrep cpoptions

(It’s important to note that in this example, “cpoptions” is a pattern—a Vim regex pattern—even despite the lack of escaped or special characters here.)

When I run the command, I am taken to line 810 of the help file for TwitVim (since I’ve installed that plugin and its help file has been added to my Vim). This is printed on the command line:

(1 of 17): like 'magic' is set and 'cpoptions' is empty. (Essentially, this is

That’s the line that the cursor was put on (810 of the help file).

From here, we can navigate through results using quickfix commands. (As in the Vim help, the bracketed parts of the commands are optional; you can enter just the non-bracketed part to save time.)

:cfir[st] (needs the ir to distinguish it from :cf, which is for :cfile, an error-related command)
:cla[st] (needs the a to distinguish it from :cl, which is for :clist)

:cl shows all of the results in “list” format (rather like :messages shows messages).

Notice the last one. When we’re running :helpgrep, :cw can open all of the results in a jump-enabling (and search-enabling!) window: the quickfix window.

Each entry (as you can see from the illustration) shows the name of the help file it’s in, the line and column numbers, and then the relevant line.

To jump to an entry, just hit Enter. The usual navigation commands apply in this buffer, too: you can j and k your way around if you wish, but also do not forget / and the power of Search To Navigate™!


  1. An operating system is the most important software that runs on a computer(UNIX Training in Chennai). It manages the computer's memory, processes, and all of its software and hardware. Using a highly secured and effective operating systems are always wanted by the consumers(Unix Shell Scripting Training in Chennai). You hae said that crystal clear in your content above. Thanks for sharing this in here.
    UNIX Training in Chennai | UNIX Certification

  2. CIIT Noida provides Best MCA Courses in Noida based on the current

    IT industry standards that help students to get high paying jobs in Top MNCs. CIIT provides Best MCA Training in Noida, Greater Noida, and Ghaziabad.

    CIIT is one of the trusted MCA training institutes in Noida providing practical knowledge and 100% job assistance with basic as well as advanced

    level MCA subjects. CIITN is the best MCA college in Noida, greater noida, ghaziabad, delhi, gurgaon regoin.

    At CIIT MCA classes in Noida is conducted by subject experts corporate professionals with 9+ years of experience in managing real-time and live

    projects. Sofracle Nano Specialized MCA classes Noida is the perfect blend of academic learning and practical sessions to provide maximum exposure to

    students that transform an average student into a corporate professional whom companies prefer to hire.

    Best MCA College in Noida