Skip to content

Instantly share code, notes, and snippets.

@gworley3
Forked from scrooloose/grep_menuitem.vim
Created June 8, 2011 19:41
Show Gist options
  • Save gworley3/1015196 to your computer and use it in GitHub Desktop.
Save gworley3/1015196 to your computer and use it in GitHub Desktop.
nerdtree plugin to integrate nerdtree with :grep (with support for spaces in file names)
if exists("g:loaded_nerdtree_grep_menuitem")
finish
endif
let g:loaded_nerdtree_grep_menuitem = 1
if !executable("grep")
finish
endif
call NERDTreeAddMenuItem({
\ 'text': '(g)rep directory',
\ 'shortcut': 'g',
\ 'callback': 'NERDTreeGrepMenuItem' })
function! NERDTreeGrepMenuItem()
let n = g:NERDTreeDirNode.GetSelected()
let pattern = input("Search Pattern: ")
if pattern == ''
return
endif
"use the previous window to jump to the first search result
wincmd w
let old_shellpipe = &shellpipe
try
"a hack for *nix to ensure the grep output isnt echoed in vim
let &shellpipe='&>'
exec 'silent grep -r ' . pattern . ' ' . '"' . n.path.str() . '"'
finally
let &shellpipe = old_shellpipe
endtry
let hits = len(getqflist())
if hits == 0
redraw
echo "No hits"
elseif hits > 1
copen
wincmd p
endif
endfunction
@gworley3
Copy link
Author

gworley3 commented Jun 8, 2011

Fork to add support for spaces in file names.

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