Skip to content

Instantly share code, notes, and snippets.

@hsawaji
Last active August 6, 2018 10:22
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 hsawaji/42a604c955929d26debc44d70885b4f7 to your computer and use it in GitHub Desktop.
Save hsawaji/42a604c955929d26debc44d70885b4f7 to your computer and use it in GitHub Desktop.
git grep with fzf on vim
" fzf git grep
command! -bang -nargs=+ Gitgrep call fzf#run({
\ 'source': 'git grep -n -I -i <args>',
\ 'sink': function('s:line_handler'),
\ 'dir': s:get_git_base_path(expand("%:p:h")),
\ 'up': '~40%',
\ 'options': '+m'
\ })
" .gitディレクトリがあるパスを取得する
function! s:get_git_base_path(current_dir) abort
if isdirectory(expand(a:current_dir . '/.git'))
return a:current_dir
else
let sp_dir = split(a:current_dir, '/')
call remove(sp_dir, -1)
return s:get_git_base_path('/' . expand(join(sp_dir, '/'))sn)
endif
endfunction
" 行が選択された時の動き
function! s:line_handler(line)
let keys = split(a:line, ':')
" path
exec 'e '. keys[0]
" line
exec keys[1]
normal! ^zz
endfunction
@hsawaji
Copy link
Author

hsawaji commented Aug 6, 2018

This is an old version.
There is the newest version the include more functions in the following link.
https://gist.github.com/hsawaji/a886e60101056264acc5b0bc6c91de94

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