diff options
| author | ache <ache@ache.one> | 2026-03-30 16:28:50 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2026-03-30 16:28:50 +0200 |
| commit | f9903728f86ea06a2bde9711b8b57ada29c97e9b (patch) | |
| tree | 22e50cdd74278c033cf81f973213bec5c08ff402 /lua | |
| parent | feat: Update config of vim surround (diff) | |
fix: Migrate to surround v4
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/ache/plugins/surround.lua | 520 |
1 files changed, 260 insertions, 260 deletions
diff --git a/lua/ache/plugins/surround.lua b/lua/ache/plugins/surround.lua index 7911827..9a4380d 100644 --- a/lua/ache/plugins/surround.lua +++ b/lua/ache/plugins/surround.lua @@ -11,267 +11,267 @@ return { "kylechui/nvim-surround", enabled = true, + version = "^4.0.0", -- Use for stability; omit to use `main` branch for the latest features dependancies = { "nvim-treesitter/nvim-treesitter-textobjects" }, -- event = { "BufReadPre", "BufNewFile" }, event = "VeryLazy", - version = "*", - config = function() - -- require("nvim-surround").setup({ - -- keymaps = { - -- insert = "<C-g>s", - -- insert_line = "<C-g>S", - -- normal = "ys", - -- normal_cur = "yss", - -- normal_line = "yS", - -- normal_cur_line = "ySS", - -- visual = "s", - -- visual_line = "gS", - -- delete = "ds", - -- change = "cs", - -- change_line = "cS", - -- }, - -- }) - require("nvim-surround").setup( - -- { - -- surrounds = { - -- ["("] = { - -- add = { "( ", " )" }, - -- find = function() - -- return M.get_selection({ motion = "a(" }) - -- end, - -- delete = "^(. ?)().-( ?.)()$", - -- }, - -- [")"] = { - -- add = { "(", ")" }, - -- find = function() - -- return M.get_selection({ motion = "a)" }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ["{"] = { - -- add = { "{ ", " }" }, - -- find = function() - -- return M.get_selection({ motion = "a{" }) - -- end, - -- delete = "^(. ?)().-( ?.)()$", - -- }, - -- ["}"] = { - -- add = { "{", "}" }, - -- find = function() - -- return M.get_selection({ motion = "a}" }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ["<"] = { - -- add = { "< ", " >" }, - -- find = function() - -- return M.get_selection({ motion = "a<" }) - -- end, - -- delete = "^(. ?)().-( ?.)()$", - -- }, - -- [">"] = { - -- add = { "<", ">" }, - -- find = function() - -- return M.get_selection({ motion = "a>" }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ["["] = { - -- add = { "[ ", " ]" }, - -- find = function() - -- return M.get_selection({ motion = "a[" }) - -- end, - -- delete = "^(. ?)().-( ?.)()$", - -- }, - -- ["]"] = { - -- add = { "[", "]" }, - -- find = function() - -- return M.get_selection({ motion = "a]" }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ["'"] = { - -- add = { "'", "'" }, - -- find = function() - -- return M.get_selection({ motion = "a'" }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ['"'] = { - -- add = { '"', '"' }, - -- find = function() - -- return M.get_selection({ motion = 'a"' }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ["`"] = { - -- add = { "`", "`" }, - -- find = function() - -- return M.get_selection({ motion = "a`" }) - -- end, - -- delete = "^(.)().-(.)()$", - -- }, - -- ["i"] = { -- TODO: Add find/delete/change functions - -- add = function() - -- local left_delimiter = M.get_input("Enter the left delimiter: ") - -- local right_delimiter = left_delimiter and M.get_input("Enter the right delimiter: ") - -- if right_delimiter then - -- return { { left_delimiter }, { right_delimiter } } - -- end - -- end, - -- find = function() end, - -- delete = function() end, - -- }, - -- ["t"] = { - -- add = function() - -- local user_input = M.get_input("Enter the HTML tag: ") - -- if user_input then - -- local element = user_input:match("^<?([^%s>]*)") - -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") - -- - -- local open = attributes and element .. " " .. attributes or element - -- local close = element - -- - -- return { { "<" .. open .. ">" }, { "</" .. close .. ">" } } - -- end - -- end, - -- find = function() - -- return M.get_selection({ motion = "at" }) - -- end, - -- delete = "^(%b<>)().-(%b<>)()$", - -- change = { - -- target = "^<([^%s<>]*)().-([^/]*)()>$", - -- replacement = function() - -- local user_input = M.get_input("Enter the HTML tag: ") - -- if user_input then - -- local element = user_input:match("^<?([^%s>]*)") - -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") - -- - -- local open = attributes and element .. " " .. attributes or element - -- local close = element - -- - -- return { { open }, { close } } - -- end - -- end, - -- }, - -- }, - -- ["T"] = { - -- add = function() - -- local user_input = M.get_input("Enter the HTML tag: ") - -- if user_input then - -- local element = user_input:match("^<?([^%s>]*)") - -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") - -- - -- local open = attributes and element .. " " .. attributes or element - -- local close = element - -- - -- return { { "<" .. open .. ">" }, { "</" .. close .. ">" } } - -- end - -- end, - -- find = function() - -- return M.get_selection({ motion = "at" }) - -- end, - -- delete = "^(%b<>)().-(%b<>)()$", - -- change = { - -- target = "^<([^>]*)().-([^/]*)()>$", - -- replacement = function() - -- local user_input = M.get_input("Enter the HTML tag: ") - -- if user_input then - -- local element = user_input:match("^<?([^%s>]*)") - -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") - -- - -- local open = attributes and element .. " " .. attributes or element - -- local close = element - -- - -- return { { open }, { close } } - -- end - -- end, - -- }, - -- }, - -- ["f"] = { - -- add = function() - -- local result = M.get_input("Enter the function name: ") - -- if result then - -- return { { result .. "(" }, { ")" } } - -- end - -- end, - -- find = function() - -- local selection = M.get_selection({ - -- query = { - -- capture = "@call.outer", - -- type = "textobjects", - -- }, - -- }) - -- - -- -- We prioritize TreeSitter-based selections if they exist, otherwise fallback on pattern-based search - -- if selection then - -- return selection - -- end - -- return M.get_selection({ pattern = "[^=%s%(%){}]+%b()" }) - -- end, - -- delete = "^(.-%()().-(%))()$", - -- change = { - -- target = "^.-([%w_]+)()%(.-%)()()$", - -- replacement = function() - -- local result = M.get_input("Enter the function name: ") - -- if result then - -- return { { result }, { "" } } - -- end - -- end, - -- }, - -- }, - -- invalid_key_behavior = { - -- -- By default, we ignore control characters for adding/finding because they are more likely typos than - -- -- intentional. We choose NOT to for deletion, as users could have redefined the find key to something like - -- -- ‘.-’. In this case we should still trim a character from each side, instead of early returning nil. - -- add = function(char) - -- if not char or char:find("%c") then - -- return nil - -- end - -- return { { char }, { char } } - -- end, - -- find = function(char) - -- if not char or char:find("%c") then - -- return nil - -- end - -- return M.get_selection({ - -- pattern = vim.pesc(char) .. ".-" .. vim.pesc(char), - -- }) - -- end, - -- delete = function(char) - -- if not char then - -- return nil - -- end - -- return M.get_selections({ - -- char = char, - -- pattern = "^(.)().-(.)()$", - -- }) - -- end, - -- }, - -- }, - -- aliases = { - -- ["a"] = ">", - -- ["b"] = ")", - -- ["B"] = "}", - -- ["r"] = "]", - -- ["q"] = { '"', "'", "`" }, - -- ["s"] = { "}", "]", ")", ">", '"', "'", "`" }, - -- }, - -- highlight = { - -- duration = 0, - -- }, - -- move_cursor = "begin", - -- indent_lines = function(start, stop) - -- local b = vim.bo - -- -- Only re-indent the selection if a formatter is set up already - -- if - -- start < stop and (b.equalprg ~= "" or b.indentexpr ~= "" or b.cindent or b.smartindent or b.lisp) - -- then - -- vim.cmd(string.format("silent normal! %dG=%dG", start, stop)) - -- require("nvim-surround.cache").set_callback("") - -- end - -- end, - -- } - ) - end, + -- config = function() + -- -- require("nvim-surround").setup({ + -- -- keymaps = { + -- -- insert = "<C-g>s", + -- -- insert_line = "<C-g>S", + -- -- normal = "ys", + -- -- normal_cur = "yss", + -- -- normal_line = "yS", + -- -- normal_cur_line = "ySS", + -- -- visual = "s", + -- -- visual_line = "gS", + -- -- delete = "ds", + -- -- change = "cs", + -- -- change_line = "cS", + -- -- }, + -- -- }) + -- require("nvim-surround").setup( + -- -- { + -- -- surrounds = { + -- -- ["("] = { + -- -- add = { "( ", " )" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a(" }) + -- -- end, + -- -- delete = "^(. ?)().-( ?.)()$", + -- -- }, + -- -- [")"] = { + -- -- add = { "(", ")" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a)" }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ["{"] = { + -- -- add = { "{ ", " }" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a{" }) + -- -- end, + -- -- delete = "^(. ?)().-( ?.)()$", + -- -- }, + -- -- ["}"] = { + -- -- add = { "{", "}" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a}" }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ["<"] = { + -- -- add = { "< ", " >" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a<" }) + -- -- end, + -- -- delete = "^(. ?)().-( ?.)()$", + -- -- }, + -- -- [">"] = { + -- -- add = { "<", ">" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a>" }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ["["] = { + -- -- add = { "[ ", " ]" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a[" }) + -- -- end, + -- -- delete = "^(. ?)().-( ?.)()$", + -- -- }, + -- -- ["]"] = { + -- -- add = { "[", "]" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a]" }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ["'"] = { + -- -- add = { "'", "'" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a'" }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ['"'] = { + -- -- add = { '"', '"' }, + -- -- find = function() + -- -- return M.get_selection({ motion = 'a"' }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ["`"] = { + -- -- add = { "`", "`" }, + -- -- find = function() + -- -- return M.get_selection({ motion = "a`" }) + -- -- end, + -- -- delete = "^(.)().-(.)()$", + -- -- }, + -- -- ["i"] = { -- TODO: Add find/delete/change functions + -- -- add = function() + -- -- local left_delimiter = M.get_input("Enter the left delimiter: ") + -- -- local right_delimiter = left_delimiter and M.get_input("Enter the right delimiter: ") + -- -- if right_delimiter then + -- -- return { { left_delimiter }, { right_delimiter } } + -- -- end + -- -- end, + -- -- find = function() end, + -- -- delete = function() end, + -- -- }, + -- -- ["t"] = { + -- -- add = function() + -- -- local user_input = M.get_input("Enter the HTML tag: ") + -- -- if user_input then + -- -- local element = user_input:match("^<?([^%s>]*)") + -- -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") + -- -- + -- -- local open = attributes and element .. " " .. attributes or element + -- -- local close = element + -- -- + -- -- return { { "<" .. open .. ">" }, { "</" .. close .. ">" } } + -- -- end + -- -- end, + -- -- find = function() + -- -- return M.get_selection({ motion = "at" }) + -- -- end, + -- -- delete = "^(%b<>)().-(%b<>)()$", + -- -- change = { + -- -- target = "^<([^%s<>]*)().-([^/]*)()>$", + -- -- replacement = function() + -- -- local user_input = M.get_input("Enter the HTML tag: ") + -- -- if user_input then + -- -- local element = user_input:match("^<?([^%s>]*)") + -- -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") + -- -- + -- -- local open = attributes and element .. " " .. attributes or element + -- -- local close = element + -- -- + -- -- return { { open }, { close } } + -- -- end + -- -- end, + -- -- }, + -- -- }, + -- -- ["T"] = { + -- -- add = function() + -- -- local user_input = M.get_input("Enter the HTML tag: ") + -- -- if user_input then + -- -- local element = user_input:match("^<?([^%s>]*)") + -- -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") + -- -- + -- -- local open = attributes and element .. " " .. attributes or element + -- -- local close = element + -- -- + -- -- return { { "<" .. open .. ">" }, { "</" .. close .. ">" } } + -- -- end + -- -- end, + -- -- find = function() + -- -- return M.get_selection({ motion = "at" }) + -- -- end, + -- -- delete = "^(%b<>)().-(%b<>)()$", + -- -- change = { + -- -- target = "^<([^>]*)().-([^/]*)()>$", + -- -- replacement = function() + -- -- local user_input = M.get_input("Enter the HTML tag: ") + -- -- if user_input then + -- -- local element = user_input:match("^<?([^%s>]*)") + -- -- local attributes = user_input:match("^<?[^%s>]*%s+(.-)>?$") + -- -- + -- -- local open = attributes and element .. " " .. attributes or element + -- -- local close = element + -- -- + -- -- return { { open }, { close } } + -- -- end + -- -- end, + -- -- }, + -- -- }, + -- -- ["f"] = { + -- -- add = function() + -- -- local result = M.get_input("Enter the function name: ") + -- -- if result then + -- -- return { { result .. "(" }, { ")" } } + -- -- end + -- -- end, + -- -- find = function() + -- -- local selection = M.get_selection({ + -- -- query = { + -- -- capture = "@call.outer", + -- -- type = "textobjects", + -- -- }, + -- -- }) + -- -- + -- -- -- We prioritize TreeSitter-based selections if they exist, otherwise fallback on pattern-based search + -- -- if selection then + -- -- return selection + -- -- end + -- -- return M.get_selection({ pattern = "[^=%s%(%){}]+%b()" }) + -- -- end, + -- -- delete = "^(.-%()().-(%))()$", + -- -- change = { + -- -- target = "^.-([%w_]+)()%(.-%)()()$", + -- -- replacement = function() + -- -- local result = M.get_input("Enter the function name: ") + -- -- if result then + -- -- return { { result }, { "" } } + -- -- end + -- -- end, + -- -- }, + -- -- }, + -- -- invalid_key_behavior = { + -- -- -- By default, we ignore control characters for adding/finding because they are more likely typos than + -- -- -- intentional. We choose NOT to for deletion, as users could have redefined the find key to something like + -- -- -- ‘.-’. In this case we should still trim a character from each side, instead of early returning nil. + -- -- add = function(char) + -- -- if not char or char:find("%c") then + -- -- return nil + -- -- end + -- -- return { { char }, { char } } + -- -- end, + -- -- find = function(char) + -- -- if not char or char:find("%c") then + -- -- return nil + -- -- end + -- -- return M.get_selection({ + -- -- pattern = vim.pesc(char) .. ".-" .. vim.pesc(char), + -- -- }) + -- -- end, + -- -- delete = function(char) + -- -- if not char then + -- -- return nil + -- -- end + -- -- return M.get_selections({ + -- -- char = char, + -- -- pattern = "^(.)().-(.)()$", + -- -- }) + -- -- end, + -- -- }, + -- -- }, + -- -- aliases = { + -- -- ["a"] = ">", + -- -- ["b"] = ")", + -- -- ["B"] = "}", + -- -- ["r"] = "]", + -- -- ["q"] = { '"', "'", "`" }, + -- -- ["s"] = { "}", "]", ")", ">", '"', "'", "`" }, + -- -- }, + -- -- highlight = { + -- -- duration = 0, + -- -- }, + -- -- move_cursor = "begin", + -- -- indent_lines = function(start, stop) + -- -- local b = vim.bo + -- -- -- Only re-indent the selection if a formatter is set up already + -- -- if + -- -- start < stop and (b.equalprg ~= "" or b.indentexpr ~= "" or b.cindent or b.smartindent or b.lisp) + -- -- then + -- -- vim.cmd(string.format("silent normal! %dG=%dG", start, stop)) + -- -- require("nvim-surround.cache").set_callback("") + -- -- end + -- -- end, + -- -- } + -- ) + -- end, } |