feat: map <c-w> to delete pair

This commit is contained in:
zztrieuzz 2021-09-23 11:23:42 +07:00
parent 3a40d753e7
commit e108a70f91
3 changed files with 34 additions and 4 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_w = false -- map <c-w> to delete an pair if possible
```

View File

@ -13,6 +13,7 @@ M.state = {
local default = {
map_bs = true,
map_c_w = false,
disable_filetype = { 'TelescopePrompt', 'spectre_panel' },
ignored_next_char = string.gsub([[ [%w%%%'%[%"%.] ]], '%s+', ''),
check_ts = false,
@ -302,12 +303,21 @@ M.on_attach = function(bufnr)
{ expr = true, noremap = true }
)
end
if M.config.map_c_w then
api.nvim_buf_set_keymap(
bufnr,
'i',
'<c-w>',
string.format('v:lua.MPairs.autopairs_c_w(%d)', bufnr),
{ expr = true, noremap = true }
)
end
api.nvim_buf_set_var(bufnr, 'nvim-autopairs', 1)
end
M.autopairs_bs = function(bufnr)
local autopairs_delete = function(bufnr,key)
if is_disable() then
return utils.esc(utils.key.bs)
return utils.esc(key)
end
local line = utils.text_get_current_line(bufnr)
local _, col = utils.get_cursor()
@ -343,7 +353,15 @@ M.autopairs_bs = function(bufnr)
end
end
end
return utils.esc(utils.key.bs)
return utils.esc(key)
end
M.autopairs_c_w = function (bufnr)
return autopairs_delete(bufnr, "<c-g>U<c-w>")
end
M.autopairs_bs = function (bufnr)
return autopairs_delete(bufnr,utils.key.bs)
end
M.autopairs_map = function(bufnr, char)

View File

@ -485,7 +485,18 @@ local data = {
before = [[{{("It doesn't name %s", ''), 'ErrorMsg'| }}, ]],
after = [[{{("It doesn't name %s", ''), 'ErrorMsg''|' }}, ]],
end_cursor = 42,
}
},
{
setup_func = function()
npairs.setup({
map_c_w = true
})
end,
name = "map <c-w>",
key = "<c-w>",
before = [[aa'|' ]],
after = [[aa| ]],
},
}
local run_data = {}