Created
December 24, 2015 04:49
-
-
Save sgur/67e8b22b6c86b873da42 to your computer and use it in GitHub Desktop.
Insert completion for YankRound
This file contains hidden or 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
" 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment