Skip to content

Instantly share code, notes, and snippets.

@jsatk
Created September 12, 2018 19:04
Show Gist options
  • Select an option

  • Save jsatk/a8994388ea9ecd9d1c273137072fa77a to your computer and use it in GitHub Desktop.

Select an option

Save jsatk/a8994388ea9ecd9d1c273137072fa77a to your computer and use it in GitHub Desktop.

Revisions

  1. jsatk created this gist Sep 12, 2018.
    20 changes: 20 additions & 0 deletions tab-or-complete.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    " Auto-Completion --------------------------------------------------------- {{{

    " Use TAB to complete when typing words, else inserts TABs as usual.
    function! Tab_Or_Complete(move_to_next_word) abort
    " If auto-complete menu is not open and we are in the middle of typing a
    " word OR if auto-complete menu is already open the `tab` cycles through
    " suggested completions.
    if pumvisible() || (col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w')
    return a:move_to_next_word
    else
    " If we aren't typing a word and we press `tab` simply do the normal `tab`
    " action.
    return "\<Tab>"
    endif
    endfunction

    inoremap <expr> <Tab> Tab_Or_Complete("\<C-N>")
    inoremap <expr> <S-Tab> Tab_Or_Complete("\<C-P>")
    " }}}