6 -- disable luasnip bindings for <tab> and <s-tab>
11 require("luasnip.loaders.from_snipmate").lazy_load()
12 require("luasnip.loaders.from_lua").load({ paths = vim.fn.stdpath("config") .. "/lua/snippets" })
20 store_selection_keys = "<Tab>",
24 { "echasnovski/mini.pairs",
27 modes = { insert = true, command = true, terminal = false },
28 -- skip autopair when next character is one of these
29 skip_next = [=[[%w%%%'%[%"%.%`%$]]=],
30 -- skip autopair when the cursor is inside these treesitter nodes
31 skip_ts = { "string" },
32 -- skip autopair when next character is closing pair
33 -- and there are more closing pairs than opening pairs
34 skip_unbalanced = true,
35 -- better deal with markdown code blocks
38 config = function(_, opts)
42 return not vim.g.minipairs_disable
45 vim.g.minipairs_disable = not state
49 local pairs = require("mini.pairs")
51 local open = pairs.open
52 --- Custom open command with extensions from LazyVim
53 ---@diagnostic disable-next-line: duplicate-set-field
54 pairs.open = function(pair, neigh_pattern)
55 if vim.fn.getcmdline() ~= "" then
56 return open(pair, neigh_pattern)
58 local o, c = pair:sub(1, 1), pair:sub(2, 2)
59 local line = vim.api.nvim_get_current_line()
60 local cursor = vim.api.nvim_win_get_cursor(0)
61 local next = line:sub(cursor[2] + 1, cursor[2] + 1)
62 local before = line:sub(1, cursor[2])
63 -- don't add fourth ` in markdown ```
64 if opts.markdown and o == "`" and vim.bo.filetype == "markdown" and before:match("^%s*``") then
65 return "`\n```" .. vim.api.nvim_replace_termcodes("<up>", true, true, true)
67 if opts.skip_next and next ~= "" and next:match(opts.skip_next) then
70 if opts.skip_ts and #opts.skip_ts > 0 then
71 local ok, captures = pcall(vim.treesitter.get_captures_at_pos, 0, cursor[1] - 1, math.max(cursor[2] - 1, 0))
72 for _, capture in ipairs(ok and captures or {}) do
73 if vim.tbl_contains(opts.skip_ts, capture.capture) then
78 if opts.skip_unbalanced and next == c and c ~= o then
79 local _, count_open = line:gsub(vim.pesc(pair:sub(1, 1)), "")
80 local _, count_close = line:gsub(vim.pesc(pair:sub(2, 2)), "")
81 if count_close > count_open then
85 return open(pair, neigh_pattern)
90 { "echasnovski/mini.surround",
92 -- HACK: use function to disable merging with LazyVim's keys definition
94 { "ys", desc = "Add surrounding", "n" },
95 { "S", desc = "Add surrounding", "x" },
96 { "ds", desc = "Delete surrounding" },
97 { "cs", desc = "Change surrounding" },
98 { "yss", "ys_", remap = true },
103 -- TODO: this is tpope/surround like, but should consider using vim-sandwich mappings
104 -- see: :h MiniSurround-vim-surround-config
114 config = function(_, opts)
115 require("mini.surround").setup(opts)
117 vim.keymap.del("x", "ys", { silent = true })
118 vim.keymap.set("x", "S", [[:<C-u>lua MiniSurround.add('visual')<CR>]], { silent = true })
122 { "echasnovski/mini.ai",
123 -- TODO: port vim text objects over
126 local ai = require("mini.ai")
129 custom_textobjects = {
130 o = ai.gen_spec.treesitter({ -- code block
131 a = { "@block.outer", "@conditional.outer", "@loop.outer" },
132 i = { "@block.inner", "@conditional.inner", "@loop.inner" },
134 f = ai.gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), -- function
135 c = ai.gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), -- class
136 t = { "<([%p%w]-)%f[^<%w][^<>]->.-</%1>", "^<.->().*()</[^/]->$" }, -- tags
137 d = { "%f[%d]%d+" }, -- digits
138 e = { -- Word with case
139 { "%u[%l%d]+%f[^%l%d]", "%f[%S][%l%d]+%f[^%l%d]", "%f[%P][%l%d]+%f[^%l%d]", "^[%l%d]+%f[^%l%d]" },
142 u = ai.gen_spec.function_call(), -- u for "Usage"
143 U = ai.gen_spec.function_call({ name_pattern = "[%w_]" }), -- without dot in function name
148 { "numToStr/Comment.nvim",
160 { "folke/lazydev.nvim",
165 { path = "${3rd}/luv/library", words = { "vim%.uv" } },
166 { path = "LazyVim", words = { "LazyVim" } },
167 { path = "snacks.nvim", words = { "Snacks" } },
168 { path = "lazy.nvim", words = { "LazySpec" } },