- opts.completion = vim.tbl_extend("force", opts.completion, {
- completeopt = "menu,menuone,noselect",
- })
- -- TODO: review if I want to keep any of LazyVim's mappings
- opts.mapping = cmp.mapping.preset.insert({
- -- lazyvims
- ["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
- ["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
- ["<C-b>"] = cmp.mapping.scroll_docs(-4),
- ["<C-f>"] = cmp.mapping.scroll_docs(4),
- ["<C-e>"] = cmp.mapping.abort(),
- ["<C-Space>"] = cmp.mapping.complete(),
- -- mine
- ["<Tab>"] = cmp.mapping(function(fallback)
- if cmp.visible() then
- cmp.select_next_item()
- elseif luasnip.expand_or_jumpable() then
- luasnip.expand_or_jump()
- elseif has_words_before() then
- cmp.complete()
- else
- fallback()
+ local pairs = require("mini.pairs")
+ pairs.setup(opts)
+ local open = pairs.open
+ --- Custom open command with extensions from LazyVim
+ ---@diagnostic disable-next-line: duplicate-set-field
+ pairs.open = function(pair, neigh_pattern)
+ if vim.fn.getcmdline() ~= "" then
+ return open(pair, neigh_pattern)
+ end
+ local o, c = pair:sub(1, 1), pair:sub(2, 2)
+ local line = vim.api.nvim_get_current_line()
+ local cursor = vim.api.nvim_win_get_cursor(0)
+ local next = line:sub(cursor[2] + 1, cursor[2] + 1)
+ local before = line:sub(1, cursor[2])
+ -- don't add fourth ` in markdown ```
+ if opts.markdown and o == "`" and vim.bo.filetype == "markdown" and before:match("^%s*``") then
+ return "`\n```" .. vim.api.nvim_replace_termcodes("<up>", true, true, true)
+ end
+ if opts.skip_next and next ~= "" and next:match(opts.skip_next) then
+ return o
+ end
+ if opts.skip_ts and #opts.skip_ts > 0 then
+ local ok, captures = pcall(vim.treesitter.get_captures_at_pos, 0, cursor[1] - 1, math.max(cursor[2] - 1, 0))
+ for _, capture in ipairs(ok and captures or {}) do
+ if vim.tbl_contains(opts.skip_ts, capture.capture) then
+ return o
+ end