Vim plugin - custom auto-complete of params in command-mode

旧街凉风 提交于 2019-12-22 04:20:25

问题


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

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


回答1:


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>

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.



来源:https://stackoverflow.com/questions/12636068/vim-plugin-custom-auto-complete-of-params-in-command-mode

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