]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/editor.lua
lazyvim: absorb editor plugins
[dotfiles.git] / nvim / lua / plugins / editor.lua
1 ---@type LazySpec
2 return {
3 { "stevearc/oil.nvim",
4 opts = {
5 keymaps = {
6 ["g?"] = "actions.show_help",
7 ["<CR>"] = "actions.select",
8 ["<C-s>"] = "actions.select_vsplit",
9 ["<C-h>"] = false, -- used to be actions.select_split
10 ["<C-t>"] = "actions.select_tab",
11 ["<C-p>"] = "actions.preview",
12 ["<C-c>"] = "actions.close",
13 ["<C-l>"] = false, -- used to be actions.refresh
14 ["-"] = "actions.parent",
15 ["_"] = "actions.open_cwd",
16 ["`"] = "actions.cd",
17 ["~"] = "actions.tcd",
18 ["gs"] = "actions.change_sort",
19 ["gx"] = "actions.open_external",
20 ["g."] = "actions.toggle_hidden",
21 ["g\\"] = "actions.toggle_trash",
22 },
23 },
24 dependencies = {"nvim-tree/nvim-web-devicons"},
25 },
26 { "folke/trouble.nvim",
27 cmd = { "Trouble" },
28 opts = {
29 modes = {
30 lsp = {
31 win = { position = "right" },
32 },
33 },
34 },
35 keys = {
36 { "<leader>xx", "<cmd>Trouble diagnostics toggle<cr>", desc = "Diagnostics (Trouble)" },
37 { "<leader>xX", "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", desc = "Buffer Diagnostics (Trouble)" },
38 { "<leader>cs", "<cmd>Trouble symbols toggle<cr>", desc = "Symbols (Trouble)" },
39 { "<leader>cS", "<cmd>Trouble lsp toggle<cr>", desc = "LSP references/definitions/... (Trouble)" },
40 { "<leader>xL", "<cmd>Trouble loclist toggle<cr>", desc = "Location List (Trouble)" },
41 { "<leader>xQ", "<cmd>Trouble qflist toggle<cr>", desc = "Quickfix List (Trouble)" },
42 {
43 "[q",
44 function()
45 if require("trouble").is_open() then
46 require("trouble").prev({ skip_groups = true, jump = true })
47 else
48 local ok, err = pcall(vim.cmd.cprev)
49 if not ok then
50 vim.notify(err, vim.log.levels.ERROR)
51 end
52 end
53 end,
54 desc = "Previous Trouble/Quickfix Item",
55 },
56 {
57 "]q",
58 function()
59 if require("trouble").is_open() then
60 require("trouble").next({ skip_groups = true, jump = true })
61 else
62 local ok, err = pcall(vim.cmd.cnext)
63 if not ok then
64 vim.notify(err, vim.log.levels.ERROR)
65 end
66 end
67 end,
68 desc = "Next Trouble/Quickfix Item",
69 },
70 },
71 },
72 { "folke/todo-comments.nvim",
73 -- Finds and lists all of the TODO, HACK, BUG, etc comment
74 -- in your project and loads them into a browsable list.
75 cmd = { "TodoTrouble", "TodoTelescope" },
76 event = "LazyFile",
77 -- stylua: ignore
78 keys = {
79 { "]t", function() require("todo-comments").jump_next() end, desc = "Next Todo Comment" },
80 { "[t", function() require("todo-comments").jump_prev() end, desc = "Previous Todo Comment" },
81 { "<leader>xt", "<cmd>Trouble todo toggle<cr>", desc = "Todo (Trouble)" },
82 { "<leader>xT", "<cmd>Trouble todo toggle filter = {tag = {TODO,FIX,FIXME}}<cr>", desc = "Todo/Fix/Fixme (Trouble)" },
83 { "<leader>st", "<cmd>TodoTelescope<cr>", desc = "Todo" },
84 { "<leader>sT", "<cmd>TodoTelescope keywords=TODO,FIX,FIXME<cr>", desc = "Todo/Fix/Fixme" },
85 },
86 opts = {}
87 },
88 { "folke/flash.nvim",
89 -- Flash enhances the built-in search functionality by showing labels
90 -- at the end of each match, letting you quickly jump to a specific
91 -- location.
92 event = "VeryLazy",
93 vscode = true,
94 ---@type Flash.Config
95 opts = {},
96 -- stylua: ignore
97 keys = {
98 { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
99 { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
100 { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
101 { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
102 { "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
103 },
104 },
105 { "lewis6991/gitsigns.nvim",
106 -- git signs highlights text that has changed since the list
107 -- git commit, and also lets you interactively stage & unstage
108 -- hunks in a commit.
109 event = "LazyFile",
110 opts = {
111 signs = {
112 add = { text = "▎" },
113 change = { text = "▎" },
114 delete = { text = "" },
115 topdelete = { text = "" },
116 changedelete = { text = "▎" },
117 untracked = { text = "▎" },
118 },
119 signs_staged = {
120 add = { text = "▎" },
121 change = { text = "▎" },
122 delete = { text = "" },
123 topdelete = { text = "" },
124 changedelete = { text = "▎" },
125 },
126 on_attach = function(buffer)
127 local gs = package.loaded.gitsigns
128
129 local function map(mode, l, r, desc)
130 vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc })
131 end
132
133 -- stylua: ignore start
134 map("n", "]h", function()
135 if vim.wo.diff then
136 vim.cmd.normal({ "]c", bang = true })
137 else
138 gs.nav_hunk("next")
139 end
140 end, "Next Hunk")
141 map("n", "[h", function()
142 if vim.wo.diff then
143 vim.cmd.normal({ "[c", bang = true })
144 else
145 gs.nav_hunk("prev")
146 end
147 end, "Prev Hunk")
148 map("n", "]H", function() gs.nav_hunk("last") end, "Last Hunk")
149 map("n", "[H", function() gs.nav_hunk("first") end, "First Hunk")
150 map({ "n", "v" }, "<leader>ghs", ":Gitsigns stage_hunk<CR>", "Stage Hunk")
151 map({ "n", "v" }, "<leader>ghr", ":Gitsigns reset_hunk<CR>", "Reset Hunk")
152 map("n", "<leader>ghS", gs.stage_buffer, "Stage Buffer")
153 map("n", "<leader>ghu", gs.undo_stage_hunk, "Undo Stage Hunk")
154 map("n", "<leader>ghR", gs.reset_buffer, "Reset Buffer")
155 map("n", "<leader>ghp", gs.preview_hunk_inline, "Preview Hunk Inline")
156 map("n", "<leader>ghb", function() gs.blame_line({ full = true }) end, "Blame Line")
157 map("n", "<leader>ghB", function() gs.blame() end, "Blame Buffer")
158 map("n", "<leader>ghd", gs.diffthis, "Diff This")
159 map("n", "<leader>ghD", function() gs.diffthis("~") end, "Diff This ~")
160 map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "GitSigns Select Hunk")
161 Snacks.toggle({
162 name = "Git Signs",
163 get = function()
164 return require("gitsigns.config").config.signcolumn
165 end,
166 set = function(state)
167 require("gitsigns").toggle_signs(state)
168 end,
169 }):map("<leader>uG")
170 end,
171 },
172 },
173
174 -- TODO: currently unused plugins, check and enable/remove
175 { "MagicDuck/grug-far.nvim", enabled = false,
176 -- search/replace in multiple files
177 opts = { headerMaxWidth = 80 },
178 cmd = "GrugFar",
179 keys = {
180 {
181 "<leader>sr",
182 function()
183 local grug = require("grug-far")
184 local ext = vim.bo.buftype == "" and vim.fn.expand("%:e")
185 grug.open({
186 transient = true,
187 prefills = {
188 filesFilter = ext and ext ~= "" and "*." .. ext or nil,
189 },
190 })
191 end,
192 mode = { "n", "v" },
193 desc = "Search and Replace",
194 },
195 },
196 },
197 { "folke/which-key.nvim",
198 -- which-key helps you remember key bindings by showing a popup
199 -- with the active keybindings of the command you started typing.
200 -- TODO: replace with mini.clue
201 event = "VeryLazy",
202 opts_extend = { "spec" },
203 opts = {
204 preset = "helix",
205 defaults = {},
206 spec = {
207 {
208 mode = { "n", "v" },
209 { "<leader><tab>", group = "tabs" },
210 { "<leader>c", group = "code" },
211 { "<leader>d", group = "debug" },
212 { "<leader>dp", group = "profiler" },
213 { "<leader>f", group = "file/find" },
214 { "<leader>g", group = "git" },
215 { "<leader>gh", group = "hunks" },
216 { "<leader>q", group = "quit/session" },
217 { "<leader>s", group = "search" },
218 { "<leader>u", group = "ui", icon = { icon = "󰙵 ", color = "cyan" } },
219 { "<leader>x", group = "diagnostics/quickfix", icon = { icon = "󱖫 ", color = "green" } },
220 { "[", group = "prev" },
221 { "]", group = "next" },
222 { "g", group = "goto" },
223 { "gs", group = "surround" },
224 { "z", group = "fold" },
225 {
226 "<leader>b",
227 group = "buffer",
228 expand = function()
229 return require("which-key.extras").expand.buf()
230 end,
231 },
232 {
233 "<leader>w",
234 group = "windows",
235 proxy = "<c-w>",
236 expand = function()
237 return require("which-key.extras").expand.win()
238 end,
239 },
240 -- better descriptions
241 { "gx", desc = "Open with system app" },
242 },
243 },
244 },
245 keys = {
246 {
247 "<leader>?",
248 function()
249 require("which-key").show({ global = false })
250 end,
251 desc = "Buffer Keymaps (which-key)",
252 },
253 {
254 "<c-w><space>",
255 function()
256 require("which-key").show({ keys = "<c-w>", loop = true })
257 end,
258 desc = "Window Hydra Mode (which-key)",
259 },
260 },
261 config = function(_, opts)
262 local wk = require("which-key")
263 wk.setup(opts)
264 if not vim.tbl_isempty(opts.defaults) then
265 LazyVim.warn("which-key: opts.defaults is deprecated. Please use opts.spec instead.")
266 wk.register(opts.defaults)
267 end
268 end,
269 },
270 }