mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
3.8 KiB
3.8 KiB
🍿 win
Easily create and manage floating windows or splits
🚀 Usage
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,
},
})
⚙️ Config
---@class snacks.win.Config: vim.api.keyset.win_config
---@field style? string merges with config from `Snacks.config.styles[style]`
---@field show? boolean Show the window immediately (default: true)
---@field minimal? boolean Disable a bunch of options to make the window minimal (default: true)
---@field position? "float"|"bottom"|"top"|"left"|"right"
---@field buf? number If set, use this buffer instead of creating a new one
---@field file? string If set, use this file instead of creating a new buffer
---@field enter? boolean Enter the window after opening (default: false)
---@field backdrop? number|false Opacity of the backdrop (default: 60)
---@field wo? vim.wo window options
---@field bo? vim.bo buffer options
---@field ft? string filetype to use for treesitter/syntax highlighting. Won't override existing filetype
---@field keys? table<string, false|string|fun(self: snacks.win)|snacks.win.Keys> Key mappings
---@field on_buf? fun(self: snacks.win) Callback after opening the buffer
---@field on_win? fun(self: snacks.win) Callback after opening the window
{
show = true,
relative = "editor",
position = "float",
minimal = true,
wo = {
winhighlight = "Normal:SnacksNormal,NormalNC:SnacksNormalNC,WinBar:SnacksWinBar,WinBarNC:SnacksWinBarNC",
},
bo = {},
keys = {
q = "close",
},
}
🎨 Styles
float
{
position = "float",
backdrop = 60,
height = 0.9,
width = 0.9,
zindex = 50,
}
minimal
{
wo = {
cursorcolumn = false,
cursorline = false,
cursorlineopt = "both",
fillchars = "eob: ,lastline:…",
list = false,
listchars = "extends:…,tab: ",
number = false,
relativenumber = false,
signcolumn = "no",
spell = false,
winbar = "",
statuscolumn = "",
wrap = false,
sidescrolloff = 0,
},
}
split
{
position = "bottom",
height = 0.4,
width = 0.4,
}
📚 Types
---@class snacks.win.Keys: vim.api.keyset.keymap
---@field [1]? string
---@field [2]? string|fun(self: snacks.win): any
---@field mode? string|string[]
📦 Module
---@class snacks.win
---@field id number
---@field buf? number
---@field win? number
---@field opts snacks.win.Config
---@field augroup? number
---@field backdrop? snacks.win
Snacks.win = {}
Snacks.win()
---@type fun(opts? :snacks.win.Config): snacks.win
Snacks.win()
Snacks.win.new()
---@param opts? snacks.win.Config
---@return snacks.win
Snacks.win.new(opts)
win:add_padding()
win:add_padding()
win:buf_valid()
win:buf_valid()
win:close()
---@param opts? { buf: boolean }
win:close(opts)
win:focus()
win:focus()
win:hide()
win:hide()
win:is_floating()
win:is_floating()
win:lines()
---@param from? number
---@param to? number
win:lines(from, to)
win:parent_size()
win:parent_size()
win:show()
win:show()
win:size()
---@return { height: number, width: number }
win:size()
win:text()
---@param from? number
---@param to? number
win:text(from, to)
win:toggle()
win:toggle()
win:update()
win:update()
win:valid()
win:valid()
win:win_valid()
win:win_valid()