From fc69f27ae336d0d4259bf51664431fc925b989dd Mon Sep 17 00:00:00 2001 From: Michal Au Date: Tue, 11 Aug 2015 18:50:11 +0200 Subject: [PATCH] nerdtree grep + ctrlp --- .gitmodules | 3 +++ .vimrc | 2 +- bundle/ctrlp | 1 + grep_menuitem.vim | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 160000 bundle/ctrlp create mode 100644 grep_menuitem.vim diff --git a/.gitmodules b/.gitmodules index d851db8..f203ac0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "bundle/vim-airline"] path = bundle/vim-airline url = https://github.com/bling/vim-airline +[submodule "bundle/ctrlp"] + path = bundle/ctrlp + url = https://github.com/kien/ctrlp.vim.git diff --git a/.vimrc b/.vimrc index ba550a8..5636d4a 100755 --- a/.vimrc +++ b/.vimrc @@ -31,7 +31,7 @@ set hidden nnoremap m :bnext nnoremap n :bprevious nnoremap b :enew -nnoremap q :bp:bd # +nnoremap q :bp "firefox-like tab navigation nnoremap :tabnext diff --git a/bundle/ctrlp b/bundle/ctrlp new file mode 160000 index 0000000..b5d3fe6 --- /dev/null +++ b/bundle/ctrlp @@ -0,0 +1 @@ +Subproject commit b5d3fe66a58a13d2ff8b6391f4387608496a030f diff --git a/grep_menuitem.vim b/grep_menuitem.vim new file mode 100644 index 0000000..71cf6a7 --- /dev/null +++ b/grep_menuitem.vim @@ -0,0 +1,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