Skip to content

Instantly share code, notes, and snippets.

@miyakawataku
Created April 14, 2013 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyakawataku/5381972 to your computer and use it in GitHub Desktop.
Save miyakawataku/5381972 to your computer and use it in GitHub Desktop.
find & grep from Vim commandline
command! -nargs=1 Grep call s:Grep(<f-args>)
function! s:Grep(command)
let orig_grepprg = &l:grepprg
let &l:grepprg = substitute(a:command, '|', '\\|', 'g')
grep
let &l:grepprg = orig_grepprg
endfunction
@miyakawataku
Copy link
Author

Settings

Copy & paste the code to your ~/.vimrc.

Usage

You can specify a chain of unix commands as an argument which results "grep -n" style output. You can then manipulate the result using QuickFix commands, such as ":cn" and ":cp", just like the regular ":grep" command.

:Grep find src -name '*.java' | xargs grep -n 'BigDecimal\|BigInteger'

or

:Grep find src -name '*.java' -exec grep -n 'BigDecimal\|BigInteger' {} +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment