在vim中为每个按键调用omnicompletion [英] Calling omnicompletion for every keypress in vim

查看:22
本文介绍了在vim中为每个按键调用omnicompletion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 vim 脚本,它使用单行窗口从用户那里获取文件名模式.如果您按 CTRL-X CTRL-O,则可以将该模式补全为数据库中的完整文件名.现在唯一的问题是您必须自己按自动完成快捷方式.但我希望自动完成以增量方式工作,以便为您键入的每个字符自动更新(想想 Eclipse 中的 CTRL-R 文件打开对话框).

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).

有没有办法使用自动命令或某种回调来为用户在此特定窗口中键入的每个字符调用 CTRL-X CTRL-O 后面的函数?

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?

推荐答案

Austin 走在正确的轨道上,但只是遇到了错误的事件.查看autocmdCursorMovedI 事件.基本上,只要在插入模式下键盘光标移动,它就会触发.输入字符?光标移动,事件被触发.

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.

这篇关于在vim中为每个按键调用omnicompletion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆