2

Given a neovim setup with a plugin installed in .local/share/nvim/site/pack/<x>/start/. From what I understand from the (neo)vim runtimepath, that plugin will automatically be loaded (otherwise it should have been put in pack/<x>/opt/). So if I have config related to that plugin, should that be added to $XDG_CONFIG_HOME/nvim or in $XDG_CONFIG_HOME/nvim/after?

In my specific case, I have the nvim-lspconfig plugin installed and the following config is present in my $XDG_CONFIG_HOME/nvim/init.vim:

lua <<END
...
require('lspconfig').ccls.setup {
    ...
}
END

Doesn't this mean that neovim will load the nvim-lspconfig plugin while executing my init.vim config, even though nvim-lspconfig would have been loaded automatically by neovim anyway?

Would adding this config to after/ make it possible to execute it conditionally based on whether the plugin was loaded or not (in case it isn't installed on a different pc)?

2 Answers 2

1

Doesn't this mean that neovim will load the nvim-lspconfig plugin while executing my init.vim config, even though nvim-lspconfig would have been loaded automatically by neovim anyway?

Basically, a plugin is a collection of scripts. So what does "loading a plugin" really mean? As simple as expanding &runtimepath and sourcing everything under plugin/ subdirectory.

However, the Lua engine doesn't require &runtimepath expansion in order to find Lua modules under lua/ (and in last versions even Vim isn't strict anymore, so it's now allowed to call plugins' functions from autoload/ right from vimrc without delaying to after/ or VimEnter).

So the real point if it's okay to call plugin's exported functions before its plugin/ was sourced as part of startup or not. Also, another question if those functions are okay to call before full application init (i.e. VimEnter).

And so it may depend on particular plugin, but in many cases it's all right.

Would adding this config to after/ make it possible to execute it conditionally based on whether the plugin was loaded or not (in case it isn't installed on a different pc)?

after/ is not a "conditional directory". It's just (the last) node in &runtimepath. So one knows that after/plugin/ is sourced after plugin/ was sourced but nothing more. Thus if you need "a condition" you still have to add it yourself. But indeed after/ could be a good place for this.

Although remember that some plugins may not expect changing its settings at this point. Or, maybe, they need quite "expensive" default init on startup, and so doing it for the second time is not recommended.

IOW, if in doubt always look into both doc/ and plugin/ subdirectory. If during the startup a plugin only creates commands/mappings etc. (and this is the case for many and many of them) then you're totally free to do anything you like (except, you can't invoke those commands from your vimrc, of course).

1

even though nvim-lspconfig would have been loaded automatically by neovim anyway?

This assumption is incorrect. You're probably thinking of vim's autoload functionality. But that is not available for lua files. i.e., lua files do not get sourced at nvim's startup. Think of how you'd have to source a vim script with :h :runtime command; that's what :lua require is doing. In fact, you can replace :lua require(foo.bar) with :ru lua/foo/bar.lua.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.