how can I configure plugins managed by vim's package manager?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how can I configure plugins managed by vim's package manager?

Aaron Bohannon
Hi,

I am running into a problem when trying to use vim's built-in package management system: since vim doesn't look for and run the plugins until after the .vimrc is executed, where am I supposed to put my configuration code that depends upon the functionality defined in my plugins?

For instance, the vim-operator-user plugin (https://github.com/kana/vim-operator-user/) defines a function "operator#user#define()". If I try to call the function in my .vimrc, vim will, at start-up, generate an error telling me that the function doesn't exist. However, I know that I have installed the plug-in properly because, if I re-run my .vimrc immediately after start-up (using the ":source" command), vim will find the function, call it, and not generate any errors. So, where am I supposed to put my code that calls "operator#user#define()"?

- Aaron

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/88a53227-bb3a-43f1-8ac2-ffe05616dbcd%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: how can I configure plugins managed by vim's package manager?

Gary Johnson-4
On 2020-01-30, Aaron Bohannon wrote:

> Hi,
>
> I am running into a problem when trying to use vim's built-in package
> management system: since vim doesn't look for and run the plugins until after
> the .vimrc is executed, where am I supposed to put my configuration code that
> depends upon the functionality defined in my plugins?
>
> For instance, the vim-operator-user plugin (https://github.com/kana/
> vim-operator-user/) defines a function "operator#user#define()". If I try to
> call the function in my .vimrc, vim will, at start-up, generate an error
> telling me that the function doesn't exist. However, I know that I have
> installed the plug-in properly because, if I re-run my .vimrc immediately after
> start-up (using the ":source" command), vim will find the function, call it,
> and not generate any errors. So, where am I supposed to put my code that calls
> "operator#user#define()"?

What I usually do is put a VimEnter autocommand in my vimrc that
tests for the existence of the plugin function or command I want to
use before calling or executing it.  For example, I have this for
configuring the Align plugin:

    autocmd VimEnter * if exists(":AlignCtrl") | AlignCtrl p0P0 | endif

Your code would look something like this:

    autocmd VimEnter * if exists("*operator#user#define)
                   \ |     call operator#user#define()
                   \ | endif

See also:

    :help VimEnter
    :help exists()

Alternatively, I have put code that requires a particular plugin in
~/.vim/after/plugin/<pluginname>.vim.  For example,
~/.vim/after/plugin/EnhancedDiff.vim contains this:

    if !exists(":PatienceDiff")
        finish
    endif

    PatienceDiff

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200130193139.GC4379%40phoenix.