Question: Wrap optional plugins in an artificial one to reduce :packadd calls

7 views
Skip to first unread message

Sascha S

unread,
Dec 7, 2020, 9:24:17 PM12/7/20
to v...@vim.org
Hello Vimmers,

when multiple plugins are placed inside the opt directory of a package,
all this plugins will be shown as completions for the :packadd command.

E.g. I have created a package called LSP. Inside this package, there are
three optional plugins (vim-lsp, asyncomplete-lsp and asyncomplete).

.../pack/langserver/opt/vim-lsp
.../pack/langserver/opt/asyncomplete-lsp
.../pack/langserver/opt/asyncomplete

Considering I need the plugins. Then I would have to invoke :packadd for
each one of these and hope, that I won't forget any.
I think it would be of great use to group these plugins under a common
name and reduce the multiple :packadd calls to one, for this given name.
E.g. ":packadd lsp".


My current solution
-------------------

I group the plugins inside another directory named lsp. Then only this
directory (lsp) will be listed as a completion for :packadd.
Next I'll create under the lsp directory another directory called plugin
with a loadPlugins.vim file. These file has the following content:

packadd lsp/vim-lsp
packadd lsp/asyncomplete-lsp
packadd lsp/asyncomplete

This is required, as Vim will only look for *.vim files to be sourced by
:packadd, inside a plugin directory under the plugin-root-directory lsp.
(See first Note for packadd help.)


The previous directory structure will now look like this.

.../pack/langserver/opt/lsp/vim-lsp
.../pack/langserver/opt/lsp/asyncomplete-lsp
.../pack/langserver/opt/lsp/asyncomplete
.../pack/langserver/opt/lsp/plugin/loadPlugins.vim

When I invoke :packadd lsp<C-R>, Vim will source the loadPlugins.vim
file, which then start the sourcing of the grouped plugins.


With this workaround, I can load all three grouped plugins via one
:packadd call of the artifical enclosing plugin.

I'm considering to make use of it in some package manager.

My only question(s) left are:
-----------------------------

- Is the behaviour of calling
:packadd {ArtificialWrapPluginName}/{RealChildPluginName}
intention or a bug? As everything after / won't have completion
entries.
- Can I rely on this behaviour in the future?


Best wishes and stay healthy!

Sascha San Juan

Reply all
Reply to author
Forward
0 new messages