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!

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? 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! 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. Commented Mar 31 at 20:13

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.