Skip to content

Instantly share code, notes, and snippets.

@davidmh
Last active May 23, 2016 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmh/31a17a0aa40f929167781790e420ddc2 to your computer and use it in GitHub Desktop.
Save davidmh/31a17a0aa40f929167781790e420ddc2 to your computer and use it in GitHub Desktop.
vim-fugitive + vim-swoop
function! Cmd2QuickFix(command, prompt, use_swoop)
" use the current word as the default value
let default = expand("<cword>")
call inputsave()
let pattern = input(a:prompt, default)
call inputrestore()
if empty(pattern)
echo a:command . ' needs a pattern, see :h ' . a:command
else
exe 'silent ' . a:command . ' ' . pattern . ' | redraw!'
let qflist = getqflist()
let rows = len(qflist)
if a:use_swoop && rows < 15
" open all files on the quickfix list
let s:prev_val = ""
for d in getqflist()
let s:curr_val = bufname(d.bufnr)
if (s:curr_val != s:prev_val)
exec "edit " . s:curr_val
endif
let s:prev_val = s:curr_val
endfor
" start swoop with the original pattern
call SwoopMultiPattern(pattern)
else
" fallback into opening the quickfix window
cwindow
endif
endif
endfunction
command! CustomGgrep call Cmd2QuickFix("Ggrep", "git grep ", 1)
command! CustomGlog call Cmd2QuickFix("Glog -S", "git log -S ", 0)
" git grep the current word
nnoremap <leader>gg :CustomGgrep<CR>
" git log the current word
nnoremap <leader>gl :CustomGlog<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment