From b337c6e0fc0a5c0c2e8125babded24ffcd544796 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sat, 9 Aug 2025 15:33:33 +0300 Subject: fix(pack): update `add()` to have default `load=false` during startup Problem: the `load=true` in `vim.pack.add()` means that `:packadd` is executed even during startup. This leads to force source of 'plugin/', which breaks the intended loading order (`:h load-plugins`) and results into sourcing them twice. This also makes it ignore `--noplugin` argument. Using `:packadd!` during startup is more appropriate, while `:packadd` afterwards is still more favorable to actually force 'plugin/' source (as there is no pre-defined mechanism that will load them later). Solution: have `load=false` default during startup, `true` - afterwards. --- runtime/lua/vim/pack.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/pack.lua') diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index 200f08e311..8069b5d947 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -669,7 +669,9 @@ end --- @class vim.pack.keyset.add --- @inlinedoc ---- @field load? boolean Load `plugin/` files and `ftdetect/` scripts. If `false`, works like `:packadd!`. Default `true`. +--- Load `plugin/` files and `ftdetect/` scripts. If `false`, works like `:packadd!`. +--- Default `false` during startup and `true` afterwards. +--- @field load? boolean --- Add plugin to current session --- @@ -693,7 +695,7 @@ end --- @param opts? vim.pack.keyset.add function M.add(specs, opts) vim.validate('specs', specs, vim.islist, false, 'list') - opts = vim.tbl_extend('force', { load = true }, opts or {}) + opts = vim.tbl_extend('force', { load = vim.v.vim_did_enter == 1 }, opts or {}) vim.validate('opts', opts, 'table') --- @type vim.pack.Plug[] -- cgit