From 7aee4524132cc10c17f17628bf16d399fba28651 Mon Sep 17 00:00:00 2001 From: rootiest Date: Wed, 25 Sep 2024 06:17:38 -0400 Subject: [PATCH] refactor: unify MultiCursor keybindings under m prefix --- lua/data/func.lua | 30 ++++++++++++++++++++++++++++++ lua/data/keys.lua | 29 +++++++++++++++++------------ lua/plugins/statusline/lualine.lua | 18 ++++++++++++++++-- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/lua/data/func.lua b/lua/data/func.lua index f592da2..4df730f 100644 --- a/lua/data/func.lua +++ b/lua/data/func.lua @@ -1197,5 +1197,35 @@ function M.exit() vim.api.nvim_command("wqall") end +---@function Function to render the MultiCursor statusline +---@return table status The MultiCursor status object +function M.mc_statusline() + local mc = require("multicursor-nvim") + local status = {} + if mc.hasCursors() then + status.enabled = true + if vim.fn.mode() == "v" then + status.icon = "󰚕 " + status.short_text = "V" + status.text = "VISUAL" + status.color = "lualine_a_visual" + else + status.icon = "󰬸 " + status.short_text = "N" + status.text = "NORMAL" + status.color = "lualine_a_normal" + end + else + status.enabled = false + status.icon = "󰘪 " + status.short_text = "NO" + status.text = "SINGLE" + status.color = "lualine_a_normal" + end + status.icon_short_text = status.icon .. status.short_text + status.icon_text = status.icon .. status.text + return status +end + -- Export the module return M diff --git a/lua/data/keys.lua b/lua/data/keys.lua index 299c3b2..7bd7855 100644 --- a/lua/data/keys.lua +++ b/lua/data/keys.lua @@ -561,6 +561,11 @@ M.group = { group = "New Commits", icon = { icon = "", color = "green" }, }, + { -- MultiCursor + lhs = "m", + group = "MultiCursor", + icon = { icon = "󰬸", color = "green" }, + }, }, } @@ -590,7 +595,7 @@ M.multicursor = { desc = "Add Cursor Below", }, { - "", + "", function() require("multicursor-nvim").addCursor("*") end, @@ -598,7 +603,7 @@ M.multicursor = { mode = { "n", "v" }, }, { - "", + "", function() require("multicursor-nvim").skipCursor("*") end, @@ -622,7 +627,7 @@ M.multicursor = { mode = { "n", "v" }, }, { - "x", + "mx", function() require("multicursor-nvim").deleteCursor() end, @@ -638,7 +643,7 @@ M.multicursor = { mode = "n", }, { - "", + "", function() if require("multicursor-nvim").cursorsEnabled() then require("multicursor-nvim").disableCursors() -- Stop other cursors from moving, allowing main cursor repositioning. @@ -664,7 +669,7 @@ M.multicursor = { mode = "n", }, { - "a", + "ma", function() require("multicursor-nvim").alignCursors() end, @@ -672,7 +677,7 @@ M.multicursor = { mode = "n", }, { - "S", + "mS", function() require("multicursor-nvim").splitCursors() end, @@ -680,7 +685,7 @@ M.multicursor = { mode = "v", }, { - "I", + "mI", function() require("multicursor-nvim").insertVisual() end, @@ -688,7 +693,7 @@ M.multicursor = { mode = "v", }, { - "A", + "mA", function() require("multicursor-nvim").appendVisual() end, @@ -696,7 +701,7 @@ M.multicursor = { mode = "v", }, { - "M", + "mM", function() require("multicursor-nvim").matchCursors() end, @@ -704,7 +709,7 @@ M.multicursor = { mode = "v", }, { - "t", + "mt", function() require("multicursor-nvim").transposeCursors(1) end, @@ -712,7 +717,7 @@ M.multicursor = { mode = "v", }, { - "T", + "mT", function() require("multicursor-nvim").transposeCursors(-1) end, @@ -1174,7 +1179,7 @@ M.substitute = { mode = "x", }, { -- Substitute visual selection in visual mode - "r", + "m", function() require("substitute").visual() end, diff --git a/lua/plugins/statusline/lualine.lua b/lua/plugins/statusline/lualine.lua index 91a8d04..8fa3bba 100644 --- a/lua/plugins/statusline/lualine.lua +++ b/lua/plugins/statusline/lualine.lua @@ -138,12 +138,25 @@ return { -- Lualine }, sections = { -- Sections lualine_a = { - { - -- Calls the current.lualine() function to get the mode string + { -- Mode function() return data.types.mode.current.lualine() end, padding = { left = 1, right = 0 }, + separator = { left = "", right = "" }, + }, + { -- MultiCursors + function() + return data.func.mc_statusline().icon + end, + cond = function() + return data.func.mc_statusline().enabled + end, + color = function() + return data.func.mc_statusline().color + end, + padding = { left = 0, right = 0 }, + separator = { left = "", right = "" }, }, }, lualine_b = { @@ -405,6 +418,7 @@ return { -- Lualine on_click = function() vim.cmd("Telescope oldfiles") end, + separator = { left = "", right = "" }, }, }, },