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

39 visualizações
Pular para a primeira mensagem não lida

Aaron Bohannon

não lida,
30 de jan. de 2020, 13:43:4730/01/2020
para 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

não lida,
30 de jan. de 2020, 14:32:3730/01/2020
para 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

Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem