if exists('g:loaded_yankround')| finish| endif| let g:loaded_yankround = 1 let s:save_cpo = &cpo| set cpo&vim "============================================================================= let g:yankround_dir = get(g:, 'yankround_dir', '~/.cache/yankround') let g:yankround_max_history = get(g:, 'yankround_max_history', 30) let g:yankround_max_element_length = get(g:, 'yankround_max_element_length', 1048576) let g:yankround_use_region_hl = get(g:, 'yankround_use_region_hl', 0) let g:yankround_region_hl_groupname = get(g:, 'yankround_region_hl_groupname', 'YankRoundRegion') "====================================== nnoremap (yankround-p) :exe yankround#init('p')call yankround#activate() nnoremap (yankround-pop) :let g:_yankround_paste = 1exe yankround#init('p')call yankround#activate() nnoremap (yankround-P) :exe yankround#init('P')call yankround#activate() nnoremap (yankround-Pop) :let g:_yankround_paste = 1exe yankround#init('P')call yankround#activate() nnoremap (yankround-gp) :exe yankround#init('gp')call yankround#activate() nnoremap (yankround-gP) :exe yankround#init('gP')call yankround#activate() xnoremap (yankround-p) :exe yankround#init('p', 'v')call yankround#activate() xmap (yankround-P) (yankround-p) xnoremap (yankround-gp) :exe yankround#init('gp', 'v')call yankround#activate() xmap (yankround-gP) (yankround-gp) nnoremap (yankround-prev) :call yankround#prev() nnoremap (yankround-next) :call yankround#next() "============================================================================= let s:yankround_dir = expand(g:yankround_dir) if !(s:yankround_dir=='' || isdirectory(s:yankround_dir)) call mkdir(s:yankround_dir, 'p') end let s:path = s:yankround_dir. '/history' if filereadable(s:yankround_dir. '/cache') call rename(s:yankround_dir. '/cache', s:path) end let g:_yankround_cache = filereadable(s:path) ? readfile(s:path) : [] unlet s:path let g:_yankround_stop_caching = 0 let g:_yankround_paste = 0 "let s:append_yankcache_debug_count = 0 aug yankround autocmd! autocmd CursorMoved * call s:append_yankcache() autocmd ColorScheme * call s:define_region_hl() autocmd VimLeavePre * call s:_persistent() autocmd CmdwinEnter * call yankround#on_cmdwinenter() autocmd CmdwinLeave * call yankround#on_cmdwinleave() aug END function! s:append_yankcache() "{{{ "let s:append_yankcache_debug_count = s:append_yankcache_debug_count + 1 if g:_yankround_paste "echo 'paste' . s:append_yankcache_debug_count if 0 < len(g:_yankround_cache) call remove(g:_yankround_cache, 0, 0) end let @" = substitute(get(g:_yankround_cache, 0, ''), '^.\d*\t', '', '') let g:_yankround_paste = 0 return end if g:_yankround_stop_caching || @" ==# substitute(get(g:_yankround_cache, 0, ''), '^.\d*\t', '', '') || @"=~'^.\?$' \ || g:yankround_max_element_length!=0 && strlen(@")>g:yankround_max_element_length "echo 'skip' . s:append_yankcache_debug_count return end "echo 'insert' . s:append_yankcache_debug_count call insert(g:_yankround_cache, getregtype('"'). "\t". @") call s:new_dupliexcluder().filter(g:_yankround_cache) if len(g:_yankround_cache) > g:yankround_max_history call remove(g:_yankround_cache, g:yankround_max_history, -1) end call s:_persistent() endfunction "}}} function! s:define_region_hl() "{{{ if &bg=='dark' highlight default YankRoundRegion guibg=Brown ctermbg=Brown term=reverse else highlight default YankRoundRegion guibg=LightRed ctermbg=LightRed term=reverse end endfunction "}}} call s:define_region_hl() "============================================================================= let s:_dupliexcluder = {} function! s:new_dupliexcluder() "{{{ let _ = {'seens': {}} call extend(_, s:_dupliexcluder, 'keep') return _ endfunction "}}} function! s:_dupliexcluder.filter(list) "{{{ return filter(a:list, 'self._seen(v:val)') endfunction "}}} function! s:_dupliexcluder._seen(str) "{{{ if has_key(self.seens, a:str) return end if a:str!='' let self.seens[a:str] = 1 end return 1 endfunction "}}} "====================================== function! s:_persistent() "{{{ if g:yankround_dir=='' || g:_yankround_cache==[] return end call writefile(g:_yankround_cache, s:yankround_dir. '/history') endfunction "}}} "============================================================================= "END "{{{1 let &cpo = s:save_cpo| unlet s:save_cpo