1
0
Fork 0
numbers/nvim/lua/plugins/autopairs.lua

54 lines
1.3 KiB
Lua

require("nvim-autopairs").setup({
check_ts = true,
ts_config = {
lua = { "string" }, -- it will not add pair on that treesitter node
javascript = { "template_string" },
},
fast_wrap = {
map = "<M-e>",
chars = { "{", "[", "(", '"', "'" },
pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
offset = 0, -- Offset from pattern match
end_key = "$",
keys = "qwertyuiopzxcvbnmasdfghjkl",
check_comma = true,
highlight = "Search",
highlight_grey = "Comment",
},
})
local Rule = require("nvim-autopairs.rule")
require("nvim-autopairs").add_rules({
Rule(" ", " "):with_pair(function(opts)
local pair = opts.line:sub(opts.col - 1, opts.col)
return vim.tbl_contains({ "()", "[]", "{}" }, pair)
end),
Rule("( ", " )")
:with_pair(function()
return false
end)
:with_move(function(opts)
return opts.prev_char:match(".%)") ~= nil
end)
:use_key(")"),
Rule("{ ", " }")
:with_pair(function()
return false
end)
:with_move(function(opts)
return opts.prev_char:match(".%}") ~= nil
end)
:use_key("}"),
Rule("[ ", " ]")
:with_pair(function()
return false
end)
:with_move(function(opts)
return opts.prev_char:match(".%]") ~= nil
end)
:use_key("]"),
})
require("cmp").event:on("confirm_done", require("nvim-autopairs.completion.cmp").on_confirm_done())