From f24b2150e7d4695b72f09f0e8f88122d8b13642a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E5=81=A5=E6=AD=A3?= Date: Sat, 15 Jun 2024 23:33:53 +0800 Subject: [PATCH] fix(mini.pairs): Improve the behavior of mini.pairs --- lua/lazyvim/plugins/coding.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 39c89a48..7535635f 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -143,7 +143,13 @@ return { event = "VeryLazy", opts = { -- skip autopair when next character is one of these - skip_next = [=[[%w%%%'%[%"%.%`%$]]=], + -- [ ( { ` ' " + left_pair = "[%[%(%{`'\"]", + -- ] ) } ` ' " + right_pair = "[%]%)%}`'\"]", + -- %w [ ] { } ( ) ` ' " + skip_before = "[%w%[%]%{%}%(%)`'\"]$", + skip_next = "^[%w%[%]%{%}%(%)`'\"]", -- skip autopair when next character is closing pair -- and there are more closing pairs than opening pairs skip_unbalanced = true, @@ -177,7 +183,16 @@ return { if opts.markdown and o == "`" and vim.bo.filetype == "markdown" and before:match("^%s*``") then return "`\n```" .. vim.api.nvim_replace_termcodes("", true, true, true) end - if opts.skip_next and next ~= "" and next:match(opts.skip_next) then + -- If the left and right characters are pairs of characters + if before:match(opts.left_pair .. "$") and next:match("^" .. opts.right_pair) then + return open(pair, neigh_pattern) + end + -- If the end of the string to the left of the cursor is a letter or a punctuation pair + if before ~= "" and before:match(opts.skip_before) then + return o + end + -- If the end of the string to the right of the cursor is a letter or a punctuation pair + if next ~= "" and next:match(opts.skip_next) then return o end if opts.skip_unbalanced and next == c and c ~= o then