最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

neovim Lazy load local pluguin with cmd returns: Command `Test` not found after loading `test` - Stack Overflow

programmeradmin3浏览0评论

I have created a minimal Neovim configuration (Test) that only includes the plugin and the lazy.nvim setup.

The local neovim plugin Test loads with lazy.nvim using Lazy-load on command: cmd = "Test".

After loading the command with :Test, i get Command Test not found after loading test.

This is the module:

local M = {}

function M.test()
    local variable = vim.ui.input({ prompt = "Enter value: " }, function(str)
        return str
    end)
    print(variable)
end

return M

This is the Lazy configuration:

local map_test = {
    ["<leader>T"] = {
        mode = { "n" },
        name = "Test",
        ["t"] = {
            function()
                require("test").test()
            end,
            "Test",
        },
    },
}

return {
    name = "test",
    cmd = "Test",
    dir = "~/.config/nvim/lua/plugins-my/test.nvim",
    config = function()
        local wk = require("which-key")
        wk.register(map_test)
    end,
}

Added the structure of the lua directory as suggested by KamilCuk:

├── config
├── plugins-active
├── plugins-inactive
├── plugins-my
│   ├── motli.nvim
│   │   ├── lua
│   │   │   └── motli
│   │   └── plugin
│   ├── presenta.nvim
│   │   ├── lua
│   │   │   └── presenta
│   │   └── plugin
│   └── test.nvim
│       ├── lua
│       └── plugin
└── util

While the plugin is loaded and working, I wonder how to get around the message.

Thanks!

I have created a minimal Neovim configuration (Test) that only includes the plugin and the lazy.nvim setup.

The local neovim plugin Test loads with lazy.nvim using Lazy-load on command: cmd = "Test".

After loading the command with :Test, i get Command Test not found after loading test.

This is the module:

local M = {}

function M.test()
    local variable = vim.ui.input({ prompt = "Enter value: " }, function(str)
        return str
    end)
    print(variable)
end

return M

This is the Lazy configuration:

local map_test = {
    ["<leader>T"] = {
        mode = { "n" },
        name = "Test",
        ["t"] = {
            function()
                require("test").test()
            end,
            "Test",
        },
    },
}

return {
    name = "test",
    cmd = "Test",
    dir = "~/.config/nvim/lua/plugins-my/test.nvim",
    config = function()
        local wk = require("which-key")
        wk.register(map_test)
    end,
}

Added the structure of the lua directory as suggested by KamilCuk:

├── config
├── plugins-active
├── plugins-inactive
├── plugins-my
│   ├── motli.nvim
│   │   ├── lua
│   │   │   └── motli
│   │   └── plugin
│   ├── presenta.nvim
│   │   ├── lua
│   │   │   └── presenta
│   │   └── plugin
│   └── test.nvim
│       ├── lua
│       └── plugin
└── util

While the plugin is loaded and working, I wonder how to get around the message.

Thanks!

Share Improve this question edited Mar 31 at 19:56 Mimosinnet asked Mar 31 at 18:37 MimosinnetMimosinnet 8855 silver badges10 bronze badges 3
  • 1 with :Test where do you register :Test command? Where is the call to vim.api.nvim_create_user_command ? Tehre is require("test"), but your dir is set to lua/plugins-my/test.nvim. So the path would be require("plugins-my.test.nvim.test"), but it is impossible to load a file with a dot, so rename it? What is the directory structure? This is the module: is require("test") working? Is your "Test" module loaded in :Lazy? – KamilCuk Commented Mar 31 at 18:45
  • From what you are saying, I am probably missing the vim.api.nvim_create_user_command. I thought it was not needed, as the spec cmd = "Test" should Lazy-load the plugin (as it does). I will try your suggestion and include the directory structure to make the question clearer. Thanks very much for the suggestions! – Mimosinnet Commented Mar 31 at 19:50
  • 1 should Lazy-load the plugin yes, it lazy loads the plugin and.. the command is still not found. You have to tell nvim the command. – KamilCuk Commented Mar 31 at 20:13
Add a comment  | 

1 Answer 1

Reset to default 1

As KamilCuk suggested, I needed to define the command Test. Defining the command in the Lazy configuration solved the issue:

return {
    name = "test",
    cmd = "Test",
    dir = "~/.config/nvim/lua/plugins-my/test.nvim",
    config = function()
        vim.api.nvim_create_user_command("Test", 'echo "Test plugin loaded"', {})
        local wk = require("which-key")
        wk.register(map_test)
    end,
}

Thanks!

发布评论

评论列表(0)

  1. 暂无评论