Skip to content

Instantly share code, notes, and snippets.

@joelklabo
Created May 5, 2011 22:52
Show Gist options
  • Save joelklabo/958143 to your computer and use it in GitHub Desktop.
Save joelklabo/958143 to your computer and use it in GitHub Desktop.
" Completion menu: completes based on text of current file, as well as other
" open buffers/windows. Use <Tab> to open the menu (or pick another key, see
" the last line), as well as to cycle between the different options. Use
" <Enter> or <Space> to use use option.
set complete=.,w,b
set completeopt=longest,menu,menuone,preview
function! AutoCompleteOnKey(key)
if pumvisible() " menu open, loop through choices
return "\<Down>"
else " menu not open, open conditionally
if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$'
return a:key
else
return "\<C-N>\<C-R>=pumvisible() ? \"\\<Down>\" : \"\"\<CR>"
end
end
endfunction
inoremap <silent> <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <silent> <expr> <Space> pumvisible() ? "\<C-y> " : "\<Space>"
inoremap <silent> <expr> <Tab> AutoCompleteOnKey("\<Tab>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment