fix(nvim): update live command to use v2 setup

This commit is contained in:
Price Hiller 2024-11-20 11:34:12 -06:00
parent 3e48185577
commit 0792690518
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -11,16 +11,25 @@ return {
commands = {
GG = { cmd = "g" },
Norm = { cmd = "norm" },
Reg = {
cmd = "norm",
-- This will transform ":5Reg a" into ":norm 5@a"
args = function(opts)
return (opts.count == -1 and "" or opts.count) .. "@" .. opts.args
end,
range = "",
},
},
})
-- Transforms ":5Reg a" into ":norm 5@a"
local function get_command_string(cmd)
local get_range_string = require("live-command").get_range_string
local args = (cmd.count == -1 and "" or cmd.count) .. "@" .. cmd.args
return get_range_string(cmd) .. "norm " .. args
end
vim.api.nvim_create_user_command("Reg", function(cmd)
vim.cmd(get_command_string(cmd))
end, {
nargs = "?",
range = true,
preview = function(cmd, preview_ns, preview_buf)
local cmd_to_preview = get_command_string(cmd)
return require("live-command").preview_callback(cmd_to_preview, preview_ns, preview_buf)
end,
})
end,
},
}