4 ms·
Here is a way to bind autocomplete to TAB such that you still get TAB unless you are at the end of a word to complete. It's super convenient. function! Ins
by lindig 10y ago
Here is a way to bind autocomplete to TAB such that you still get TAB unless you are at the end of a word to complete. It's super convenient.
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
- Watabou 10y agoI made a plugin [1] similar to this which offers more options when you press the Tab key. For instance, if you're typing a file path, you get Ctrl-X Ctrl-f completion (vim's file path completion) instead of the regular keyword completion. And if you type a period (configurable) and press Tab in filetypes like C, Python, Ruby, etc, you get omni completion (vim's semi-intelligent completion, which offers methods on classes, looks in ctags files, etc). The great thing is that I was able to do this in less than 100 lines of code, and I love using it myself every day at work. Just goes to show that Vim has a pretty good completion system already and you don't need to use some bloated plugin system like YouCompleteMe or Neocomplete. [1]: https://github.com/ajh17/VimCompletesMe https://github.com/ajh17/VimCompletesMe
- azinman2 10y agoWhat's wrong with these others? I'm reacting to the word "bloat," which is frequently thrown around on HN. To me, generally bloat is probably a good thing, as it means additional functionality and nice-ites.
- muppetman 10y agoThere's also mu-complete[1] which is much like VimCompletes me - small and lightweight using only vim's built-in functionality. Doesn't work very well with vim < 7.3 (I haven't actually checked yours out, but I assume they're very similar in what they offer) [1]: https://github.com/lifepillar/vim-mucomplete https://github.com/lifepillar/vim-mucomplete
- tremendo 10y agoI got that one some time ago from https://github.com/garybernhardt/dotfiles/blob/master/.vimrc#L167 https://github.com/garybernhardt/dotfiles/blob/master/.vimrc... which offers several other useful functions and settings.
- grimgrin 10y agoIt's nice to point that out. It shows the binding for shift-tab, as well. function! InsertTabWrapper() let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\<tab>" else return "\<c-p>" endif endfunction inoremap <expr> <tab> InsertTabWrapper() inoremap <s-tab> <c-n>
- lifepillar 10y agoI had something like that in my vimrc for some time (snippet posted here: https://vimrcfu.com/snippet/222 https://vimrcfu.com/snippet/222), using omni-completion when set in the buffer and keyword completion otherwise. Then, I developed the idea into a plugin that retains the minimalistic spirit, but it's much more flexible: https://github.com/lifepillar/vim-mucomplete https://github.com/lifepillar/vim-mucomplete.