Share your layouts! #1306
drowning-cat
started this conversation in
Show and tell
Replies: 4 comments 15 replies
-
Floating previewExpand configurationpicker = {
sources = {
explorer = {
on_show = function(picker)
local show = false
local gap = 1
local clamp_width = function(value)
return math.max(20, math.min(100, value))
end
--
local position = picker.resolved_layout.layout.position
local rel = picker.layout.root
local update = function(win) ---@param win snacks.win
local border = win:border_size().left + win:border_size().right
win.opts.row = vim.api.nvim_win_get_position(rel.win)[1]
win.opts.height = 0.8
if position == 'left' then
win.opts.col = vim.api.nvim_win_get_width(rel.win) + gap
win.opts.width = clamp_width(vim.o.columns - border - win.opts.col)
end
if position == 'right' then
win.opts.col = -vim.api.nvim_win_get_width(rel.win) - gap
win.opts.width = clamp_width(vim.o.columns - border + win.opts.col)
end
win:update()
end
local preview_win = Snacks.win.new {
relative = 'editor',
external = false,
focusable = false,
border = 'rounded',
backdrop = false,
show = show,
bo = {
filetype = 'snacks_float_preview',
buftype = 'nofile',
buflisted = false,
swapfile = false,
undofile = false,
},
on_win = function(win)
update(win)
picker:show_preview()
end,
}
rel:on('WinLeave', function()
vim.schedule(function()
if not picker:is_focused() then
picker.preview.win:close()
end
end)
end)
rel:on('WinResized', function()
update(preview_win)
end)
picker.preview.win = preview_win
picker.main = preview_win.win
end,
on_close = function(picker)
picker.preview.win:close()
end,
layout = {
preset = 'sidebar',
preview = false, ---@diagnostic disable-line
},
actions = {
-- `<A-p>`
toggle_preview = function(picker) --[[Override]]
picker.preview.win:toggle()
end,
},
},
},
}, Floating explorerExpand configurationpicker = {
sources = {
explorer = {
actions = {
bufadd = function(_, item)
if vim.fn.bufexists(item.file) == 0 then
local buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_buf_set_name(buf, item.file)
vim.api.nvim_buf_call(buf, vim.cmd.edit)
end
end,
confirm_nofocus = function(picker, item)
if item.dir then
picker:action 'confirm'
else
picker:action 'bufadd'
end
end,
},
win = {
list = {
keys = {
['l'] = 'confirm_nofocus',
['L'] = 'confirm',
},
},
},
auto_close = true,
layout = {
cycle = true,
preview = true, ---@diagnostic disable-line: assign-type-mismatch
layout = {
box = 'horizontal',
position = 'float',
height = 0.95,
width = 0,
border = 'rounded',
{
box = 'vertical',
width = 40,
min_width = 40,
{ win = 'input', height = 1, title = '{title} {live} {flags}', border = 'single' },
{ win = 'list' },
},
{ win = 'preview', width = 0, border = 'left' },
},
},
},
},
}, Persistent colorscheme pickerRelated: #1239 (comment) Expand configuration-- init.lua
---@param fallback? string
_G.get_colorscheme = function(fallback)
if not vim.g.COLORS_NAME then
vim.cmd.rshada()
end
if not vim.g.COLORS_NAME or vim.g.COLORS_NAME == '' then
return fallback or 'default'
end
return vim.g.COLORS_NAME
end
---@param colorscheme? string
_G.save_colorscheme = function(colorscheme)
colorscheme = colorscheme or vim.g.colors_name
if get_colorscheme() == colorscheme then
return
end
vim.g.COLORS_NAME = colorscheme
vim.cmd.wshada()
end
require('lazy').setup {
spec = {
{ import = 'plugins' },
},
install = {
colorscheme = { get_colorscheme 'habamax' },
},
} -- plugins/snacks.lua
return {
'folke/snacks.nvim',
priority = 1000,
lazy = false,
init = function()
vim.api.nvim_create_autocmd('User', {
pattern = { 'LazyDone', 'VeryLazy' },
callback = function()
pcall(vim.cmd.colorscheme, get_colorscheme())
return vim.g.colors_name == get_colorscheme 'default'
end,
})
end,
---@type snacks.Config
opts = {
picker = {
sources = {
colorschemes = {
confirm = function(picker, item)
vim.g.snacks_colors_confirm = true
Snacks.picker.sources.colorschemes.confirm(picker, item)
save_colorscheme(item.text)
end,
on_close = function()
if vim.g.snacks_colors_confirm ~= true then
pcall(vim.cmd.colorscheme, get_colorscheme())
end
vim.g.snacks_colors_confirm = nil
end,
on_change = function(_, item)
if item then
pcall(vim.cmd.colorscheme, item.text)
end
end,
layout = { preset = 'sidebar' },
},
},
},
},
} |
Beta Was this translation helpful? Give feedback.
14 replies
-
Here are my (in progress) picker layouts. The style is based on that used for Telescope in NvChad. I'm using the Tokyonight colorscheme with specific highlights for Snacks pickers. Some screenshots File picker: Buffer picker: Icon picker: Snacks Picker Configpicker = {
prompt = ' ',
layouts = {
my_default_layout = {
layout = {
box = 'vertical',
width = 0.9,
height = 0.9,
border = 'none',
{ win = 'input', height = 1, border = 'single', title = 'Find {title} {live} {flags}', title_pos = 'center' },
{
box = 'horizontal',
{ win = 'list', border = { '🭽', '▔', '🭾', '▕', '🭿', '▁', '🭼', '▏' },
{ win = 'preview', border = { '🭽', '▔', '🭾', '▕', '🭿', '▁', '🭼', '▏' }, width = 0.6 },
},
},
},
my_vertical_layout = {
layout = {
box = 'vertical',
width = 0.8,
height = 0.9,
border = 'none',
{ win = 'input', border = 'single', height = 1, title = 'Find {title} {live} {flags}', title_pos = 'center' },
{ win = 'list', border = { '🭽', '▔', '🭾', '▕', '🭿', '▁', '🭼', '▏' }, height = 8 },
{ win = 'preview', border = { '🭽', '▔', '🭾', '▕', '🭿', '▁', '🭼', '▏' } },
},
},
vscode = {
layout = {
width = 0.5,
},
},
},
sources = {
autocmds = { layout = { preset = 'my_default_layout' } },
buffers = { layout = { preset = 'my_vertical_layout' } },
files = { layout = { preset = 'my_default_layout' } },
grep = { layout = { preset = 'my_default_layout' } },
grep_word = { layout = { preset = 'my_default_layout' } },
help = { layout = { preset = 'my_default_layout' } },
keymaps = { layout = { preset = 'vscode' } },
lazy = { layout = { preset = 'my_default_layout' } },
lines = { layout = { preset = 'my_default_layout' } },
recent = { layout = { preset = 'my_vertical_layout' }, title = 'Most Recently Used Files' },
undo = { layout = { preset = 'my_default_layout' } },
},
}, Tokyonight Color Scheme Configrequire('tokyonight').setup({
style = 'night',
on_highlights = function(highlights, colors)
-- Colors for Snacks pickers
highlights.SnacksPickerBoxTitle = { bg = '#1c99f2', fg = '#ffffff', bold = true }
highlights.SnacksPickerInput = { bg = '#23273b', fg = '#C0CAF5' }
highlights.SnacksPickerInputBorder = { bg = '#23273b', fg = '#23273b' }
highlights.SnacksPickerInputTitle = { bg = '#1c99f2', fg = '#ffffff', bold = true }
highlights.SnacksPickerList = { bg = '#262e46' }
highlights.SnacksPickerListBorder = { bg = '#262e46', fg = '#23273b' }
highlights.SnacksPickerListCursorLine = { bg = '#1a1d2f' }
highlights.SnacksPickerPreviewBorder = { bg = '#16161E', fg = '#23273b' }
highlights.SnacksPickerPrompt = { bg = '#23273b', fg = '#1c99f2' }
end,
})
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Replicating NvChad's iconic telescope for snacks pickerThis is what it looks like :Config:snacks picker : opts = {
picker = {
enabled = true,
layout = {
-- The default layout for "telescopy" pickers, e.g. `files`, `commands`, ...
-- It will not override non-standard pickers, e.g. `explorer`, `lines`, ...
preset = function()
return vim.o.columns >= 120 and 'telescope' or 'vertical'
end,
},
layouts = {
telescope = {
-- Copy from https://github.com/folke/snacks.nvim/blob/main/docs/picker.md#telescope
reverse = false,
layout = {
box = 'horizontal',
backdrop = false,
height = 0.9,
border = 'none',
{
box = 'vertical',
{
win = 'input',
height = 1,
border = 'rounded',
title = '{title} {live} {flags}',
title_pos = 'center',
},
{ win = 'list', title = ' Results ', title_pos = 'center', border = 'rounded' },
},
{
win = 'preview',
title = '{preview:Preview}',
width = 0.51, -- Change the preview width
border = 'rounded',
title_pos = 'center',
},
},
},
},
sources = {
files = {},
explorer = {
layout = {
layout = {
position = 'right',
},
},
},
lines = {
layout = {
preset = function()
return vim.o.columns >= 120 and 'telescope' or 'vertical'
end,
},
},
},
}
} Highlight Group : vim.api.nvim_set_hl(0, 'FloatBorder', { fg = '#45475A', bg = 'NONE' })
vim.api.nvim_set_hl(0, 'SnacksPickerTitle', { bg = '#7aa2f7', fg = '#1f2335' })
vim.api.nvim_set_hl(0, 'SnacksPickerPreview', { bg = '#1a1b26' })
vim.api.nvim_set_hl(0, 'SnacksPickerList', { bg = '#1a1b26' })
vim.api.nvim_set_hl(0, 'SnacksPickerListTitle', { bg = '#9ece6a', fg = '#1f2335' })
vim.api.nvim_set_hl(0, 'SnacksPickerInputTitle', { bg = '#f7768e', fg = '#1f2335' })
vim.api.nvim_set_hl(0, 'SnacksPickerInputBorder', { bg = '#1a1b26', fg = '#45475a' })
vim.api.nvim_set_hl(0, 'SnacksPickerInputSearch', { bg = '#f7768e', fg = '#1f2335' })
vim.api.nvim_set_hl(0, 'SnacksPickerInput', { bg = '#1a1b26' }) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Cheers, thanks!
Regards,
Ravi
…On Sat, 21 Jun, 2025, 1:31 am Drowning Cat, ***@***.***> wrote:
I've updated the code. You can see the latest edit.
—
Reply to this email directly, view it on GitHub
<#1306 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFZI3STWEQDA2XWXHVYJTL3ERSC3AVCNFSM6AAAAABXN5VUK6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJTGM3TMNA>
.
You are receiving this because you commented.Message ID: <folke/snacks.
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Have you created any neat
dashboardslayouts, you can share a screenshot with the config here.Beta Was this translation helpful? Give feedback.
All reactions