Skip to content

Instantly share code, notes, and snippets.

@gworley3
Created May 8, 2013 14:57
Show Gist options
  • Save gworley3/5541029 to your computer and use it in GitHub Desktop.
Save gworley3/5541029 to your computer and use it in GitHub Desktop.
an ack menuitem for nerdtree; requires ack plugin for vim
if exists("g:loaded_nerdtree_ack_menuitem")
finish
endif
let g:loaded_nerdtree_ack_menuitem = 1
if !executable("ack")
finish
endif
call NERDTreeAddMenuItem({
\ 'text': '(s)earch directory with ack',
\ 'shortcut': 's',
\ 'callback': 'NERDTreeAckMenuItem' })
function! NERDTreeAckMenuItem()
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 'Ack -H --nocolor --nogroup -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 May 8, 2013

like my grep_menuitem.vim, this also support having spaces in the filenames, which is a common thing on systems like mac os x

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