Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Vim omnicomplete on certain characters instead of Ctrl-X Ctrl-O?

In Vim 7, Ctrl-X Ctrl-O shows a list of possible values but I find this sequence of keys to be too long when I frequently use the autocomplete feature. For instance, in an HTML file, I'd like to see the list automatically popup after I type a < followed by one or two letters. In a CSS file, I'd like to see the list after I hit the ":" key. Is there a way to set this up?

like image 846
geoffeg Avatar asked Jul 01 '10 18:07

geoffeg


2 Answers

To activate the omnicompletion on typing a ":" you can use the following mapping.

imap : :<c-x><c-o>

The disadvantage is that each time you press ":" omnicompletion will be activated, even when typing ":" in comments or in any other context in which you do not want omnicompletion.

I have mapped ctrl-space to active omnicompletion:

imap <c-space> <c-x><c-o>

This gives me the choice to activate omni whenever I need it.

like image 151
Habi Avatar answered Nov 17 '22 12:11

Habi


Another alternative that I found easier is just to press tab two times when you want autocomplete, and one time for regular tab. Add the following line to your ~/.vimrc

imap <tab><tab> <c-x><c-o>
like image 32
alfonsodev Avatar answered Nov 17 '22 11:11

alfonsodev