Vim 插件 - 在命令模式下自定义自动完成参数 [英] Vim plugin - custom auto-complete of params in command-mode

查看:29
本文介绍了Vim 插件 - 在命令模式下自定义自动完成参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写我的第一个 vim 插件(viml + python).该插件具有的一个命令是GetStepCommand()",它基本上从远程数据源获取数据,我对数据进行了一点处理并将其复制到缓冲区中,以便用户可以开始编辑它.用户必须向GetStepsCommand"提供一个参数,即数据所在位置的搜索路径,例如:/projects/procedure/step

I'm writing my first vim plugin (viml + python). One command that the plugin has is "GetStepCommand()" and it basically fetches data from a remote data source, I massage the data a bit and copies it into the buffer so the user can start editing it. There is a parameter that the user has to supply to "GetStepsCommand" and that is the search path to where the data resides, for ex: /projects/procedure/step

现在这条路可能很长,而且很容易拼错.所以我想为参数部分实现我自己的制表符补全.Vim 已经负责通过 Tab 键自动补全命令,但当然它无法知道如何补全参数(这个我会自己解决).

Now that path can be long and its easy to miss-spell something. So I wanted to implement my own tab-completion for the parameter part. Vim already takes care of auto-completing the command by tabbing, but of course it can not have any knowledge about how to complete the parameter (something I'll solve myself).

但首先我需要知道:- 如果/如何我可以在命令模式下拦截按键- 获取/获取用户当前正在编写的命令行- 测试它是在命令模式还是插入/查看模式- 最后返回一个更新的命令行(制表符完成),用户可以在按键后继续在:"中书写.

But first I need to know: - if/how I can intercept the keypress in command-mode - fetch/get the command-line that the user currently is writing - test if it's in command-mode or insert/view-mode - and finally return an updated command-line (tab-completed) that the user can continue writing on in ':' after the keypress.

任何指示、技巧、文章、教程......即非常感谢信息

Any pointers, tips, articles, tutorials... i.e information is greatly appreciated

推荐答案

当自定义命令的参数是文件系统路径时,只需将 -complete=file 添加到您的:command 定义,像这样:

When the argument to your custom command is a file-system path, it's simply a matter of adding -complete=file to your :command definition, like this:

:command -nargs=1 -complete=file MyCommand echomsg <q-args>

你不需要在命令行模式下拦截按键(你不应该,因为这会导致与其他插件的不良交互!)Vim 提供其他默认完成(cp. :help :command-complete),甚至是调用 Vimscript 函数来确定完成候选的自定义函数.

You don't need to intercept keypresses in command-line mode (and you should not, for this would lead to bad interactions with other plugins!) Vim offers other default completions (cp. :help :command-complete), even a custom one where a Vimscript function is invoked to determine the completion candidates.

这篇关于Vim 插件 - 在命令模式下自定义自动完成参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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