1
0
Fork 0
numbers/nvim/plugin/pares.lua

53 lines
1.6 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'},
}
}
local Rule = require('nvim-autopairs.rule')
require('nvim-autopairs').add_rules({
Rule("%", "%", "lua")
:with_pair(require('nvim-autopairs.ts-conds').is_ts_node({'string','comment'})),
Rule("$", "$", "lua")
:with_pair(require('nvim-autopairs.ts-conds').is_not_ts_node({'function'})),
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(']'),
Rule('%(.*%)%s*%=>$', ' { }', { 'typescript', 'typescriptreact', 'javascript' })
:use_regex(true)
:set_end_pair_length(2),
})
require("nvim-autopairs.completion.cmp").setup({
map_cr = true, -- map <CR> on insert mode
map_complete = true, -- it will auto insert `(` (map_char) after select function or method item
auto_select = true, -- automatically select the first item
insert = false, -- use insert confirm behavior instead of replace
map_char = { -- modifies the function or method delimiter by filetypes
all = '(',
tex = '{'
}
})