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

39 views
Skip to first unread message

Aaron Bohannon

unread,
Jan 30, 2020, 1:43:47 PM1/30/20
to vim_use
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

Gary Johnson

unread,
Jan 30, 2020, 2:32:37 PM1/30/20
to vim_use
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

Reply all
Reply to author
Forward
0 new messages