sgur
12/24/2015 - 4:49 AM

Insert completion for YankRound

Insert completion for YankRound

" YankRound complete
" Locate this at .vim/after/plugin/yankround_complete.vim

" Vim >= 7.4.774 (requires v:completed_item)
" Yankround is loaded
" This plugins hasn't been loaded
if !(v:version > 704 || has('patch-7.4.774')) || get(g:, 'loaded_yankround_complete', 0) || !get(g:, 'loaded_yankround', 0)
  finish
endif
let g:loaded_yankround_complete = 1

let s:save_cpo = &cpo
set cpo&vim


function! s:yankround_complete() "{{{
  let items = map(copy(g:_yankround_cache), 's:completion_item(v:val[0], v:val[2:])')
  let col = match(getline('.')[: -1], '\S\+$') + 1
  call complete(col > 0 ? col : col('$'), items)
  let s:yankround_complete_done = 1
  return ''
endfunction "}}}

function! s:completion_item(type_char, word) "{{{{
  let chars = strchars(a:word)
  let width = &columns / 2
  return { "word" : a:word
        \ , "abbr" : chars > width ? a:word[: width - 3] . "..." : a:word
        \ , "menu" : a:type_char is# "v" ? printf("%2d chars", chars) : printf("%2d lines", len(split(a:word, "\\n", 1)))
        \ }
endfunction "}}}

function! s:on_completedone_yankround() "{{{
  if !get(s:, 'yankround_complete_done', 0)
    return
  endif
  let s:yankround_complete_done = 0
  if empty(get(v:, 'completed_item', {}))
    return
  endif
  undojoin | execute 's/\%x00/\r/ge'
endfunction "}}}

augroup yankround_complete "{{{
  autocmd!
  autocmd CompleteDone *  call s:on_completedone_yankround()
augroup END "}}}

inoremap <Plug>(yankround-complete) <C-r>=<SID>yankround_complete()<CR>

if !hasmapto('<Plug>(yankround-complete)', 'i')
  imap <C-x><C-x> <Plug>(yankround-complete)
endif


let &cpo = s:save_cpo
unlet s:save_cpo