From 6902f6bc1cdde530c2b335e4b4ebc7745d18c34b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 24 Nov 2017 01:07:14 +0900 Subject: [PATCH] [[B]Commits] CTRL-Y to yank commit hashes to register Close #516 --- autoload/fzf/vim.vim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 9f83e6c..89537f9 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1043,16 +1043,29 @@ endfunction " ------------------------------------------------------------------ " Commits / BCommits " ------------------------------------------------------------------ +function! s:yank_to_register(data) + let @" = a:data + silent! let @* = a:data + silent! let @+ = a:data +endfunction + function! s:commits_sink(lines) if len(a:lines) < 2 return endif + let pat = '[0-9a-f]\{7,9}' + + if a:lines[0] == 'ctrl-y' + let hashes = join(filter(map(a:lines[1:], 'matchstr(v:val, pat)'), 'len(v:val)')) + return s:yank_to_register(hashes) + end + let diff = a:lines[0] == 'ctrl-d' let cmd = s:action_for(a:lines[0], 'e') let buf = bufnr('') for idx in range(1, len(a:lines) - 1) - let sha = matchstr(a:lines[idx], '[0-9a-f]\{7,9}') + let sha = matchstr(a:lines[idx], pat) if !empty(sha) if diff if idx > 1 @@ -1098,8 +1111,8 @@ function! s:commits(buffer_local, args) \ 'sink*': s:function('s:commits_sink'), \ 'options': ['--ansi', '--multi', '--tiebreak=index', '--reverse', \ '--inline-info', '--prompt', command.'> ', '--bind=ctrl-s:toggle-sort', - \ '--header', ':: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort', - \ '--expect='.expect_keys] + \ '--header', ':: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort, '.s:magenta('CTRL-Y', 'Special').' to yank commit hashes', + \ '--expect=ctrl-y,'.expect_keys] \ } if a:buffer_local