Call omnicompletion for every keystroke in vim

I have a vim script that uses a single line window to get a file name template from a user. This template can be populated with the full file name from the database if you press CTRL-X CTRL-O. Now the only problem is that you have to press the autocomplete key yourself. But I want the automatic completion to work gradually so that every character you enter is automatically updated (think about opening the CTRL-R file dialog in Eclipse).

Is there a way to use an auto command or some kind of callback to call the CTRL-X function CTRL-O for each character that the user enters in this particular window?

+3
source share
3 answers

Austin is on the right track, but only with the wrong event. Take a look at the CursorMovedIevent autocmd. Basically, it fires at any time when the keyboard cursor moves in Insert mode. Enter a character? The cursor moves and the event fires.

Remember that this is a little hard for your use, because the cursor can move due to things other than entering or deleting characters. The user can use the arrow keys to move back where they want to edit. You will pop up completion with each step.

I can not find anything in the help about local auto-commands with a window, but there is a buffer-locale, so it can be quite close.

+2
source

You have to look :h autocmd. I believe that an event InsertChangecan be used to accomplish what you want.

0
source

Source: https://habr.com/ru/post/1740135/


All Articles