This whole time I had no idea vim could autocomplete
This is classic "string-based" autocomplete. It completes based on strings it knows about but doesn't take into account the context. I've used for years but yesterday I realized that since Vim version 7 there's a more intelligent kind of autocomplete triggered by C-x C-o that is context-aware. It can complete object methods, HTML tag attribtes, CSS properties, etc. For info: :help new-omni-completion
Built-In Vim Autocomplete
21–30 of 30 posts
Re: Built-In Vim Autocomplete
#22Long time emacs user here. I had an aha moment yesterday, when after several months of using God mode I said "I should rebind C-t to generic transpose and use a follow-up key to specify char, word, sexp, etc." If I understand correctly, this is sort of how VIM works. I want to try EVIL now. Anyone here that's made the switch in this direction and can talk about it?
Re: Built-In Vim Autocomplete
#23Here 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 "\ " else return "\ " endif endfunction inoremap =InsertTabWrapper()
Re: Built-In Vim Autocomplete
#24Re: Built-In Vim Autocomplete
#25Here 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 "\ " else return "\ " endif endfunction inoremap =InsertTabWrapper()
I 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 cla…
Re: Built-In Vim Autocomplete
#26Here 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 "\ " else return "\ " endif endfunction inoremap =InsertTabWrapper()
I 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 cla…
Re: Built-In Vim Autocomplete
#27Vim's built-in autocomplete is the only autocomplete I use. Does anyone know why I should use something else?
Re: Built-In Vim Autocomplete
#28Long time emacs user here. I had an aha moment yesterday, when after several months of using God mode I said "I should rebind C-t to generic transpose and use a follow-up key to specify char, word, sexp, etc." If I understand correctly, this is sort of how VIM works. I want to try EVIL now. Anyone here that's made the switch in this direction and can talk about it?
I think the biggest thing to accept is that you will not be proficient with your editor for quite a long time. I recommend practicing with vim tutorials until it feels reasonably good before taking the plunge entirely. One very important thing is to keep looking for efficient ways to work with it. It's a bit like emacs in that if you ever think, "Oh, this is just painful. There must be a better way", then there is almost guaranteed to be a better way. Stop, find out what it is. Practice it.
My last piece of advice is that vim-style editing is a little bit different that emacs-style editing (at least for me). With emacs, I find that I memorise keybindings and practice using them. With vim, it's much more about the context -- when you are in situation X, you do this kind of thing. So it needs more practice (again IMO). However, once you have your brain oriented (orientated? :-) ), there is this sense of freedom. You are working with larger blocks of abstraction, rather than just the character level. Some people feel this is more efficient (i.e. faster), but I'm not sure. For me it's rather that it is closer to what I'm actually thinking when I'm programming. YMMV and I should warn you again that it takes considerable practice to get to the point where it starts to feel good.
Re: Built-In Vim Autocomplete
#29Here 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 "\ " else return "\ " endif endfunction inoremap =InsertTabWrapper()
I got that one some time ago from https://github.com/garybernhardt/dotfiles/blob/master/.vimrc... which offers several other useful functions and settings.
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\"
else
return "\"
endif
endfunction
inoremap InsertTabWrapper()
inoremap Re: Built-In Vim Autocomplete
#30What is xctrl?
You mean `Ctrl-xCtrl-f`? That's `Ctrl-x Ctrl-f`. In terms of how it parses, after `Ctrl-`, the next token must be a single character (a key) is accepted. So `Ctrl-x` completes that particular accord and `Ctrl-f` is the accord following it.