nvim/lua/pika/plugins/snacks.lua
2025-05-19 17:50:15 +02:00

395 lines
8 KiB
Lua

return {
"folke/snacks.nvim",
priority = 1000,
lazy = false,
---@type snacks.Config
opts = {
explorer = { enabled = false },
bigfile = { enabled = true },
quickfile = { enabled = true },
---@class snacks.animate.Config
---@field easing? snacks.animate.easing|snacks.animate.easing.Fn
animate = {
enabled = true,
---@type snacks.animate.Duration|number
duration = 4, -- ms per step
easing = "linear",
fps = 60, -- frames per second. Global setting for all animations
},
notifier = { enabled = true },
indent = { enabled = true },
toggle = { enabled = true },
scroll = { enabled = true },
dashboard = {
row = nil,
col = nil,
pane_gap = 2,
enabled = true,
-- example = "pokemon",
sections = {
{ section = "header" },
{
pane = 2,
section = "terminal",
cmd = "colorscript -e square",
height = 6,
padding = 1,
},
{ section = "keys", gap = 1, padding = 1 },
{
pane = 2,
icon = "",
title = "Recent Files",
section = "recent_files",
indent = 2,
padding = 1,
},
{ pane = 2, icon = "", title = "Projects", section = "projects", indent = 2, padding = 1 },
{
pane = 2,
icon = "",
title = "Git Status",
section = "terminal",
enabled = function()
return Snacks.git.get_root() ~= nil
end,
cmd = "git status --short --branch --renames",
height = 5,
padding = 1,
ttl = 5 * 60,
indent = 3,
},
{ section = "startup" },
},
},
},
keys = {
-- Top Pickers & Explorer
{
"<leader>sf",
function()
Snacks.picker.smart()
end,
desc = "Smart Find Files",
},
{
"<leader><space>",
function()
Snacks.picker.buffers()
end,
desc = "Buffers",
},
{
"<leader>/",
function()
Snacks.picker.grep()
end,
desc = "Grep",
},
{
"<leader>:",
function()
Snacks.picker.command_history()
end,
desc = "Command History",
},
{
"<leader>n",
function()
Snacks.picker.notifications()
end,
desc = "Notification History",
},
-- {
-- "<leader>e",
-- function()
-- Snacks.explorer()
-- end,
-- desc = "File Explorer",
-- },
-- find
-- {
-- "<leader>fb",
-- function()
-- Snacks.picker.buffers()
-- end,
-- desc = "Buffers",
-- },
-- both of the next two bindings are the same, just for different keymaps
-- ─< find [N]eovim config >────────────────────────────────────────────────────────────
{
"<leader>fn",
function()
Snacks.picker.files({ cwd = vim.fn.stdpath("config") })
end,
desc = "Find Config File",
},
-- ─< find neovim [C]onfig >────────────────────────────────────────────────────────────
{
"<leader>fc",
function()
Snacks.picker.files({ cwd = vim.fn.stdpath("config") })
end,
desc = "Find Config File",
},
{
"<leader>ff",
function()
Snacks.picker.files()
end,
desc = "Find Files",
},
{
"<leader>fg",
function()
Snacks.picker.git_files()
end,
desc = "Find Git Files",
},
{
"<leader>fp",
function()
Snacks.picker.projects()
end,
desc = "Projects",
},
{
"<leader>fr",
function()
Snacks.picker.recent()
end,
desc = "Recent",
},
-- git
{
"<leader>gb",
function()
Snacks.picker.git_branches()
end,
desc = "Git Branches",
},
{
"<leader>gl",
function()
Snacks.picker.git_log()
end,
desc = "Git Log",
},
{
"<leader>gL",
function()
Snacks.picker.git_log_line()
end,
desc = "Git Log Line",
},
{
"<leader>gs",
function()
Snacks.picker.git_status()
end,
desc = "Git Status",
},
{
"<leader>gS",
function()
Snacks.picker.git_stash()
end,
desc = "Git Stash",
},
{
"<leader>gd",
function()
Snacks.picker.git_diff()
end,
desc = "Git Diff (Hunks)",
},
{
"<leader>gf",
function()
Snacks.picker.git_log_file()
end,
desc = "Git Log File",
},
-- Grep
{
"<leader>sg",
function()
Snacks.picker.grep()
end,
desc = "Grep",
},
{
"<leader>sw",
function()
Snacks.picker.grep_word()
end,
desc = "Visual selection or word",
mode = { "n", "x" },
},
{
"<leader>T",
function()
Snacks.picker.colorschemes()
end,
desc = "Colorschemes",
},
-- LSP
{
"gd",
function()
Snacks.picker.lsp_definitions()
end,
desc = "Goto Definition",
},
{
"gD",
function()
Snacks.picker.lsp_declarations()
end,
desc = "Goto Declaration",
},
{
"gr",
function()
Snacks.picker.lsp_references()
end,
nowait = true,
desc = "References",
},
{
"gI",
function()
Snacks.picker.lsp_implementations()
end,
desc = "Goto Implementation",
},
{
"gy",
function()
Snacks.picker.lsp_type_definitions()
end,
desc = "Goto T[y]pe Definition",
},
-- Other
{
"<leader>z",
function()
Snacks.zen()
end,
desc = "Toggle Zen Mode",
},
{
"<leader>Z",
function()
Snacks.zen.zoom()
end,
desc = "Toggle Zoom",
},
{
"<leader>n",
function()
Snacks.notifier.show_history()
end,
desc = "Notification History",
},
{
"<leader>cR",
function()
Snacks.rename.rename_file()
end,
desc = "Rename File",
},
{
"<leader>gB",
function()
Snacks.gitbrowse()
end,
desc = "Git Browse",
mode = { "n", "v" },
},
{
"<leader>gg",
function()
Snacks.lazygit()
end,
desc = "Lazygit",
},
{
"<leader>un",
function()
Snacks.notifier.hide()
end,
desc = "Dismiss All Notifications",
},
{
"<leader>N",
desc = "Neovim News",
function()
Snacks.win({
file = vim.api.nvim_get_runtime_file("doc/news.txt", false)[1],
width = 0.6,
height = 0.6,
wo = {
spell = false,
wrap = false,
signcolumn = "yes",
statuscolumn = " ",
conceallevel = 3,
},
})
end,
},
},
init = function()
vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
callback = function()
-- Setup some globals for debugging (lazy-loaded)
_G.dd = function(...)
Snacks.debug.inspect(...)
end
_G.bt = function()
Snacks.debug.backtrace()
end
vim.print = _G.dd -- Override print to use snacks for `:=` command
-- Create some toggle mappings
Snacks.toggle.option("spell", { name = "Spelling" }):map("<leader>us")
Snacks.toggle.option("wrap", { name = "Wrap" }):map("<leader>uw")
Snacks.toggle.option("relativenumber", { name = "Relative Number" }):map("<leader>uL")
Snacks.toggle.diagnostics():map("<leader>ud")
Snacks.toggle.line_number():map("<leader>ul")
Snacks.toggle
.option("conceallevel", { off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2 })
:map("<leader>uc")
Snacks.toggle.treesitter():map("<leader>uT")
Snacks.toggle
.option("background", { off = "light", on = "dark", name = "Dark Background" })
:map("<leader>ub")
Snacks.toggle.inlay_hints():map("<leader>uh")
Snacks.toggle.indent():map("<leader>ug")
Snacks.toggle.dim():map("<leader>uD")
end,
})
end,
dependencies = {
{
"folke/persistence.nvim",
event = "BufReadPre",
opts = {},
-- stylua: ignore
keys = {
-- { "<leader>qs", function() require("persistence").load() end, desc = "Restore Session" },
-- { "<leader>ql", function() require("persistence").load({ last = true }) end, desc = "Restore Last Session" },
-- { "<leader>qd", function() require("persistence").stop() end, desc = "Don't Save Current Session" },
{ "<leader>db", "<cmd>:Dashboard<CR>", desc = "Dashboard"},
{ "<leader>dq", function() require("inspire").show_quote() end, desc = "Show Inspire Quote"},
},
},
},
}