Calling omnicompletion for every keypress in vim

泪湿孤枕 提交于 2019-12-01 06:16:36

问题


I have a vim script that uses a one line window to get a filename pattern from the user. This pattern can be completed to a full filename from a database if you press CTRL-X CTRL-O. Now the only problem is that you have to press the auto completion shortcut by yourself. But I want the auto completion to work incrementally so that for every character you type it automatically gets updated (think about the CTRL-R file open dialog in Eclipse).

Is there a way to use an autocommand or some kind of callback to call the function behind CTRL-X CTRL-O for each character the user is typing in this particular window?


回答1:


Austin is on the right track, but just with the wrong event. Take a look at the CursorMovedI event of autocmd. Basically, it'll fire any time the keyboard cursor moves while in Insert mode. Type a character? Cursor moves, and the event is fired.

Keep in mind this is a bit heavy-handed for your use, because the cursor can move due to other things than typing or deleting characters. The user could use the arrow keys to move back where they want to edit. You'd be popping up the completion with every move.

I can't find anything in the help about window-local autocommands, but buffer-local exists, so that might be close enough.




回答2:


Try - and modify if necessary - this plugin: http://www.vim.org/scripts/script.php?script_id=1879

I'm a happy user.




回答3:


You should look at :h autocmd. I believe the InsertChange event could be used to do what you want.



来源:https://stackoverflow.com/questions/2591822/calling-omnicompletion-for-every-keypress-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!