From 7d929b96e2588fe9710ad795402eaead1aa0f70f Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 5 Jul 2021 19:49:06 +0200 Subject: [PATCH] fix: make which-key's lazy loading work when it is also lazy-loaded --- lua/which-key/init.lua | 12 +++++++++++- plugin/which-key.vim | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/which-key/init.lua b/lua/which-key/init.lua index 492c62f..ddb2604 100644 --- a/lua/which-key/init.lua +++ b/lua/which-key/init.lua @@ -6,6 +6,11 @@ local M = {} function M.setup(options) require("which-key.config").setup(options) + if vim.v.vim_did_enter == 0 then + vim.cmd([[au VimEnter * ++once lua require("which-key").load()]]) + else + M.load() + end end function M.execute(id) @@ -42,7 +47,9 @@ function M.show_command(keys, mode) mode = mode or "n" keys = Util.t(keys) if not Util.check_mode(mode) then - Util.error("Invalid mode passed to :WhichKey (Dont create any keymappings to trigger WhichKey. WhichKey does this automaytically)") + Util.error( + "Invalid mode passed to :WhichKey (Dont create any keymappings to trigger WhichKey. WhichKey does this automaytically)" + ) else M.show(keys, { mode = mode }) end @@ -63,6 +70,9 @@ end -- Load mappings and update only once function M.load() + if loaded then + return + end require("which-key.plugins").setup() require("which-key.colors").setup() Keys.register({}, { prefix = "", mode = "n" }) diff --git a/plugin/which-key.vim b/plugin/which-key.vim index 585d67f..2d14bfa 100644 --- a/plugin/which-key.vim +++ b/plugin/which-key.vim @@ -1,2 +1 @@ command! -nargs=* WhichKey lua require('which-key').show_command() -au VimEnter * ++once lua require("which-key").load()