Vim Omnicomplete Autocomplete item selection issue

594 Views Asked by At

I am using vim with Omnicomplete. Right now when I type something I get a list of valid option as shown in the image link Vim Working WIth Omnicomplete

However as you can see none of the options are highlighted in the dropdown menu by default. I have to manually use arrow button to select an item and then press CTRL-Y to finish the selection. What I would like it to do is automatically highlight the item closely matching the word I am typing so I have to only press CTRL-Y without using the arrow keys every time if not necessary. Also how can I avoid adding a new line when pressing enter to select the item from the drop down list? Thank you.

Edit: I should mention that my drop down menu appears automatically without manually pressing CTRL-N. So what I am thinking is how can I detect that pumvisible() is active and if it is active I simulate <Down> button once. Something like

autocmd if pumvisible() then \<Down>

I don't know the exact syntax but something along this line should work? I will appreciate any advise regarding this.

1

There are 1 best solutions below

1
romainl On

Here is the mapping I use to obtain exactly your desired behavior:

inoremap ,, <C-x><C-o><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>" : ""<CR>