Tip 110 | Customize the grep Program |
Vim’s :grep command is a wrapper for the external grep program. We can customize the way that Vim delegates this task by manipulating two settings: ‘grepprg’ and ‘grepformat’. First we’ll examine the defaults, and then we’ll see how tweaking them allows us to outsource the search task to any other suitable program.
Vim’s Default grep Settings
The ‘grepprg’ setting specifies what to run in the shell when Vim’s :grep command is executed ('grepprg'ⓘ). The ‘grepformat’ setting tells Vim how to parse the output returned by the :grep command (see 'grepformat'ⓘ). On Unix systems, the defaults are these:
| grepprg="grep -n $* /dev/null" |
| grepformat="%f:%l:%m,%f:%l%m,%f %l%m" |
The $* symbol used in the ‘grepprg’ ...
Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.