public
Last active — forked from scrooloose/grep_menuitem.vim

nerdtree plugin to integrate nerdtree with :grep : Forked from http://gist.github.com/205807

  • Download Gist
grep_menuitem.vim
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
"shove this in ~/.vim/nerdtree_plugin/grep_menuitem.vim
"
"A really rough integration of :grep with nerdtree. Adds a 'g' menu item that
"prompts the user for a search pattern to use with :grep. :grep is run on the
"selected dir (using the parent if a file is selected)
"
" Originally written by scrooloose
" (http://gist.github.com/205807)
 
if exists("g:loaded_nerdtree_grep_menuitem")
finish
endif
let g:loaded_nerdtree_grep_menuitem = 1
 
call NERDTreeAddMenuItem({
\ 'text': '(g)rep directory',
\ 'shortcut': 'g',
\ 'callback': 'NERDTreeGrep' })
 
function! NERDTreeGrep()
let dirnode = g:NERDTreeDirNode.GetSelected()
 
let pattern = input("Enter the search pattern: ")
if pattern == ''
echo 'Aborted'
return
endif
 
"use the previous window to jump to the first search result
wincmd w
 
"a hack for *nix to make sure the output of "grep" isnt echoed in vim
let old_shellpipe = &shellpipe
let &shellpipe='&>'
 
try
exec 'silent cd ' . dirnode.path.str()
exec 'silent grep -rn ' . pattern . ' .'
" exec 'silent grep -rn ' . pattern . ' ' . dirnode.path.str()
finally
let &shellpipe = old_shellpipe
endtry
 
let hits = len(getqflist())
if hits == 0
echo "No hits"
elseif hits > 1
copen
" echo "Multiple hits. Jumping to first, use :copen to see them all."
endif
 
endfunction

Looks exactly what I have been looking for, but can't make it work. Hmm - folder path ~/.vim/nerdtree_plugin/: My Nerd-tree is located somewhere else. I tried putting the file here as well. Anything else I have to do to initialise it?

Nothing happens at the moment when opening Nerd-tree and pressing 'g' ...

@nikolajhave Try [vim-install-dir]/vimfiles/nerdtree_plugin/. However I'm using forked version of vim (Kaoriya's one, which is suitable for Japanese encoding) on Windows7, it might just be special directory for this version. But just try.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.