Replace GitGrep with Ag

This commit is contained in:
Yan Pritzker
2014-02-15 21:08:32 -06:00
parent 5d72a8c5a4
commit 399d1d290a
8 changed files with 70 additions and 49 deletions

View File

@@ -1,24 +0,0 @@
"git grep the current word using K (mnemonic Kurrent)
nnoremap <silent> K :GitGrep <cword><CR>
function! GetVisual()
let reg_save = getreg('"')
let regtype_save = getregtype('"')
let cb_save = &clipboard
set clipboard&
normal! ""gvy
let selection = getreg('"')
call setreg('"', reg_save, regtype_save)
let &clipboard = cb_save
return selection
endfunction
"git grep visual selection
vnoremap K :<C-U>execute GitGrep(GetVisual())<CR>
"git grep current word up to the next exclamation point using ,K
nnoremap ,K viwf!:<C-U>execute GitGrep(GetVisual())<CR>
"grep for 'def foo'
nnoremap <silent> ,gd :GitGrep 'def <cword>'<CR>

View File

@@ -4,6 +4,3 @@ nnoremap <silent> <leader>q/ :execute 'vimgrep /'.@/.'/g %'<CR>:copen<CR>
" Ag for the last search.
nnoremap <silent> <leader>qa/ :execute "Ag! '" . substitute(substitute(substitute(@/, "\\\\<", "\\\\b", ""), "\\\\>", "\\\\b", ""), "\\\\v", "", "") . "'"<CR>
" GitGrep the last search (my own invention)
nnoremap <silent> <leader>qg/ :execute "GitGrep '" . substitute(substitute(substitute(@/, "\\\\<", "\\\\b", ""), "\\\\>", "\\\\b", ""), "\\\\v", "", "") . "'"<CR>

43
vim/settings/search.vim Normal file
View File

@@ -0,0 +1,43 @@
function! GetVisual()
let reg_save = getreg('"')
let regtype_save = getregtype('"')
let cb_save = &clipboard
set clipboard&
normal! ""gvy
let selection = getreg('"')
call setreg('"', reg_save, regtype_save)
let &clipboard = cb_save
return selection
endfunction
"git grep the current word using K (mnemonic Kurrent)
nnoremap <silent> K :Ag <cword><CR>
"git grep visual selection
vnoremap K :<C-U>execute Ag(GetVisual())<CR>
"git grep current word up to the next exclamation point using ,K
nnoremap ,K viwf!:<C-U>execute Ag(GetVisual())<CR>
"grep for 'def foo'
nnoremap <silent> ,gd :Ag 'def <cword>'<CR>
",gg = Grep! - using Ag the silver searcher
" open up a grep line, with a quote started for the search
nnoremap ,gg :Ag ""<left>
"Grep Current Partial
function! AgCurrentPartial()
let l:fileNameWithoutExtension = expand('%:t:r')
let l:fileNameWithoutUnderscore = substitute(l:fileNameWithoutExtension, '^_','','g')
let l:grepPattern = "render.*[\\\'\\\"].*" . l:fileNameWithoutUnderscore . "[\\\'\\\"]$"
exec 'Ag "' . l:grepPattern . '"'
endfunction
command! AgCurrentPartial call AgCurrentPartial()
"
nnoremap ,gcp :AgCurrentPartial<CR>
"Grep for usages of the current file
nnoremap ,gcf :exec "Ag " . expand("%:t:r")<CR>

View File

@@ -105,7 +105,7 @@ nmap <D-N> :NERDTreeToggle<CR>
" Open the project tree and expose current file in the nerdtree with Ctrl-\
nnoremap <silent> <C-\> :NERDTreeFind<CR>:vertical res 30<CR>
" ,q to toggle quickfix window (where you have stuff like GitGrep)
" ,q to toggle quickfix window (where you have stuff like Ag)
" ,oq to open it back up (rare)
nmap <silent> ,qc :cclose<CR>
nmap <silent> ,qo :copen<CR>
@@ -126,13 +126,6 @@ autocmd FileType javascript map <buffer> <D-j> {
map <D-/> :TComment<CR>
imap <D-/> <Esc>:TComment<CR>i
"GitGrep - open up a git grep line, with a quote started for the search
nnoremap ,gg :GitGrep ""<left>
"GitGrep Current Partial
nnoremap ,gcp :GitGrepCurrentPartial<CR>
"GitGrep Current File
nnoremap ,gcf :call GitGrep(expand("%:t:r"))<CR>
"Move back and forth through previous and next buffers
"with ,z and ,x

View File

@@ -83,8 +83,6 @@ Bundle "justinmk/vim-sneak"
"Search
Bundle "rking/ag.vim"
Bundle "skwp/vim-git-grep-rails-partial"
Bundle "tjennings/git-grep-vim"
Bundle "vim-scripts/IndexedSearch"
Bundle "nelstrom/vim-visual-star-search"