Skip to content

Commit 6d1771c

Browse files
committed
nvim
1 parent 4fd2558 commit 6d1771c

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

home/.config/nvim/init.lua

+56-3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ local function nmapp(lhs, rhs, opts)
208208
end
209209
vim.api.nvim_set_keymap('n', lhs, rhs, options)
210210
end
211+
-- diagnostic
212+
local diagnostic_goto = function(next, severity)
213+
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
214+
severity = severity and vim.diagnostic.severity[severity] or nil
215+
return function()
216+
go({ severity = severity })
217+
end
218+
end
211219

212220
map({'n', 'x'}, ':', ';')
213221
map({'n', 'x'}, ';', ':')
@@ -261,9 +269,11 @@ nmap('<leader>gb', function() require'my.util'.blame_line() end)
261269
nmap('<leader>gB', '<cmd>Git blame<cr>')
262270
nmap('<leader>gd', '<cmd>Git diff<cr>')
263271
nmap('<leader>ge', function() require'neo-tree.command'.execute({source='git_status', toggle = true}) end, 'Git explorer')
264-
nmap('<leader>gf', function() require'my.util'.lazygit({size={width=0.9}, args={'log', '-f', vim.api.nvim_buf_get_name(0)}}) end)
265-
nmap('<leader>gg', '<cmd>lua ToggleTermCmd({cmd="lazygit",direction="float"})<cr>')
266-
nmap('<leader>gl', '<cmd>Git log<cr>')
272+
nmap('<leader>gf', function() Snacks.lazygit.log_file() end, 'Lazygit Current File History')
273+
nmap('<leader>gg', function() Snacks.lazygit( { cwd = MyProject() }) end, 'Lazygit (Root Dir)')
274+
nmap('<leader>gG', function() Snacks.lazygit() end, 'Lazygit (cwd)')
275+
nmap('<leader>gl', function() Snacks.lazygit.log({ cwd = MyProject() }) end, 'Lazygit Log')
276+
nmap('<leader>gL', function() Snacks.lazygit.log() end, 'Lazygit Log (cwd)')
267277
nmap('<leader>gw', function() require'snacks'.gitbrowse() end, 'Git Browse')
268278
-- <leader>h (harpoon)
269279
local mark = require("harpoon.mark")
@@ -311,6 +321,9 @@ nmap('<leader>tn', '<cmd>set number!<cr>')
311321
nmap('<leader>tq', '<cmd>Trouble qflist toggle<cr>', 'Quickfix List (Trouble)')
312322
nmap('<leader>ts', '<cmd>set spell!<cr>')
313323
nmap('<leader>tw', '<cmd>set wrap!<cr>')
324+
-- u (inspect)
325+
nmap('<leader>ui', '<cmd>Inspect<cr>')
326+
nmap('<leader>uI', '<cmd>InspectTree<cr>')
314327
-- w (window)
315328
nmapp('<leader>wo', '<C-w>o')
316329
nmapp('<leader>ws', '<C-w>s')
@@ -351,6 +364,13 @@ nmap(']q', function()
351364
end
352365
end
353366
end)
367+
nmap('<leader>cd', vim.diagnostic.open_float, 'Line Diagnostics')
368+
nmap(']d', diagnostic_goto(true), 'Next Diagnostic')
369+
nmap('[d', diagnostic_goto(false), 'Prev Diagnostic')
370+
nmap(']e', diagnostic_goto(true, 'ERROR'), 'Next Error')
371+
nmap('[e', diagnostic_goto(false, 'ERROR'), 'Prev Error')
372+
nmap(']w', diagnostic_goto(true, 'WARN'), 'Next Warning')
373+
nmap('[w', diagnostic_goto(false, 'WARN'), 'Prev Warning')
354374
nmap('<f1>', '<cmd>Gdb<cr>')
355375
nmap('<f2>', '<cmd>Program<cr>')
356376
nmap('<f11>', '<cmd>Break<cr>')
@@ -396,6 +416,39 @@ local autocmds = {
396416
}
397417
nvim_create_augroups(autocmds)
398418

419+
-- close some filetypes with <q>
420+
vim.api.nvim_create_autocmd("FileType", {
421+
group = vim.api.nvim_create_augroup("my_close_with_q", {clear=true}),
422+
pattern = {
423+
"checkhealth",
424+
"dbout",
425+
"help",
426+
"lspinfo",
427+
"neotest-output",
428+
"neotest-output-panel",
429+
"neotest-summary",
430+
"notify",
431+
"qf",
432+
"snacks_win",
433+
"spectre_panel",
434+
"startuptime",
435+
"tsplayground",
436+
},
437+
callback = function(event)
438+
vim.bo[event.buf].buflisted = false
439+
vim.schedule(function()
440+
vim.keymap.set("n", "q", function()
441+
vim.cmd("close")
442+
pcall(vim.api.nvim_buf_delete, event.buf, { force = true })
443+
end, {
444+
buffer = event.buf,
445+
silent = true,
446+
desc = "Quit buffer",
447+
})
448+
end)
449+
end,
450+
})
451+
399452
--cmd 'autocmd TermOpen * startinsert'
400453
cmd 'autocmd WinEnter * if &buftype ==# "terminal" | startinsert | endif'
401454

0 commit comments

Comments
 (0)