aboutsummaryrefslogtreecommitdiff
path: root/common/config/nvim/lua/plugins/autopairs.lua
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2025-08-30 00:50:31 +0200
committersrdusr <trevorgray@srdusr.com>2025-08-30 00:50:31 +0200
commit5928998af5404ae2be84c6cecc10ebf84bd3f3ed (patch)
treec72a17cb6eb84f01c52666e3f95853cf5e636bb8 /common/config/nvim/lua/plugins/autopairs.lua
parentbba0c17c6c0bc310e44ae45b9573d2dc99b8157f (diff)
parent2a8020a2e9b7ef2ee77ddee14892127a4eb95187 (diff)
downloaddotfiles-5928998af5404ae2be84c6cecc10ebf84bd3f3ed.tar.gz
dotfiles-5928998af5404ae2be84c6cecc10ebf84bd3f3ed.zip
Add 'common/config/nvim/' from commit '2a8020a2e9b7ef2ee77ddee14892127a4eb95187'
git-subtree-dir: common/config/nvim git-subtree-mainline: bba0c17c6c0bc310e44ae45b9573d2dc99b8157f git-subtree-split: 2a8020a2e9b7ef2ee77ddee14892127a4eb95187
Diffstat (limited to 'common/config/nvim/lua/plugins/autopairs.lua')
-rw-r--r--common/config/nvim/lua/plugins/autopairs.lua87
1 files changed, 87 insertions, 0 deletions
diff --git a/common/config/nvim/lua/plugins/autopairs.lua b/common/config/nvim/lua/plugins/autopairs.lua
new file mode 100644
index 0000000..90b62b1
--- /dev/null
+++ b/common/config/nvim/lua/plugins/autopairs.lua
@@ -0,0 +1,87 @@
+local status_ok, autopairs = pcall(require, "nvim-autopairs")
+if not status_ok then
+ return
+end
+
+autopairs.setup({
+ check_ts = true,
+ ts_config = {
+ lua = { "string", "source" },
+ javascript = { "string", "template_string" },
+ java = false,
+ },
+ map = "<M-e>",
+ pairs_map = {
+ ["<"] = ">",
+ },
+ disable_filetype = { "TelescopePrompt", "spectre_panel" },
+ disable_in_macro = true,
+ disable_in_visualblock = true,
+ enable_moveright = true,
+ enable_afterquote = true, -- add bracket pairs after quote
+ enable_check_bracket_line = false, --- check bracket in same line
+ enable_bracket_in_quote = true, --
+ break_undo = true, -- switch for basic rule break undo sequence
+ --fast_wrap = {
+ -- chars = { "{", "[", "(", '"', "'" },
+ -- pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
+ -- offset = 0, -- Offset from pattern match
+ -- end_key = "$",
+ -- keys = "qwertyuiopzxcvbnmasdfghjkl",
+ -- check_comma = true,
+ -- highlight = "PmenuSel",
+ -- highlight_grey = "LineNr",
+ --},
+})
+local Rule = require("nvim-autopairs.rule")
+
+local cond = require("nvim-autopairs.conds")
+
+autopairs.add_rules({
+ Rule("`", "'", "tex"),
+ Rule("$", "$", "tex"),
+ Rule(" ", " ")
+ :with_pair(function(opts)
+ local pair = opts.line:sub(opts.col, opts.col + 1)
+ return vim.tbl_contains({ "$$", "()", "{}", "[]", "<>" }, pair)
+ end)
+ :with_move(cond.none())
+ :with_cr(cond.none())
+ :with_del(function(opts)
+ local col = vim.api.nvim_win_get_cursor(0)[2]
+ local context = opts.line:sub(col - 1, col + 2)
+ return vim.tbl_contains({ "$ $", "( )", "{ }", "[ ]", "< >" }, context)
+ end),
+ Rule("$ ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("[ ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("{ ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("( ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+ Rule("< ", " ", "tex"):with_pair(cond.not_after_regex(" ")):with_del(cond.none()),
+})
+
+autopairs.get_rule("$"):with_move(function(opts)
+ return opts.char == opts.next_char:sub(1, 1)
+end)
+
+-- import nvim-cmp plugin (completions plugin)
+local cmp = require("cmp")
+
+-- import nvim-autopairs completion functionality
+local cmp_autopairs = require("nvim-autopairs.completion.cmp")
+
+-- make autopairs and completion work together
+cmp.event:on(
+ "confirm_done",
+ cmp_autopairs.on_confirm_done({
+ filetypes = {
+ tex = false, -- Disable for tex
+ },
+ })
+)
+
+--local cmp_autopairs = require "nvim-autopairs.completion.cmp"
+--local cmp_status_ok, cmp = pcall(require, "cmp")
+--if not cmp_status_ok then
+-- return
+--end
+--cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = { tex = "" } })