0

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).

3
  • You are already using an autoload-aware plugin. Why do you need lazy loading? Commented Nov 4, 2023 at 15:18
  • I don't need lazy loading for this plugin, but I might benefit from lazy loading for one of my other more CPU-intensive plugins and I'm trying to come up with a convention that I can use for all of my plugins. Surely lazy loading is a first-class feature in a plugin manager named lazy.nvim. It would feel awkward to bail on it right out of the gate. Commented Nov 4, 2023 at 15:47
  • Vim already goes to pretty decent efforts to load things lazily (hence autoload). If you have a plugin that impacts start up time to the point that you want to delay loading it, consider fixing it :) otoh, for this particular issue the lazy vim devs might be able to help
    – D. Ben Knoble
    Commented Nov 4, 2023 at 20:55

0

Your Answer

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

Browse other questions tagged or ask your own question.