Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting multiple values for Vim command -complete attribute

Tags:

shell

vim

I am trying to enable command completion for a custom command that I am setting up for a plugin in the following manner:

command! -complete=shellcmd -nargs=* EScratch call s:ShellScratch(<f-args>)

I would like to enable complete options for shellcmd and file. However it seems that the complete attribute would only take 1 option.

To give a bit more context as to what I am trying to achieve: I am working on a plugin to create a simple scratch buffer. I would like to be able to run a shell command from the command mode and copy the output to the scratch buffer. I have been able to achieve all this but it would be much more productive to have auto completion similar to shell. The complete script can be viewed here https://github.com/ifthikhan/vimscratch/blob/master/plugin/vimscratch.vim. Any pointers will be highly appreciated.

like image 657
Ifthikhan Avatar asked Sep 03 '26 06:09

Ifthikhan


1 Answers

Unfortunately, you can't. If you really need this, you have to either

  • define two separate commands, e.g. :ScratchShell and :ScratchFile, with the corresponding completions, or
  • use a -complete=custom[list] and provide your own complete function, where you have to re-implement both sources yourself. Filename completion actually is quite easily done with glob(); I'm not so sure about shell commands.
like image 154
Ingo Karkat Avatar answered Sep 06 '26 11:09

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!