From 77f8963a603824f3f67ebadfe085b10b9026f378 Mon Sep 17 00:00:00 2001 From: steven-na Date: Mon, 1 Jun 2026 23:48:47 -0700 Subject: Update nvim conf --- arch/lightvim/.config/lightvim/lua/plugins.lua | 133 +++++++++++++++++++++---- 1 file changed, 116 insertions(+), 17 deletions(-) diff --git a/arch/lightvim/.config/lightvim/lua/plugins.lua b/arch/lightvim/.config/lightvim/lua/plugins.lua index b6af099..d9b563b 100644 --- a/arch/lightvim/.config/lightvim/lua/plugins.lua +++ b/arch/lightvim/.config/lightvim/lua/plugins.lua @@ -98,16 +98,60 @@ return { }, { "jake-stewart/multicursor.nvim", - branch = "1.0", event = "VeryLazy", config = function() local mc = require("multicursor-nvim") mc.setup() - vim.keymap.set({ "n", "v" }, "", function() mc.lineAddCursor(1) end, { desc = "Add cursor down" }) - vim.keymap.set({ "n", "v" }, "", function() mc.lineAddCursor(-1) end, { desc = "Add cursor up" }) - vim.keymap.set({ "n", "v" }, "mA", mc.matchAllAddCursors, { desc = "Cursors for all matches" }) - vim.keymap.set({ "n", "v" }, "mn", function() mc.matchAddCursor(1) end, { desc = "Add cursor next match" }) - vim.keymap.set("n", "", function() + local set = vim.keymap.set + local nv = { "n", "v" } + + -- Adding cursors (Alt+Shift+arrow — Ctrl+Shift+arrow is move-line) + set(nv, "", function() mc.lineAddCursor(1) end, { desc = "Add cursor down" }) + set(nv, "", function() mc.lineAddCursor(-1) end, { desc = "Add cursor up" }) + + -- Skipping (advance without dropping a cursor) + set(nv, "m", function() mc.lineSkipCursor(1) end, { desc = "Skip line down" }) + set(nv, "m", function() mc.lineSkipCursor(-1) end, { desc = "Skip line up" }) + + -- Match-based add / skip + set(nv, "mn", function() mc.matchAddCursor(1) end, { desc = "Add cursor: next match" }) + set(nv, "mp", function() mc.matchAddCursor(-1) end, { desc = "Add cursor: prev match" }) + set(nv, "ms", function() mc.matchSkipCursor(1) end, { desc = "Skip match, advance" }) + set(nv, "mA", mc.matchAllAddCursors, { desc = "Cursors for all matches" }) + + -- Repeat keys: ;/, add or skip when cursors active; default f/F/t/T otherwise + set("n", ";", function() + if mc.hasCursors() then mc.matchAddCursor(1) else vim.cmd("normal! ;") end + end, { desc = "Repeat f/F/t/T · next-match cursor when active" }) + set("n", ",", function() + if mc.hasCursors() then mc.matchSkipCursor(1) else vim.cmd("normal! ,") end + end, { desc = "Reverse f/F/t/T · skip-match when active" }) + + -- Manual toggle / delete + set(nv, "mt", mc.toggleCursor, { desc = "Toggle cursor here" }) + set(nv, "mx", mc.deleteCursor, { desc = "Delete cursor under main" }) + + -- Rotate / jump main focus through cursor list (arrows) + set(nv, "m", mc.nextCursor, { desc = "Rotate to next cursor" }) + set(nv, "m", mc.prevCursor, { desc = "Rotate to prev cursor" }) + set(nv, "mF", mc.firstCursor, { desc = "Jump to first cursor" }) + set(nv, "mL", mc.lastCursor, { desc = "Jump to last cursor" }) + + -- Bulk ops + set(nv, "m=", mc.alignCursors, { desc = "Align cursors" }) + set(nv, "mu", mc.restoreCursors, { desc = "Restore last cursors" }) + set(nv, "md", function() + if mc.cursorsEnabled() then mc.disableCursors() else mc.enableCursors() end + end, { desc = "Freeze/unfreeze cursors" }) + set(nv, "m.", function() mc.transposeCursors(1) end, { desc = "Transpose forward" }) + set(nv, "m,", function() mc.transposeCursors(-1) end, { desc = "Transpose back" }) + + -- Pattern-based (visual mode — needs a selection) + set("x", "m/", mc.matchCursors, { desc = "Cursors at regex matches" }) + set("x", "mS", mc.splitCursors, { desc = "Split selection by pattern" }) + + -- Esc: re-enable / clear / nohlsearch + set("n", "", function() if not mc.cursorsEnabled() then mc.enableCursors() elseif mc.hasCursors() then @@ -119,23 +163,78 @@ return { end, }, - -- === Treesitter === + -- === Treesitter (main branch, nvim 0.11+ API) === { "nvim-treesitter/nvim-treesitter", + branch = "main", + lazy = false, build = ":TSUpdate", - event = { "BufReadPre", "BufNewFile" }, - opts = { - ensure_installed = { + dependencies = { + { "nvim-treesitter/nvim-treesitter-textobjects", branch = "main" }, + }, + config = function() + require("nvim-treesitter").setup({}) + + local parsers = { "c", "cpp", "python", "lua", "haskell", "rust", "odin", "vim", "vimdoc", "query", "bash", "diff", "markdown", "markdown_inline", "json", "toml", "yaml", - }, - highlight = { enable = true }, - indent = { enable = true }, - auto_install = false, - }, - config = function(_, opts) - require("nvim-treesitter").setup(opts) + } + require("nvim-treesitter").install(parsers) + + vim.api.nvim_create_autocmd("FileType", { + callback = function(args) + local lang = vim.treesitter.language.get_lang(vim.bo[args.buf].filetype) + if lang and vim.treesitter.language.add(lang) then + pcall(vim.treesitter.start, args.buf, lang) + vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + end, + }) + + -- Textobjects --------------------------------------------------- + local ok_to, to = pcall(require, "nvim-treesitter-textobjects") + if not ok_to then return end + to.setup({ + select = { lookahead = true }, + move = { set_jumps = true }, + }) + local sel = require("nvim-treesitter-textobjects.select") + local move = require("nvim-treesitter-textobjects.move") + local swap = require("nvim-treesitter-textobjects.swap") + local map = vim.keymap.set + + local objs = { + { "af", "@function.outer", "around function" }, + { "if", "@function.inner", "inside function" }, + { "ac", "@class.outer", "around class" }, + { "ic", "@class.inner", "inside class" }, + { "aa", "@parameter.outer", "around argument" }, + { "ia", "@parameter.inner", "inside argument" }, + { "ab", "@block.outer", "around block" }, + { "ib", "@block.inner", "inside block" }, + { "ai", "@conditional.outer", "around conditional" }, + { "ii", "@conditional.inner", "inside conditional" }, + { "al", "@loop.outer", "around loop" }, + { "il", "@loop.inner", "inside loop" }, + } + for _, o in ipairs(objs) do + local lhs, q, d = o[1], o[2], o[3] + map({ "x", "o" }, lhs, function() sel.select_textobject(q, "textobjects") end, { desc = d }) + end + + local nmo = { "n", "x", "o" } + map(nmo, "]m", function() move.goto_next_start("@function.outer", "textobjects") end, { desc = "next func start" }) + map(nmo, "[m", function() move.goto_previous_start("@function.outer", "textobjects") end, { desc = "prev func start" }) + map(nmo, "]M", function() move.goto_next_end("@function.outer", "textobjects") end, { desc = "next func end" }) + map(nmo, "[M", function() move.goto_previous_end("@function.outer", "textobjects") end, { desc = "prev func end" }) + map(nmo, "]]", function() move.goto_next_start("@class.outer", "textobjects") end, { desc = "next class start" }) + map(nmo, "[[", function() move.goto_previous_start("@class.outer", "textobjects") end, { desc = "prev class start" }) + map(nmo, "][", function() move.goto_next_end("@class.outer", "textobjects") end, { desc = "next class end" }) + map(nmo, "[]", function() move.goto_previous_end("@class.outer", "textobjects") end, { desc = "prev class end" }) + + map("n", "a", function() swap.swap_next("@parameter.inner") end, { desc = "Swap arg with next" }) + map("n", "A", function() swap.swap_previous("@parameter.inner") end, { desc = "Swap arg with prev" }) end, }, -- cgit v1.2.3