I've been using neovim for quite a while, but I'm looking to switch to a Lua config. I'm looking to use lazy.nvim, but I can't figure out why my plugin commands only get initialized when I configure keymaps in init and do not lazy load the plugin. I get this error when I try to close a window through the keymap.
E492: Not an editor command: LWCLose
Oddly, when I manually type :LWClose
, it works.
I have simplified the init.lua
so it will be easier to help me.
vim.g.mapleader = " "
vim.g.maplocalleader = ","
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
"cskeeters/vim-leave-window",
--lazy=false,
dependencies = {
"moll/vim-bbye"
},
-- This works when lazy=false
-- init = function()
-- vim.keymap.set('n', '<leader>w', ':LWClose<cr>', { noremap=true, silent=true, desc="Closes a buffer" })
-- vim.keymap.set('n', '<leader>gw', ':LWClose!<cr>', { noremap=true, silent=true, desc="Closes a buffer (Without Saving!)" })
-- end
-- When keys are configured this way, I get "E492: Not an editor command: LWCLose" when I type <leader>w
keys = {
{ "<leader>w", "<cmd>LWCLose<cr>", noremap=true, silent=true, desc = "Closes a buffer" },
{ "<leader>gw", "<cmd>LWCLose!<cr>", noremap=true, silent=true, desc = "Closes a buffer (Without Saving!)" },
}
}
})
vim.keymap.set('n', '<Leader>l', ':Lazy<cr>', { desc="Opens the Lazy Package Manager UI" })
Here is a link to my plugin. This plugin works fine in vim/neovim, just not with this particular configuration of lazy.nvim where the plugin is lazy loaded with the mappings performed via keys
.
https://github.com/cskeeters/vim-leave-window/blob/master/plugin/leave-window.vim#L20
I'm using NVIM v0.9.4 installed by brew
on macOS Sonoma 14.1 (23B74).