nvim-config/lua/plugins/nvim-autopairs.lua

43 lines
1.5 KiB
Lua

---@type LazySpec
return {
"windwp/nvim-autopairs",
config = function(plugin, opts)
require("astronvim.plugins.configs.nvim-autopairs")(plugin, opts)
local Rule = require "nvim-autopairs.rule"
local npairs = require "nvim-autopairs"
local cond = require "nvim-autopairs.conds"
npairs.add_rules {
Rule(' ', ' ')
:with_pair(function(options)
local pair = options.line:sub(options.col - 1, options.col)
return vim.tbl_contains({ '()', '{}', '[]' }, pair)
end)
:with_move(cond.none())
:with_cr(cond.none())
:with_del(function(options)
local col = vim.api.nvim_win_get_cursor(0)[2]
local context = options.line:sub(col - 1, col + 2)
return vim.tbl_contains({ '( )', '{ }', '[ ]' }, context)
end),
Rule('', ' )')
:with_pair(cond.none())
:with_move(function(options) return options.char == ')' end)
:with_cr(cond.none())
:with_del(cond.none())
:use_key(')'),
Rule('', ' }')
:with_pair(cond.none())
:with_move(function(options) return options.char == '}' end)
:with_cr(cond.none())
:with_del(cond.none())
:use_key('}'),
Rule('', ' ]')
:with_pair(cond.none())
:with_move(function(options) return options.char == ']' end)
:with_cr(cond.none())
:with_del(cond.none())
:use_key(']'),
}
end,
}