]> git.rmz.io Git - dotfiles.git/blob - nvim/lua/plugins/editor.lua
nvim: add mini.hipatterns to highlight hex colours and any strings
[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"},
76 event = { "BufReadPost", "BufNewFile", "BufWritePre" },
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 },
84 opts = {}
85 },
86 { "echasnovski/mini.hipatterns", -- highlight hex colours and other matched words
87 event = { "BufReadPost", "BufNewFile", "BufWritePre" },
88 opts = function()
89 local hi = require("mini.hipatterns")
90 return {
91 highlighters = {
92 hex_color = hi.gen_highlighter.hex_color({ priority = 2000 }),
93 },
94 }
95 end,
96 },
97 { "folke/flash.nvim",
98 -- Flash enhances the built-in search functionality by showing labels
99 -- at the end of each match, letting you quickly jump to a specific
100 -- location.
101 event = "VeryLazy",
102 vscode = true,
103 ---@type Flash.Config
104 opts = {},
105 -- stylua: ignore
106 keys = {
107 { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
108 { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
109 { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
110 { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
111 { "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
112 },
113 },
114 { "lewis6991/gitsigns.nvim",
115 -- git signs highlights text that has changed since the list
116 -- git commit, and also lets you interactively stage & unstage
117 -- hunks in a commit.
118 event = { "BufReadPost", "BufNewFile", "BufWritePre" },
119 opts = {
120 signs = {
121 add = { text = "▎" },
122 change = { text = "▎" },
123 delete = { text = "" },
124 topdelete = { text = "" },
125 changedelete = { text = "▎" },
126 untracked = { text = "▎" },
127 },
128 signs_staged = {
129 add = { text = "▎" },
130 change = { text = "▎" },
131 delete = { text = "" },
132 topdelete = { text = "" },
133 changedelete = { text = "▎" },
134 },
135 on_attach = function(buffer)
136 local gs = package.loaded.gitsigns
137
138 local function map(mode, l, r, desc)
139 vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc })
140 end
141
142 -- stylua: ignore start
143 map("n", "]h", function()
144 if vim.wo.diff then
145 vim.cmd.normal({ "]c", bang = true })
146 else
147 gs.nav_hunk("next")
148 end
149 end, "Next Hunk")
150 map("n", "[h", function()
151 if vim.wo.diff then
152 vim.cmd.normal({ "[c", bang = true })
153 else
154 gs.nav_hunk("prev")
155 end
156 end, "Prev Hunk")
157 map("n", "]H", function() gs.nav_hunk("last") end, "Last Hunk")
158 map("n", "[H", function() gs.nav_hunk("first") end, "First Hunk")
159 map({ "n", "v" }, "<leader>ghs", ":Gitsigns stage_hunk<CR>", "Stage Hunk")
160 map({ "n", "v" }, "<leader>ghr", ":Gitsigns reset_hunk<CR>", "Reset Hunk")
161 map("n", "<leader>ghS", gs.stage_buffer, "Stage Buffer")
162 map("n", "<leader>ghu", gs.undo_stage_hunk, "Undo Stage Hunk")
163 map("n", "<leader>ghR", gs.reset_buffer, "Reset Buffer")
164 map("n", "<leader>ghp", gs.preview_hunk_inline, "Preview Hunk Inline")
165 map("n", "<leader>ghb", function() gs.blame_line({ full = true }) end, "Blame Line")
166 map("n", "<leader>ghB", function() gs.blame() end, "Blame Buffer")
167 map("n", "<leader>ghd", gs.diffthis, "Diff This")
168 map("n", "<leader>ghD", function() gs.diffthis("~") end, "Diff This ~")
169 map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "GitSigns Select Hunk")
170 Snacks.toggle({
171 name = "Git Signs",
172 get = function()
173 return require("gitsigns.config").config.signcolumn
174 end,
175 set = function(state)
176 require("gitsigns").toggle_signs(state)
177 end,
178 }):map("<leader>uG")
179 end,
180 },
181 },
182
183 -- TODO: currently unused plugins, check and enable/remove
184 { "MagicDuck/grug-far.nvim", enabled = false,
185 -- search/replace in multiple files
186 opts = { headerMaxWidth = 80 },
187 cmd = "GrugFar",
188 keys = {
189 {
190 "<leader>sr",
191 function()
192 local grug = require("grug-far")
193 local ext = vim.bo.buftype == "" and vim.fn.expand("%:e")
194 grug.open({
195 transient = true,
196 prefills = {
197 filesFilter = ext and ext ~= "" and "*." .. ext or nil,
198 },
199 })
200 end,
201 mode = { "n", "v" },
202 desc = "Search and Replace",
203 },
204 },
205 },
206 { "aymericbeaumet/vim-symlink",
207 dependencies = { "moll/vim-bbye" }, -- NOTE: Snacks.buddelete also provides this
208 },
209 }