From 88a70bfeb4af3b4f46dd8b570f135016c9f01f51 Mon Sep 17 00:00:00 2001 From: Albin Chaboissier Date: Mon, 10 Nov 2025 15:40:33 +0100 Subject: [PATCH] Adds multicursor dumb --- lua/plugins/multicursors.lua | 141 +++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 63 deletions(-) diff --git a/lua/plugins/multicursors.lua b/lua/plugins/multicursors.lua index 6493e1a..41245d8 100644 --- a/lua/plugins/multicursors.lua +++ b/lua/plugins/multicursors.lua @@ -1,76 +1,91 @@ return { - "jake-stewart/multicursor.nvim", - branch = "1.0", - config = function() - local mc = require("multicursor-nvim") - mc.setup() + "jake-stewart/multicursor.nvim", + branch = "1.0", + config = function() + local mc = require("multicursor-nvim") + mc.setup() - local set = vim.keymap.set + local set = vim.keymap.set - -- Add or skip cursor above/below the main cursor. - set({"n", "x"}, "", function() mc.lineAddCursor(-1) end) - set({"n", "x"}, "", function() mc.lineAddCursor(1) end) - -- set({"n", "x"}, "", function() mc.lineSkipCursor(-1) end) - -- set({"n", "x"}, "", function() mc.lineSkipCursor(1) end) + -- Add or skip cursor above/below the main cursor. + set({ "n", "x" }, "", function() + mc.lineAddCursor(-1) + end) + set({ "n", "x" }, "", function() + mc.lineAddCursor(1) + end) + set({ "n", "x" }, "", function() + mc.lineSkipCursor(-1) + end) + set({ "n", "x" }, "", function() + mc.lineSkipCursor(1) + end) - -- Add or skip adding a new cursor by matching word/selection - set({"n", "x"}, "", function() mc.matchAddCursor(1) end) - set({"n", "x"}, "", function() mc.matchSkipCursor(1) end) - set({"n", "x"}, "", function() mc.matchAddCursor(-1) end) - set({"n", "x"}, "", function() mc.matchSkipCursor(-1) end) + -- Add or skip adding a new cursor by matching word/selection + set({ "n", "x" }, "", function() + mc.matchAddCursor(1) + end) + set({ "n", "x" }, "", function() + mc.matchSkipCursor(1) + end) + set({ "n", "x" }, "", function() + mc.matchAddCursor(-1) + end) + set({ "n", "x" }, "", function() + mc.matchSkipCursor(-1) + end) - -- Add and remove cursors with control + left click. - set("n", "", mc.handleMouse) - set("n", "", mc.handleMouseDrag) - set("n", "", mc.handleMouseRelease) + -- Add and remove cursors with control + left click. + set("n", "", mc.handleMouse) + set("n", "", mc.handleMouseDrag) + set("n", "", mc.handleMouseRelease) - -- Disable and enable cursors. - set({"n", "x"}, "", mc.toggleCursor) + -- Disable and enable cursors. + set({ "n", "x" }, "", mc.toggleCursor) - -- Mappings defined in a keymap layer only apply when there are - -- multiple cursors. This lets you have overlapping mappings. - mc.addKeymapLayer(function(layerSet) + -- Mappings defined in a keymap layer only apply when there are + -- multiple cursors. This lets you have overlapping mappings. + mc.addKeymapLayer(function(layerSet) + -- Select a different cursor as the main one. + layerSet({ "n", "x" }, "", mc.prevCursor) + layerSet({ "n", "x" }, "", mc.nextCursor) - -- Select a different cursor as the main one. - layerSet({"n", "x"}, "", mc.prevCursor) - layerSet({"n", "x"}, "", mc.nextCursor) + -- Delete the main cursor. + layerSet({ "n", "x" }, "x", mc.deleteCursor) - -- Delete the main cursor. - layerSet({"n", "x"}, "x", mc.deleteCursor) + -- Enable and clear cursors using escape. + layerSet("n", "", function() + if not mc.cursorsEnabled() then + mc.enableCursors() + else + mc.clearCursors() + end + end) + end) - -- Enable and clear cursors using escape. - layerSet("n", "", function() - if not mc.cursorsEnabled() then - mc.enableCursors() - else - mc.clearCursors() - end - end) - end) + -- Customize how cursors look. + local hl = vim.api.nvim_set_hl + hl(0, "MultiCursorCursor", { reverse = true, fg = "#aaaaff" }) + hl(0, "MultiCursorVisual", { link = "Visual" }) + hl(0, "MultiCursorSign", { link = "SignColumn" }) + hl(0, "MultiCursorMatchPreview", { link = "Search" }) + hl(0, "MultiCursorDisabledCursor", { reverse = true }) + hl(0, "MultiCursorDisabledVisual", { link = "Visual" }) + hl(0, "MultiCursorDisabledSign", { link = "SignColumn" }) - -- Customize how cursors look. - local hl = vim.api.nvim_set_hl - hl(0, "MultiCursorCursor", { reverse = true, fg = "#aaaaff"}) - hl(0, "MultiCursorVisual", { link = "Visual" }) - hl(0, "MultiCursorSign", { link = "SignColumn"}) - hl(0, "MultiCursorMatchPreview", { link = "Search" }) - hl(0, "MultiCursorDisabledCursor", { reverse = true }) - hl(0, "MultiCursorDisabledVisual", { link = "Visual" }) - hl(0, "MultiCursorDisabledSign", { link = "SignColumn"}) + -- Autocmds to change main cursor color when multicursors is active + vim.api.nvim_create_autocmd("User", { + pattern = "MultiCursorStart", + callback = function() + vim.api.nvim_set_hl(0, "Cursor", { bg = "#000000", fg = "#ffffff" }) -- bright red + end, + }) - -- Autocmds to change main cursor color when multicursors is active - vim.api.nvim_create_autocmd("User", { - pattern = "MultiCursorStart", - callback = function() - vim.api.nvim_set_hl(0, "Cursor", { bg = "#000000", fg = "#ffffff" }) -- bright red - end, - }) - - vim.api.nvim_create_autocmd("User", { - pattern = "MultiCursorExit", - callback = function() - vim.api.nvim_set_hl(0, "Cursor", { link = "Cursor" }) -- restore default - end, - }) - end + vim.api.nvim_create_autocmd("User", { + pattern = "MultiCursorExit", + callback = function() + vim.api.nvim_set_hl(0, "Cursor", { link = "Cursor" }) -- restore default + end, + }) + end, }