marleyvim/nvim/lua/snacks-nvim.lua

135 lines
3.3 KiB
Lua
Raw Permalink Normal View History

2024-11-28 20:30:20 -08:00
-- Snacks needs to be loaded very early, so it gets its own special file.
local set = vim.keymap.set
require('snacks').setup({
bigfile = { enabled = true },
2024-11-29 20:19:17 -08:00
notifier = { enabled = true },
quickfile = { enabled = true },
statuscolumn = { enabled = true },
words = { enabled = true },
2024-11-28 20:30:20 -08:00
})
2024-11-29 20:19:17 -08:00
-- Debuggers -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
_G.dd = function(...)
Snacks.debug.inspect(...)
end
_G.bt = function()
Snacks.debug.backtrace()
end
vim.print = _G.dd
-- Notifier -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>un', function()
Snacks.notifier.hide()
2024-12-01 17:10:02 -08:00
end, { desc = 'dismiss all notifications' })
2024-11-29 20:19:17 -08:00
2024-11-28 20:30:20 -08:00
-- Buffers -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>bd', function()
Snacks.bufdelete()
2024-12-01 17:10:02 -08:00
end, { desc = 'delete buffer' })
2024-11-28 20:30:20 -08:00
set({ 'n' }, '<LEADER>bo', function()
Snacks.bufdelete.other()
2024-12-01 17:10:02 -08:00
end, { desc = 'delete other buffers' })
2024-11-28 20:30:20 -08:00
-- Toggles -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
local toggle = Snacks.toggle
toggle.option('spell', { name = 'spelling' }):map('<LEADER>us')
toggle.option('wrap', { name = 'wrap' }):map('<LEADER>uw')
toggle.option('relativenumber', { name = 'relative number' }):map('<LEADER>uL')
toggle.line_number():map('<LEADER>ul')
toggle.diagnostics():map('<LEADER>ud')
toggle
.option(
'conceallevel',
{ off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2 }
)
:map('<LEADER>uc')
toggle.treesitter():map('<LEADER>uT')
if vim.lsp.inlay_hint then
toggle.inlay_hints():map('<LEADER>uh')
end
2024-12-15 12:21:28 -08:00
toggle({
name = 'auto format (global)',
get = function()
return vim.g.autoformat == nil or vim.g.autoformat
end,
set = function(enable)
vim.g.autoformat = (enable == nil and true) or enable
vim.b.autoformat = nil
end,
}):map('<LEADER>uf')
toggle({
name = 'auto format (buffer)',
get = function()
local buf = vim.api.nvim_get_current_buf()
local gopt = vim.g.autoformat
local bopt = vim.b[buf].autoformat
if bopt ~= nil then
return bopt
end
return gopt == nil or gopt
end,
set = function(enable)
vim.b.autoformat = (enable == nil and true) or enable
end,
}):map('<LEADER>uF')
2024-11-28 20:30:20 -08:00
-- Git -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>gb', function()
Snacks.git.blame_line()
2024-12-01 17:10:02 -08:00
end, { desc = 'git blame line' })
2024-11-28 20:30:20 -08:00
set({ 'n' }, '<LEADER>gB', function()
Snacks.gitbrowse()
2024-12-01 17:10:02 -08:00
end, { desc = 'git browse (open)' })
2024-11-28 20:30:20 -08:00
set({ 'n' }, '<LEADER>gY', function()
Snacks.gitbrowse({
open = function(url)
vim.fn.setreg('+', url)
end,
})
2024-12-01 17:10:02 -08:00
end, { desc = 'git browse (copy)' })
2024-11-28 20:30:20 -08:00
-- LazyGit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
if vim.fn.executable('lazygit') == 1 then
set({ 'n' }, '<LEADER>gg', function()
2024-12-01 11:07:51 -08:00
Snacks.lazygit({ cwd = MarleyVim.root() })
2024-12-01 17:10:02 -08:00
end, { desc = 'lazygit (root dir)' })
2024-11-28 20:30:20 -08:00
-- set({ 'n' }, '<LEADER>gG', function()
-- Snacks.lazygit()
-- end, { desc = 'Lazygit (cwd)' })
set({ 'n' }, '<LEADER>gf', function()
Snacks.lazygit.log_file()
2024-12-01 17:10:02 -08:00
end, { desc = 'lazygit current file history' })
2024-11-28 20:30:20 -08:00
set({ 'n' }, '<LEADER>gl', function()
2024-12-01 11:07:51 -08:00
Snacks.lazygit.log({ cwd = MarleyVim.root() })
2024-11-28 20:30:20 -08:00
end, { desc = 'Lazygit log' })
-- set({ 'n' }, '<LEADER>gL', function()
-- Snacks.lazygit.log()
-- end, { desc = 'Lazygit log (cwd)' })
end