Skip to content

Instantly share code, notes, and snippets.

@chemzqm
Created February 22, 2016 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemzqm/43fe9044df1eb37cdfd1 to your computer and use it in GitHub Desktop.
Save chemzqm/43fe9044df1eb37cdfd1 to your computer and use it in GitHub Desktop.
if exists('did_completes_me_loaded') || v:version < 700
finish
endif
let did_completes_me_loaded = 1
function! s:completes_me(shift_tab)
let dirs = ["\<c-p>", "\<c-n>"]
if get(b:, 'complete_disable', 0)
return a:shift_tab ? "\<S-Tab>" : "\<Tab>"
endif
if pumvisible()
if a:shift_tab
return dirs[0]
else
return dirs[1]
endif
endif
" Figure out whether we should indent.
let pos = getpos('.')
let substr = matchstr(strpart(getline(pos[1]), 0, pos[2]-1), "[^ \t]*$")
if strlen(substr) == 0 | return "\<Tab>" | endif
if a:shift_tab
return "\<c-p>"
else
return "\<c-n>"
endif
endfunction
inoremap <expr> <plug>completes_me_forward <SID>completes_me(0)
inoremap <expr> <plug>completes_me_backward <SID>completes_me(1)
imap <Tab> <plug>completes_me_forward
imap <S-Tab> <plug>completes_me_backward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment