Skip to content

Commit

Permalink
🧑🧑 add YankHistoryYank
Browse files Browse the repository at this point in the history
  • Loading branch information
yazgoo committed Aug 27, 2021
1 parent 0b73190 commit ca84035
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/yank-history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ COMMANDS *yank-history-commands*
grep within yank history via FZF and paste the content of the file matching
the search pattern

:YankHistoryRgYank[!] *:YankHistoryRgYank*
grep within yank history via FZF and add the content in yank register


vim:tw=78:ts=8:ft=help:norl:
22 changes: 21 additions & 1 deletion plugin/yank-history.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ let g:yank_history_max_size = 20
let s:yank_history_script_dir = expand('<sfile>:p:h')
let s:yank_history_last=""

function! s:get_file_contents(line)
return join(readfile(split(a:line, ':')[0], 'b'), "\n")
endfunction

function! s:yank_history_paste(line)
execute 'normal! o' . join(readfile(split(a:line, ':')[0], 'b'), "\n")
execute 'normal! o' . s:get_file_contents(a:line)
endfunction

function! s:yank_history_yank(line)
let @@ = s:get_file_contents(a:line)
endfunction

function! YankHistoryYank()
Expand Down Expand Up @@ -88,3 +96,15 @@ command! -bang -nargs=* YankHistoryRgPaste
\ 'sink': function('s:yank_history_paste')
\ },
\ <bang>0)

""
" grep within yank history via FZF and add the content
" in yank register
command! -bang -nargs=* YankHistoryRgYank
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>).' '.g:yank_history_dir, 0,
\ {
\ 'options': ["--prompt", "> ", "--preview", s:yank_history_script_dir .'/../../fzf.vim/bin/preview.sh {}'],
\ 'sink': function('s:yank_history_yank')
\ },
\ <bang>0)

0 comments on commit ca84035

Please sign in to comment.