Feat: Add the option mapping <C-h> to deleting a pair

This commit is contained in:
Jakub Kaczor 2021-12-17 11:48:41 +01:00 committed by windwp
parent 04cd1779f8
commit 4406e94ba6
4 changed files with 27 additions and 0 deletions

View File

@ -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 <BS> key
local map_c_h = false -- Map the <C-h> key to delete a pair
local map_c_w = false -- map <c-w> to delete a pair if possible
```

View File

@ -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, '<c-g>U<c-w>')
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

View File

@ -5,6 +5,7 @@ local log = require('nvim-autopairs._log')
M.key = {
del = "<del>",
bs = "<bs>",
c_h = "<C-h>",
left = "<left>",
right = "<right>",
join_left = "<c-g>U<left>",

View File

@ -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 <c-h>",
key = "<c-h>",
before = [[aa'|' ]],
after = [[aa| ]],
},
{
setup_func = function()
npairs.setup({