Vim plugin - customizable automatic command-line parameter set

I am writing my first vim plugin (viml + python). One command that the plugin has is GetStepCommand (), and it basically extracts data from a remote data source, I massage the data a bit and copy it to the buffer so that the user can start editing it. There is a parameter that the user must provide "GetStepsCommand", and this is the search path where the data is located, for example: / projects / procedure / step

Now this path can be long, and it is easy to miss something. Therefore, I wanted to implement my own tab completion for the parameter part. Vim is already engaged in automatic completion of the command by tabulation, but, of course, he cannot know how to complete the parameter (I will allow something myself).

But first, I need to know: - if / how I can intercept a keystroke in command mode - get / get the command line that the user is currently writing - check if it works in command line or insert / view mode - and finally return the updated command line (tab completed), so that the user can continue writing to ':' after pressing the key.

Any pointers, tips, articles, tutorials ... ie highly appreciated

+8
vim vim plugin
source share
1 answer

If the argument to your user command is the path to the file system, it is just a matter of adding -complete=file to your definition :command , for example:

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

You do not need to intercept keystrokes in command line mode (and you should not do this because it will lead to poor interactions with other plugins!). Vim offers other default replenishment (cp :help :command-complete ), even custom where the Vimscript function is called to determine the candidates for completion.

+6
source share

All Articles