-- snacks.nvim: only picker, lazygit, terminal and image are used. -- fff handles files and grep in the full profile; if its native library was -- not built (or in slim), those maps fall back to snacks.picker. local full = vim.g.profile == "full" local fff_built local function use_fff() if fff_built == nil then fff_built = false local plugin = full and require("lazy.core.config").plugins["fff.nvim"] if plugin then local ext = jit.os == "OSX" and "dylib" or "so" fff_built = vim.uv.fs_stat(plugin.dir .. "/target/release/libfff_nvim." .. ext) ~= nil end end return fff_built end local function files() if use_fff() then require("fff").find_files() else Snacks.picker.files() end end local function grep() if use_fff() then require("fff").live_grep() else Snacks.picker.grep() end end local function fuzzy_grep() if use_fff() then require("fff").live_grep({ grep = { modes = { "fuzzy", "plain" } } }) else Snacks.picker.grep() end end -- The dashboard centres every line on its own, so pad them all to one width to keep the art aligned. local header = (function() local lines = { [[ __ __]], [[ |__| ____ | | _________ ____ ______ ____ ___________]], [[ | |/ _ \| |/ /\_ __ \_/ __ \ / ___// \_/ __ \_ __ \]], [[ | ( <_> ) < | | \/\ ___/ \___ \| | \ ___/| | \/]], [[/\__| |\____/|__|_ \ |__| \___ >____ >___| /\___ >__|]], [[\______| \/ \/ \/ \/ \/]], } local width = 0 for _, line in ipairs(lines) do width = math.max(width, #line) end for i, line in ipairs(lines) do lines[i] = line .. string.rep(" ", width - #line) end return table.concat(lines, "\n") end)() -- The finder entries press the same leader maps as below, so fff and the snacks fallback stay in one place. local dashboard = { enabled = true, width = 66, -- the header is 64 columns wide preset = { header = header, keys = { { icon = " ", key = "f", desc = "Find file", action = "ff" }, { icon = " ", key = "r", desc = "Recent files", action = "fr" }, { icon = " ", key = "w", desc = "Find word", action = "fw" }, { icon = " ", key = "g", desc = "Grep", action = "fg" }, { icon = " ", key = "p", desc = "Projects", action = "fp" }, { icon = " ", key = "s", desc = "Restore session", action = function() require("persistence").load() end, }, { icon = "󰒲 ", key = "l", desc = "Lazy", action = ":Lazy" }, { icon = " ", key = "q", desc = "Quit", action = ":qa" }, }, }, } local keys = { { "ff", files, desc = "Find files" }, { "", files, desc = "Find files" }, { ",", function() Snacks.picker.buffers() end, desc = "Buffers" }, { "fr", function() Snacks.picker.recent() end, desc = "Recent files" }, { "fp", function() Snacks.picker.projects() end, desc = "Projects" }, { "fR", function() Snacks.picker.resume() end, desc = "Resume last picker" }, { "fu", function() Snacks.picker.undo() end, desc = "Undo history" }, { "fG", fuzzy_grep, desc = "Fuzzy grep" }, { "gB", function() Snacks.picker.git_branches() end, desc = "Git branches" }, { "gc", function() Snacks.picker.git_log() end, desc = "Git log" }, { "gC", function() Snacks.picker.git_log_file() end, desc = "Git log (file)" }, { "gx", function() Snacks.picker.git_status() end, desc = "Git status" }, { "bd", function() Snacks.bufdelete() end, desc = "Delete buffer" }, { "bD", function() Snacks.bufdelete({ force = true }) end, desc = "Delete buffer (force)" }, { "bo", function() Snacks.bufdelete.other() end, desc = "Delete other buffers" }, { "bb", "e #", desc = "Alternate buffer" }, { "fg", grep, desc = "Live grep" }, { "fw", function() Snacks.picker.grep_word() end, desc = "Grep word under cursor", mode = { "n", "x" } }, { "fb", function() Snacks.picker.buffers() end, desc = "Buffers" }, { "fh", function() Snacks.picker.help() end, desc = "Help" }, { "fk", function() Snacks.picker.keymaps() end, desc = "Keymaps" }, { "fd", function() Snacks.picker.diagnostics() end, desc = "Diagnostics" }, { "cn", function() Snacks.words.jump(vim.v.count1) end, desc = "Next reference", mode = { "n", "t" } }, { "cp", function() Snacks.words.jump(-vim.v.count1) end, desc = "Previous reference", mode = { "n", "t" } }, { "", function() Snacks.terminal.toggle(nil, { win = { position = "float" } }) end, desc = "Toggle terminal", mode = { "n", "t" } }, { "", function() Snacks.terminal.toggle(nil, { win = { position = "float" } }) end, desc = "which_key_ignore", mode = { "n", "t" } }, } if full then table.insert(keys, { "fs", function() Snacks.picker.lsp_workspace_symbols() end, desc = "Workspace symbols" }) table.insert(keys, { "fo", function() Snacks.picker.lsp_symbols() end, desc = "Document symbols" }) end if vim.fn.executable("lazygit") == 1 then table.insert(keys, { "gg", function() Snacks.lazygit() end, desc = "Lazygit" }) end local picker = {} if full then -- sends selected files or grep hits to the running agent. picker = { actions = { sidekick_send = function(...) return require("sidekick.cli.picker.snacks").send(...) end, }, win = { input = { keys = { [""] = { "sidekick_send", mode = { "n", "i" } } } } }, } end return { { "folke/snacks.nvim", lazy = false, priority = 1000, keys = keys, opts = { dashboard = dashboard, picker = picker, lazygit = {}, terminal = {}, image = { enabled = full }, words = { enabled = true }, statuscolumn = { enabled = true }, quickfile = { enabled = true }, }, config = function(_, opts) require("snacks").setup(opts) require("core.toggles").setup() end, }, { "dmtrKovalenko/fff.nvim", cond = full, lazy = true, -- Only the Lua library; the workspace also has bins that fail to link. build = "cargo build --release -p fff-nvim --lib", opts = {}, }, }