Skip to main content

Snacks_picker

info

You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed.

Options

Additional options for this extra can be configured in your lua/config/options.lua file:

lua/config/options.lua
-- In case you don't want to use `:LazyExtras`,
-- then you need to set the option below.
vim.g.lazyvim_picker = "snacks"

Below you can find a list of included plugins and their default settings.

caution

You don't need to copy the default settings to your config. They are only shown here for reference.

snacks.nvim

opts = {
picker = {
win = {
input = {
keys = {
["<a-c>"] = {
"toggle_cwd",
mode = { "n", "i" },
},
},
},
},
actions = {
---@param p snacks.Picker
toggle_cwd = function(p)
local root = LazyVim.root({ buf = p.input.filter.current_buf, normalize = true })
local cwd = vim.fs.normalize((vim.uv or vim.loop).cwd() or ".")
local current = p:cwd()
p:set_cwd(current == root and cwd or root)
p:find()
end,
},
},
}

snacks.nvim

opts = function(_, opts)
if LazyVim.has("trouble.nvim") then
return vim.tbl_deep_extend("force", opts or {}, {
picker = {
actions = {
trouble_open = function(...)
return require("trouble.sources.snacks").actions.trouble_open.action(...)
end,
},
win = {
input = {
keys = {
["<a-t>"] = {
"trouble_open",
mode = { "n", "i" },
},
},
},
},
},
})
end
end

nvim-lspconfig

opts = function()
local Keys = require("lazyvim.plugins.lsp.keymaps").get()
-- stylua: ignore
vim.list_extend(Keys, {
{ "gd", function() Snacks.picker.lsp_definitions() end, desc = "Goto Definition", has = "definition" },
{ "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" },
{ "<leader>ss", function() Snacks.picker.lsp_symbols({ filter = LazyVim.config.kind_filter }) end, desc = "LSP Symbols", has = "documentSymbol" },
{ "<leader>sS", function() Snacks.picker.lsp_workspace_symbols({ filter = LazyVim.config.kind_filter }) end, desc = "LSP Workspace Symbols", has = "workspace/symbols" },
})
end

snacks.nvim

opts = function(_, opts)
table.insert(opts.dashboard.preset.keys, 3, {
icon = " ",
key = "p",
desc = "Projects",
action = ":lua Snacks.picker.projects()",
})
end

snacks.nvim

opts = {
picker = {
win = {
input = {
keys = {
["<a-s>"] = { "flash", mode = { "n", "i" } },
["s"] = { "flash" },
},
},
},
actions = {
flash = function(picker)
require("flash").jump({
pattern = "^",
label = { after = { 0, 0 } },
search = {
mode = "search",
exclude = {
function(win)
return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "snacks_picker_list"
end,
},
},
action = function(match)
local idx = picker.list:row2idx(match.pos[1])
picker.list:_move(idx, true, true)
end,
})
end,
},
},
}

todo-comments.nvim (optional)

opts = nil

alpha-nvim (optional)

opts = function(_, dashboard)
local button = dashboard.button("p", " " .. " Projects", [[<cmd> lua Snacks.picker.projects() <cr>]])
button.opts.hl = "AlphaButtons"
button.opts.hl_shortcut = "AlphaShortcut"
table.insert(dashboard.section.buttons.val, 4, button)
end

mini.starter (optional)

opts = function(_, opts)
local items = {
{
name = "Projects",
action = [[lua Snacks.picker.projects()]],
section = string.rep(" ", 22) .. "Telescope",
},
}
vim.list_extend(opts.items, items)
end

dashboard-nvim (optional)

opts = function(_, opts)
if not vim.tbl_get(opts, "config", "center") then
return
end
local projects = {
action = "lua Snacks.picker.projects()",
desc = " Projects",
icon = " ",
key = "p",
}

projects.desc = projects.desc .. string.rep(" ", 43 - #projects.desc)
projects.key_format = " %s"

table.insert(opts.config.center, 3, projects)
end

flash.nvim (optional)

opts = nil