PracticalVim Tip109 - yszheda/wiki GitHub Wiki

Table of Contents

Tip 109: Customize the grep Program

Return to the top: <>

Vim's Default grep Settings

  • 'grepprg' setting specifies what to run in the shell when Vim's `:grep` command is executed.

References:

  • 'grepformat' setting tells Vim how to parse the output returned by the `:grep` command.

References:

  • Default settings on Unix systems:
* The $* symbol used in the 'grepprg' setting is a placeholder, which is replaced with any arguments supplied to the :grep command. * The special tokens used in the 'grepformat' string are the same as those used by 'errorformat'.

* `%f` matches the filename * `%l` matches the line number * `%m` matches the text on that line

Make `:grep` Call ack

Make ack Jump to Line and Column

  • `%c` matches the column number

Alternative grep Plugins

  • grep uses POSIX regular expressions, whereas ack uses Perl regular expressions.
  • ack.vim and fugitive.vim create custom commands rather than overriding the :grep command, they can all coexist without conflict.
⚠️ **GitHub.com Fallback** ⚠️