Use Tab for auto-completion

2 Points

Lifepillar Lifepillar

6 years ago

Use Tab to complete a word (with omnifunc if available, otherwise with <c-n>) or to move down when the completion pop-up menu is active. Use Shift-Tab to move up when in pop-up menu. Define b:tab_complete to override the default mapping for completion in a buffer (e.g., in SQL buffers you may want to let b:tab_complete = "\<c-c>a").

imap <expr><silent> <tab> pumvisible()
  \ ? "\<c-n>"
  \ : (col('.')>1 && (matchstr(getline('.'), '\%' . (col('.')-1) . 'c.') =~ '\S')
    \ ? get(b:, 'tab_complete', &omnifunc != '' ? "\<c-x>\<c-o>" : "\<c-n>")
    \ : "\<tab>"
    \ ) 

inoremap <expr><silent> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"

Durga Swaroop Perla

Durga Swaroop Perla 6 years ago

This is good. But is there a way to have the functionality of the regular tab as well? Perhaps a switch that turns this off or on.


Lifepillar 5 years ago

Type <c-v><tab> to insert a literal tab. See also: :h i_ctrl-v.