replace autopairs with a mini version

This commit is contained in:
2025-11-23 01:54:32 +01:00
parent f0a4230996
commit 8f98beb4a7
2 changed files with 1 additions and 32 deletions

View File

@@ -1,32 +0,0 @@
---@type LazySpec
return { {
'windwp/nvim-autopairs', -- automatically inserts closing brackets
event = { 'BufReadPre', 'BufNewFile' },
opts = {
enable_moveright = true, -- moves the cursor over existing pairs instead of inserting duplicates
check_ts = true, -- whether to check treesitter for specific nodes
ts_config = {}
},
config = function(_, opts)
local autopairs = require 'nvim-autopairs'
autopairs.setup(opts)
-- customise the rule for [] brackets so it doesn't close when typing ANSI escape codes
local rule = autopairs.get_rule '['
if rule then
rule:with_pair(function(opt)
local ei = math.max(1, opt.col - 1) -- get the end-index
local prev_oct = opt.line:sub(math.max(1, opt.col - 4), ei) -- get the range of an octal escape code
local prev_hex = opt.line:sub(math.max(1, opt.col - 4), ei) -- get the range of a hexadecimal escape code
local prev_cha = opt.line:sub(math.max(1, opt.col - 2), ei) -- get the range of a character escape code
-- check whether we can't match any of the patterns,
-- if so return true, otherwise return false (whether to insert a pair)
return (prev_oct ~= [[\033]] and prev_hex ~= [[\x1b]] and prev_cha ~= [[\e]])
end)
else
vim.notify('could not add a rule for not auto-closing [ when typing an ANSI escape code',
vim.log.levels.WARN)
end
end,
} }

View File

@@ -18,6 +18,7 @@ require('mini.align').setup() -- utility to align text in various ways
require('mini.comment').setup() -- for toggling comments inline
require('mini.move').setup() -- moving lines
require('mini.operators').setup() -- duplicating lines and evaluating equations inline
require('mini.pairs').setup() -- automatic closing pairs
require('mini.surround').setup() -- surround stuff
require('mini.clue').setup({ -- shows available keybinds when performing keybind actions
window = { delay = 50 },