-
I'm trying to load Packer itself lazily. My spec looks like the following: local function init_packer()
vim.cmd('packadd packer.nvim')
require('packer').startup({
function(use)
use { 'wbthomason/packer.nvim', opt = true }
end,
config = {
compile_path = vim.fn.stdpath('data') .. '/plugin/packer_compiled.lua',
}
})
end It's working ok, but when I open -- Automatically generated packer.nvim plugin loader code
if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then
vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"')
return
end
vim.api.nvim_command('packadd packer.nvim')
... As I understand it, that defeats the purpose of lazy loading Packer. Is that the intended behavior or am I missing something here? Should I create an issue? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I've come to the conclusion that it is intended behavior, because Packer has to be present in Anyway, what I'm doing right now is setting up the commands myself and only calling local function init_packer()
vim.cmd('packadd packer.nvim')
require('packer').startup({
function(use)
use { 'wbthomason/packer.nvim', opt = true }
-- ...
end,
config = {
compile_path = vim.fn.stdpath('data') .. '/site/plugin/packer_compiled.lua',
}
})
end
local function lazy_packer()
return setmetatable({}, {
__index = function(_, key)
init_packer()
return require('packer')[key]
end,
__newindex = function(_, key, value)
init_packer()
require('packer')[key] = value
end,
})
end
_G._lazy_packer = lazy_packer()
vim.api.nvim_exec([[
command! -nargs=* -complete=customlist,v:lua._lazy_packer.plugin_complete PackerInstall lua _lazy_packer.install(<f-args>)
command! -nargs=* -complete=customlist,v:lua._lazy_packer.plugin_complete PackerUpdate lua _lazy_packer.update(<f-args>)
command! -nargs=* -complete=customlist,v:lua._lazy_packer.plugin_complete PackerSync lua _lazy_packer.sync(<f-args>)
command! PackerClean lua _lazy_packer.clean()
command! PackerCompile packadd packer.nvim | lua _lazy_packer.compile()
command! -nargs=+ -complete=customlist,v:lua._lazy_packer.loader_complete PackerLoad | lua _lazy_packer.loader(<q-args>)
]], false) |
Beta Was this translation helpful? Give feedback.
I've come to the conclusion that it is intended behavior, because Packer has to be present in
runtimepath
in order to load other plugins. Also, I think lazy loading Packer isn't that big of an advantage, as it doesn't set up anything unless I callpacker.startup()
.Anyway, what I'm doing right now is setting up the commands myself and only calling
packer.startup()
when I run one of them. The relevant part of my Packer config is below.