Last active
August 6, 2018 10:22
-
-
Save hsawaji/42a604c955929d26debc44d70885b4f7 to your computer and use it in GitHub Desktop.
git grep with fzf on vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an old version.
There is the newest version the include more functions in the following link.
https://gist.github.com/hsawaji/a886e60101056264acc5b0bc6c91de94