]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/coding.lua
vim: do not set pastetoggle in nvim
[dotfiles.git] / nvim / lua / plugins / coding.lua
1 ---@type LazySpec
2 return {
3 -- snippets
4 { "l3mon4d3/luasnip",
5 build = "make install_jsregexp", -- optional
6 dependencies = {
7 { "honza/vim-snippets", },
8 },
9 config = function()
10 local snippets = vim.fn.stdpath("config").."/snippets"
11 require("luasnip.loaders.from_snipmate").load({ paths = { snippets }})
12 require("luasnip.loaders.from_lua").load({ paths = { snippets }})
13 end,
14 keys = function()
15 return {}
16 end,
17 opts = {
18 history = true,
19 delete_check_events = "TextChanged",
20 store_selection_keys = "<Tab>",
21 },
22 },
23
24 { "echasnovski/mini.pairs",
25 event = "VeryLazy",
26 opts = {
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
36 markdown = true,
37 },
38 config = function(_, opts)
39 Snacks.toggle({
40 name = "Mini Pairs",
41 get = function()
42 return not vim.g.minipairs_disable
43 end,
44 set = function(state)
45 vim.g.minipairs_disable = not state
46 end,
47 }):map("<leader>up")
48
49 local pairs = require("mini.pairs")
50 pairs.setup(opts)
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)
57 end
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)
66 end
67 if opts.skip_next and next ~= "" and next:match(opts.skip_next) then
68 return o
69 end
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
74 return o
75 end
76 end
77 end
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
82 return o
83 end
84 end
85 return open(pair, neigh_pattern)
86 end
87 end,
88 },
89
90 { "echasnovski/mini.surround",
91 keys = function()
92 -- HACK: use function to disable merging with LazyVim's keys definition
93 return {
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 },
99 }
100 end,
101 opts = {
102 mappings = {
103 -- TODO: this is tpope/surround like, but should consider using vim-sandwich mappings
104 -- see: :h MiniSurround-vim-surround-config
105 add = "ys",
106 delete = "ds",
107 find = "",
108 find_left = "",
109 highlight = "",
110 replace = "cs",
111 update_n_lines = "",
112 },
113 },
114 config = function(_, opts)
115 require("mini.surround").setup(opts)
116 -- remap visual
117 vim.keymap.del("x", "ys", { silent = true })
118 vim.keymap.set("x", "S", [[:<C-u>lua MiniSurround.add('visual')<CR>]], { silent = true })
119 end,
120 },
121
122 { "echasnovski/mini.ai",
123 -- TODO: port vim text objects over
124 event = "VeryLazy",
125 opts = function()
126 local ai = require("mini.ai")
127 return {
128 n_lines = 500,
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" },
133 }),
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]" },
140 "^().*()$",
141 },
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
144 },
145 }
146 end,
147 },
148 { "numToStr/Comment.nvim",
149 dependencies = {
150 { "JoosepAlviste/nvim-ts-context-commentstring", -- nested language commenting (f.ex markdown code blocks)
151 opts = { enable_autocmd = false, },
152 }
153 },
154 opts = function(_, opts)
155 local tscci = require('ts_context_commentstring.integrations.comment_nvim')
156 vim.tbl_deep_extend('force', opts, {
157 toggler = {
158 line = "gcc",
159 block = "gbb",
160 },
161 mappings = {
162 basic = true,
163 extra = true,
164 },
165 pre_hook = tscci.create_pre_hook()
166 })
167 return opts
168 end,
169 },
170 { "danymat/neogen", -- Generate annotations like doxygen
171 cmd = "Neogen",
172 keys = {
173 { "<leader>cn", function() require("neogen").generate() end, desc = "Generate Annotations (Neogen)", },
174 },
175 opts = {
176 snippet_engine = "luasnip",
177 },
178 },
179 { "folke/lazydev.nvim",
180 ft = "lua",
181 cmd = "LazyDev",
182 opts = {
183 library = {
184 { path = "${3rd}/luv/library", words = { "vim%.uv" } },
185 { path = "snacks.nvim", words = { "Snacks" } },
186 { path = "lazy.nvim", words = { "LazySpec" } },
187 },
188 },
189 },
190 { "gbprod/yanky.nvim", enabled = false, -- better yank/paste
191 -- TODO: integrate?
192 -- I'm not entirely convinced, it doesn't provide functionality like vim-peekaboo,
193 -- maybe it can supplement it though?
194 -- Also, see issues on OSC52: https://github.com/gbprod/yanky.nvim/issues/213
195 recommended = true,
196 desc = "Better Yank/Paste",
197 event = "LazyFile",
198 opts = {
199 highlight = { timer = 150 },
200 },
201 keys = {
202 {
203 "<leader>p",
204 function() vim.cmd([[YankyRingHistory]]) end,
205 mode = { "n", "x" },
206 desc = "Open Yank History",
207 },
208 -- stylua: ignore
209 { "y", "<Plug>(YankyYank)", mode = { "n", "x" }, desc = "Yank Text" },
210 { "p", "<Plug>(YankyPutAfter)", mode = { "n", "x" }, desc = "Put Text After Cursor" },
211 { "P", "<Plug>(YankyPutBefore)", mode = { "n", "x" }, desc = "Put Text Before Cursor" },
212 { "gp", "<Plug>(YankyGPutAfter)", mode = { "n", "x" }, desc = "Put Text After Selection" },
213 { "gP", "<Plug>(YankyGPutBefore)", mode = { "n", "x" }, desc = "Put Text Before Selection" },
214 { "[y", "<Plug>(YankyCycleForward)", desc = "Cycle Forward Through Yank History" },
215 { "]y", "<Plug>(YankyCycleBackward)", desc = "Cycle Backward Through Yank History" },
216 { "]p", "<Plug>(YankyPutIndentAfterLinewise)", desc = "Put Indented After Cursor (Linewise)" },
217 { "[p", "<Plug>(YankyPutIndentBeforeLinewise)", desc = "Put Indented Before Cursor (Linewise)" },
218 { "]P", "<Plug>(YankyPutIndentAfterLinewise)", desc = "Put Indented After Cursor (Linewise)" },
219 { "[P", "<Plug>(YankyPutIndentBeforeLinewise)", desc = "Put Indented Before Cursor (Linewise)" },
220 { ">p", "<Plug>(YankyPutIndentAfterShiftRight)", desc = "Put and Indent Right" },
221 { "<p", "<Plug>(YankyPutIndentAfterShiftLeft)", desc = "Put and Indent Left" },
222 { ">P", "<Plug>(YankyPutIndentBeforeShiftRight)", desc = "Put Before and Indent Right" },
223 { "<P", "<Plug>(YankyPutIndentBeforeShiftLeft)", desc = "Put Before and Indent Left" },
224 { "=p", "<Plug>(YankyPutAfterFilter)", desc = "Put After Applying a Filter" },
225 { "=P", "<Plug>(YankyPutBeforeFilter)", desc = "Put Before Applying a Filter" },
226 },
227 },
228
229 { "andrewferrier/debugprint.nvim",
230 dependencies = { "nvim-treesitter" },
231 -- TODO: setup debugprint (or maybe not)
232 opts = { }
233 }
234 }