Thursday, January 30, 2020

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

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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200130193139.GC4379%40phoenix.

No comments: