monaqa / dial.nvim

enhanced increment/decrement plugin for Neovim.
MIT License
783 stars 12 forks source link

<C-a> somehow conflicts with `mini.clue` #94

Closed simonmandlik closed 1 month ago

simonmandlik commented 1 month ago

I am using dial.nvim alongside mini.clue and have recently noticed that <C-a> in visual mode doesn't work. In normal mode <C-a> works, and <C-x> (and also g* variants) work in both modes.

I have also opened similar issue with mini.clue: https://github.com/echasnovski/mini.nvim/issues/1059

MWE:

local root = vim.fn.fnamemodify("./.repro", ":p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
local lazypath = root .. "/plugins/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", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
    "monaqa/dial.nvim",
    {
        "echasnovski/mini.clue",
        opts = function()
            return {
                triggers = {
                    { mode = "n", keys = "g" },
                    { mode = "v", keys = "g" }
                }
            }
        end
    }
}

require("lazy").setup(plugins, { root = root .. "/plugins", })

vim.keymap.set("n", "<C-a>", function()
    print("n <C-a>")
    require("dial.map").manipulate("increment", "normal")
end)
vim.keymap.set("v", "<C-a>", function()
    print("v <C-a>")
    require("dial.map").manipulate("increment", "visual")
end)
vim.keymap.set("n", "<C-x>", function()
    print("n <C-x>")
    require("dial.map").manipulate("decrement", "normal")
end)
vim.keymap.set("v", "<C-x>", function()
    print("v <C-x>")
    require("dial.map").manipulate("decrement", "visual")
end)
monaqa commented 1 month ago

Reproduced the problem, and it helped me to determine the cause. Thanks for the report.

dial.nvim uses the command g@ internally, and the definition of g@ was changed inside mini.clue, causing the conflict. We don't know why g@ doesn't work as expected (you'll have to ask mini.clue to figure it out). However, at least using the default g@ on dial.nvim should solve the problem, so I'll try to fix it that way.

monaqa commented 1 month ago

@simonmandlik #95 should fix the problem. Could you try the following configuration, update the plugin (with :Lazy + U), and check whether v_CTRL-A works? (it worked in my environment)

 local plugins = {
-    "monaqa/dial.nvim",
+    { "monaqa/dial.nvim", branch = "fix-cmd_normal_bang" },
     {
         "echasnovski/mini.clue",
         opts = function()
             return {
                 triggers = {
                     { mode = "n", keys = "g" },
                     { mode = "v", keys = "g" },
                 },
             }
         end,
     },
 }
echasnovski commented 1 month ago

Thanks for the quick fix!

Preferring :normal! ... instead of :normal ... for executing some built-in functionality is indeed usually a safer way. Not the OP, but for me it indeed seems to fix it.

simonmandlik commented 1 month ago

Yes, I can confirm the fix works, thanks!