Skip to content

Instantly share code, notes, and snippets.

@PeterRincker
Created January 3, 2018 00:20
Show Gist options
  • Save PeterRincker/3d79000c69bde9bc95789d47b100da1c to your computer and use it in GitHub Desktop.
Save PeterRincker/3d79000c69bde9bc95789d47b100da1c to your computer and use it in GitHub Desktop.
Complete abbreviations
" Completion for iabbrev's
" example:
" imap <c-x><c-x><c-a> <Plug>(complete-appbrev)
function! s:complete_abbrev()
let lst = split(execute('iabbrev'), '\n')
let lst = map(lst, 'split(v:val, ''\s\+'')[1:]')
let lst = map(lst, '{"word": v:val[0], "menu": substitute(join(v:val[1:], " "), ''^[@*]\s'', "", "")}')
let col = col('.')
let prefix = matchstr(getline('.')[0:col-2], '\k\+$')
if len(prefix)
let lst = filter(lst, 'len(prefix) <= len(v:val.word) && v:val.word[0:len(prefix)-1] == prefix')
let col = col - len(prefix)
endif
call sort(lst, {a,b-> a.word ==? b.word ? 0 : a.word > b.word ? 1 : -1})
call complete(col, lst)
return ''
endfunction
inoremap <Plug>(complete-appbrev) <c-r>=<SID>complete_abbrev()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment