-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheditor.lua
674 lines (667 loc) · 19.5 KB
/
editor.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
return {
-- Better escape
{
"max397574/better-escape.nvim",
event = "InsertEnter",
opts = {
-- NOTE: Refer if any issues with tui like lazygit https://github.com/max397574/better-escape.nvim/issues/85
default_mappings = false,
mappings = {
i = {
j = {
k = "<Esc>",
j = "<Esc>",
},
},
},
},
},
-- Send buffers into early retirement by automatically closing them after x minutes of inactivity.
{
"chrisgrieser/nvim-early-retirement",
config = true,
event = "VeryLazy",
opts = {
-- if a buffer has been inactive for this many minutes, close it
retirementAgeMins = 30,
},
},
-- Use mini.icon for better performance
{
"echasnovski/mini.icons",
opts = {
file = {
[".keep"] = { glyph = "", hl = "MiniIconsGrey" },
["devcontainer.json"] = { glyph = "", hl = "MiniIconsAzure" },
},
filetype = {
dotenv = { glyph = "", hl = "MiniIconsYellow" },
},
},
config = function(_, options)
local icons = require("mini.icons")
icons.setup(options)
-- Mocking methods of 'nvim-tree/nvim-web-devicons' for better integrations with plugins outside 'mini.nvim'
icons.mock_nvim_web_devicons()
end,
},
--
-- Git signs
{
"lewis6991/gitsigns.nvim",
event = "VeryLazy",
opts = {
signs = {
add = { text = "▎" },
change = { text = "▎" },
delete = { text = "" },
topdelete = { text = "" },
changedelete = { text = "▎" },
untracked = { text = "▎" },
},
on_attach = function(buffer)
local gs = package.loaded.gitsigns
local function map(mode, l, r, desc)
vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc })
end
map("n", "]h", function()
if vim.wo.diff then
vim.cmd.normal({ "]c", bang = true })
else
gs.nav_hunk("next")
end
end, "Next Hunk")
map("n", "[h", function()
if vim.wo.diff then
vim.cmd.normal({ "[c", bang = true })
else
gs.nav_hunk("prev")
end
end, "Prev Hunk")
map("n", "]H", function()
gs.nav_hunk("last")
end, "Last Hunk")
map("n", "[H", function()
gs.nav_hunk("first")
end, "First Hunk")
map({ "n", "v" }, "<leader>ghs", ":Gitsigns stage_hunk<CR>", "Stage Hunk")
map({ "n", "v" }, "<leader>ghr", ":Gitsigns reset_hunk<CR>", "Reset Hunk")
map("n", "<leader>ghS", gs.stage_buffer, "Stage Buffer")
map("n", "<leader>ghu", gs.undo_stage_hunk, "Undo Stage Hunk")
map("n", "<leader>ghR", gs.reset_buffer, "Reset Buffer")
map("n", "<leader>ghp", gs.preview_hunk_inline, "Preview Hunk Inline")
map("n", "<leader>ghb", function()
gs.blame_line({ full = true })
end, "Blame Line")
map("n", "<leader>ghB", function()
gs.blame()
end, "Blame Buffer")
map("n", "<leader>ghd", gs.diffthis, "Diff This")
map("n", "<leader>ghD", function()
gs.diffthis("~")
end, "Diff This ~")
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "GitSigns Select Hunk")
-- Toggle blame line
map("n", "<leader>tb", function()
gs.toggle_current_line_blame()
end, "Toggle Blame Line")
end,
},
},
-- Tabline
{
"akinsho/bufferline.nvim",
event = "VeryLazy",
keys = {
{ "<leader>bp", "<Cmd>BufferLineTogglePin<CR>", desc = "Toggle Pin" },
{ "<leader>bP", "<Cmd>BufferLineGroupClose ungrouped<CR>", desc = "Delete Non-Pinned Buffers" },
{ "<leader>bo", "<Cmd>BufferLineCloseOthers<CR>", desc = "Delete Other Buffers" },
{ "<leader>br", "<Cmd>BufferLineCloseRight<CR>", desc = "Delete Buffers to the Right" },
{ "<leader>bl", "<Cmd>BufferLineCloseLeft<CR>", desc = "Delete Buffers to the Left" },
{ "<S-h>", "<cmd>BufferLineCyclePrev<cr>", desc = "Prev Buffer" },
{ "<S-l>", "<cmd>BufferLineCycleNext<cr>", desc = "Next Buffer" },
{ "[b", "<cmd>BufferLineCyclePrev<cr>", desc = "Prev Buffer" },
{ "]b", "<cmd>BufferLineCycleNext<cr>", desc = "Next Buffer" },
{ "[B", "<cmd>BufferLineMovePrev<cr>", desc = "Move buffer prev" },
{ "]B", "<cmd>BufferLineMoveNext<cr>", desc = "Move buffer next" },
},
opts = {
options = {
diagnostics = "nvim_lsp",
always_show_bufferline = false,
offsets = {
{
filetype = "neo-tree",
text = "Neo-tree",
highlight = "Directory",
text_align = "left",
},
},
},
},
config = function(_, opts)
require("bufferline").setup(opts)
-- Fix bufferline when restoring a session
vim.api.nvim_create_autocmd({ "BufAdd", "BufDelete" }, {
callback = function()
vim.schedule(function()
pcall(nvim_bufferline)
end)
end,
})
end,
},
-- Status line
{
"echasnovski/mini.statusline",
opts = {
set_vim_settings = false,
content = {
active = function()
local MiniStatusline = require("mini.statusline")
local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
local git = MiniStatusline.section_git({ trunc_width = 40 })
local filename = MiniStatusline.section_filename({ trunc_width = 140 })
local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 })
local lint_progress = function()
local linters = require("lint").get_running()
if #linters == 0 then
return ""
end
return " " .. table.concat(linters, ", ")
end
return MiniStatusline.combine_groups({
{ hl = mode_hl, strings = { mode:upper() } },
{ hl = "MiniStatuslineDevinfo", strings = { git, diagnostics, lint_progress() } },
"%<", -- Mark general truncate point
{ hl = "MiniStatuslineFilename", strings = { filename } },
"%=", -- End left alignment
{
hl = "MiniStatuslineFileinfo",
strings = {
vim.bo.filetype ~= ""
and require("mini.icons").get("filetype", vim.bo.filetype) .. " " .. vim.bo.filetype,
},
},
{ hl = mode_hl, strings = { "%l:%v" } },
})
end,
},
},
},
-- Remove buffer
{
"echasnovski/mini.bufremove",
keys = {
{
"<S-q>",
desc = "Delete buffer",
function()
require("mini.bufremove").delete(0, false)
end,
},
{
"<C-q>",
desc = "Delete buffer",
function()
require("mini.bufremove").delete(0, false)
end,
},
},
},
-- Indent
{
"echasnovski/mini.indentscope",
version = false,
event = "VeryLazy",
opts = {
symbol = "│",
options = { try_as_border = true },
},
init = function()
-- Disable mini.indentscope for some filetypes
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"dashboard",
"fzf",
"help",
"lazy",
"mason",
"toggleterm",
"Trouble",
"trouble",
},
callback = function()
vim.b.miniindentscope_disable = true
end,
})
end,
},
-- Which key
{
"folke/which-key.nvim",
event = "VeryLazy",
opts_extend = { "spec" },
opts = {
defaults = {},
---@type false | "classic" | "modern" | "helix"
preset = vim.g.which_key_preset or "helix", -- default is "classic"
-- Custom helix layout
win = vim.g.which_key_window or {
width = { min = 30, max = 60 },
height = { min = 4, max = 0.85 },
},
spec = {
{
mode = { "n", "v" },
{ "<leader><tab>", group = "tabs" },
{ "<leader>b", group = "buffer" },
{ "<leader>c", group = "code" },
{ "<leader>f", group = "file/find" },
{ "<leader>g", group = "git" },
{ "<leader>gh", group = "hunks" },
{ "<leader>q", group = "quit/session" },
{ "<leader>s", group = "search" },
{ "<leader>t", group = "toggle" },
{ "<leader>u", group = "ui", icon = { icon = " ", color = "cyan" } },
{ "<leader>w", group = "windows" },
{ "<leader>x", group = "diagnostics/quickfix", icon = { icon = " ", color = "green" } },
{ "[", group = "prev" },
{ "]", group = "next" },
{ "g", group = "goto" },
{ "gs", group = "surround" },
{ "z", group = "fold" },
},
},
},
keys = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Keymaps (which-key)",
},
},
config = function(_, opts)
local wk = require("which-key")
wk.setup(opts)
if not vim.tbl_isempty(opts.defaults) then
wk.register(opts.defaults)
end
end,
},
-- Better UI
{
"folke/noice.nvim",
event = "VeryLazy",
opts = {
lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
},
},
-- you can enable a preset for easier configuration
presets = {
bottom_search = true, -- use a classic bottom cmdline for search
command_palette = true, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
},
dependencies = {
"MunifTanjim/nui.nvim",
},
config = function(_, opts)
-- HACK: noice shows messages from before it was enabled,
-- but this is not ideal when Lazy is installing plugins,
-- so clear the messages in this case.
if vim.o.filetype == "lazy" then
vim.cmd([[messages clear]])
end
require("noice").setup(opts)
end,
},
-- Toggle term
{
"akinsho/toggleterm.nvim",
version = "*",
opts = {
size = 20,
open_mapping = [[<c-_>]],
dir = "git_dir",
hide_numbers = true,
shade_terminals = true,
shading_factor = 2,
start_in_insert = true,
insert_mappings = true,
persist_size = true,
close_on_exit = true,
shell = vim.o.shell,
},
keys = {
{
"<c-_>",
"<cmd>:ToggleTerm<cr>",
desc = "Toggle Term",
},
{
"<leader>ft",
"<cmd>:ToggleTerm<cr>",
desc = "Find Toggle Term",
},
-- Send to terminal
{
"<leader><c-_>",
"<cmd>:ToggleTermSendCurrentLine<cr>",
desc = "Send Current Line To Terminal",
},
{
"<leader><c-_>",
"<cmd>:ToggleTermSendVisualSelection<cr>",
desc = "Send Visual Selection To Terminal",
mode = "v",
},
{
"<leader>gg",
function()
local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new({
cmd = "lazygit",
dir = "git_dir",
direction = "float",
-- 90% width and height
float_opts = {
width = math.floor(vim.o.columns * 0.9),
height = math.floor(vim.o.lines * 0.9),
},
-- function to run on opening the terminal
on_open = function(term)
vim.cmd("startinsert!")
vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", { noremap = true, silent = true })
-- Allow to make it work for lazygit for Esc and ctrl + hjkl
vim.keymap.set("t", "<c-h>", "<c-h>", { buffer = term.bufnr, nowait = true })
vim.keymap.set("t", "<c-j>", "<c-j>", { buffer = term.bufnr, nowait = true })
vim.keymap.set("t", "<c-k>", "<c-k>", { buffer = term.bufnr, nowait = true })
vim.keymap.set("t", "<c-l>", "<c-l>", { buffer = term.bufnr, nowait = true })
vim.keymap.set("t", "<esc>", "<esc>", { buffer = term.bufnr, nowait = true })
end,
-- function to run on closing the terminal
on_close = function(_)
vim.cmd("startinsert!")
end,
})
lazygit:toggle()
end,
desc = "Lazygit Toggle",
mode = "n",
},
},
},
-- Trouble
{
"folke/trouble.nvim",
opts = {
modes = {
-- Diagnostics for the current buffer and errors from the current project
errors = {
mode = "diagnostics", -- inherit from diagnostics mode
filter = {
any = {
buf = 0, -- current buffer
{
severity = vim.diagnostic.severity.ERROR, -- errors only
-- limit to files in the current project
function(item)
return item.filename:find((vim.loop or vim.uv).cwd(), 1, true)
end,
},
},
},
},
},
},
cmd = "Trouble",
keys = {
{
"<leader>xx",
"<cmd>Trouble diagnostics toggle<cr>",
desc = "Diagnostics (Trouble)",
},
{
"<leader>xX",
"<cmd>Trouble diagnostics toggle filter.buf=0<cr>",
desc = "Buffer Diagnostics (Trouble)",
},
{
"<leader>cs",
"<cmd>Trouble symbols toggle focus=false<cr>",
desc = "Symbols (Trouble)",
},
{
"<leader>xL",
"<cmd>Trouble loclist toggle<cr>",
desc = "Location List (Trouble)",
},
{
"<leader>xQ",
"<cmd>Trouble qflist toggle<cr>",
desc = "Quickfix List (Trouble)",
},
},
},
{
"folke/todo-comments.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
opts = {},
keys = {
{
"<leader>xf",
":Trouble todo filter = {tag = {FIX,FIXME}}<CR>",
desc = "Fix/Fixme (Trouble)",
},
{
"<leader>xt",
":Trouble todo filter = {tag = {TODO}}<CR>",
desc = "Todo (Troble)",
},
},
},
-- Navigate text with flash
{
"folke/flash.nvim",
event = "VeryLazy",
vscode = true, -- Enable this plugin for vscode
---@type Flash.Config
opts = {},
keys = {
{
"s",
mode = { "n", "x", "o" },
function()
require("flash").jump()
end,
desc = "Flash",
},
{
"S",
mode = { "n", "o", "x" },
function()
require("flash").treesitter()
end,
desc = "Flash Treesitter",
},
{
"r",
mode = "o",
function()
require("flash").remote()
end,
desc = "Remote Flash",
},
{
"R",
mode = { "o", "x" },
function()
require("flash").treesitter_search()
end,
desc = "Treesitter Search",
},
{
"<c-s>",
mode = { "c" },
function()
require("flash").toggle()
end,
desc = "Toggle Flash Search",
},
{
"<leader>j",
mode = { "n" },
function()
local Flash = require("flash")
---@param opts Flash.Format
local function format(opts)
-- always show first and second label
return {
{ opts.match.label1, "FlashMatch" },
{ opts.match.label2, "FlashLabel" },
}
end
Flash.jump({
search = { mode = "search" },
label = { after = false, before = { 0, 0 }, uppercase = false, format = format },
pattern = [[\<]],
action = function(match, state)
state:hide()
Flash.jump({
search = { max_length = 0 },
highlight = { matches = false },
label = { format = format },
matcher = function(win)
-- limit matches to the current label
return vim.tbl_filter(function(m)
return m.label == match.label and m.win == win
end, state.results)
end,
labeler = function(matches)
for _, m in ipairs(matches) do
m.label = m.label2 -- use the second label
end
end,
})
end,
labeler = function(matches, state)
local labels = state:labels()
for m, match in ipairs(matches) do
match.label1 = labels[math.floor((m - 1) / #labels) + 1]
match.label2 = labels[(m - 1) % #labels + 1]
match.label = match.label1
end
end,
})
end,
desc = "2-char jump",
},
},
},
-- Use gs for surround as `s` is used by flash
{
"echasnovski/mini.surround",
vscode = true,
opts = {
mappings = {
add = "gsa", -- Add surrounding in Normal and Visual modes
delete = "gsd", -- Delete surrounding
find = "gsf", -- Find surrounding (to the right)
find_left = "gsF", -- Find surrounding (to the left)
highlight = "gsh", -- Highlight surrounding
replace = "gsr", -- Replace surrounding
update_n_lines = "gsn", -- Update `n_lines`
},
},
},
-- Mini pairs
{
"echasnovski/mini.pairs",
event = "VeryLazy",
vscode = true,
opts = {},
},
-- Layout with edgy
{
"folke/edgy.nvim",
event = "VeryLazy",
keys = {
{
"<leader>ue",
function()
require("edgy").toggle()
end,
desc = "Edgy Toggle",
},
{
"<leader>uE",
function()
require("edgy").select()
end,
desc = "Edgy Select Window",
},
},
opts = function()
local opts = {
wo = {
spell = false,
},
animate = {
enabled = false,
},
bottom = {
{
ft = "toggleterm",
size = { height = 0.4 },
filter = function(_, win)
return vim.api.nvim_win_get_config(win).relative == ""
end,
},
"Trouble",
{
ft = "qf",
title = "QuickFix",
},
{
ft = "help",
size = { height = 20 },
-- don't open help files in edgy that we're editing
filter = function(buf)
return vim.bo[buf].buftype == "help"
end,
},
},
keys = {
-- increase width
["<c-Right>"] = function(win)
win:resize("width", 2)
end,
-- decrease width
["<c-Left>"] = function(win)
win:resize("width", -2)
end,
-- increase height
["<c-Up>"] = function(win)
win:resize("height", 2)
end,
-- decrease height
["<c-Down>"] = function(win)
win:resize("height", -2)
end,
},
}
return opts
end,
},
}