diff --git a/README.md b/README.md index bb0a535..de268e0 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ local enable_afterquote = true -- add bracket pairs after quote local enable_check_bracket_line = true --- check bracket in same line local check_ts = false local map_bs = true -- map the key +local map_c_h = false -- Map the key to delete a pair local map_c_w = false -- map to delete a pair if possible ``` diff --git a/lua/nvim-autopairs.lua b/lua/nvim-autopairs.lua index 8521419..8b546aa 100644 --- a/lua/nvim-autopairs.lua +++ b/lua/nvim-autopairs.lua @@ -13,6 +13,7 @@ M.state = { local default = { map_bs = true, + map_c_h = false, map_c_w = false, map_cr = true, disable_filetype = { 'TelescopePrompt', 'spectre_panel' }, @@ -317,6 +318,17 @@ M.on_attach = function(bufnr) { expr = true, noremap = true } ) end + + if M.config.map_c_h then + api.nvim_buf_set_keymap( + bufnr, + "i", + utils.key.c_h, + string.format("v:lua.MPairs.autopairs_c_h(%d)", bufnr), + {expr = true, noremap = true} + ) + end + if M.config.map_c_w then api.nvim_buf_set_keymap( bufnr, @@ -374,6 +386,10 @@ M.autopairs_c_w = function(bufnr) return autopairs_delete(bufnr, 'U') end +M.autopairs_c_h = function(bufnr) + return autopairs_delete(bufnr, utils.key.c_h) +end + M.autopairs_bs = function(bufnr) return autopairs_delete(bufnr, utils.key.bs) end diff --git a/lua/nvim-autopairs/utils.lua b/lua/nvim-autopairs/utils.lua index dc7b60a..8b0951d 100644 --- a/lua/nvim-autopairs/utils.lua +++ b/lua/nvim-autopairs/utils.lua @@ -5,6 +5,7 @@ local log = require('nvim-autopairs._log') M.key = { del = "", bs = "", + c_h = "", left = "", right = "", join_left = "U", diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index 9ed3b13..3383ae2 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -514,6 +514,15 @@ local data = { after = [[{{("It doesn't name %s", ''), 'ErrorMsg''|' }}, ]], end_cursor = 41 }, + { + setup_func = function() + npairs.setup({map_c_h = true}) + end, + name = "map ", + key = "", + before = [[aa'|' ]], + after = [[aa| ]], + }, { setup_func = function() npairs.setup({