mirror of
https://github.com/folke/snacks.nvim
synced 2025-07-07 21:25:11 +00:00
132 lines
2.7 KiB
Markdown
132 lines
2.7 KiB
Markdown
# 🍿 input
|
|
|
|
Better `vim.ui.input`.
|
|
|
|

|
|
|
|
<!-- docgen -->
|
|
|
|
## 📦 Setup
|
|
|
|
```lua
|
|
-- lazy.nvim
|
|
{
|
|
"folke/snacks.nvim",
|
|
---@type snacks.Config
|
|
opts = {
|
|
input = {
|
|
-- your input configuration comes here
|
|
-- or leave it empty to use the default settings
|
|
-- refer to the configuration section below
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## ⚙️ Config
|
|
|
|
```lua
|
|
---@class snacks.input.Config
|
|
---@field enabled? boolean
|
|
---@field win? snacks.win.Config|{}
|
|
---@field icon? string
|
|
---@field icon_pos? snacks.input.Pos
|
|
---@field prompt_pos? snacks.input.Pos
|
|
{
|
|
icon = " ",
|
|
icon_hl = "SnacksInputIcon",
|
|
icon_pos = "left",
|
|
prompt_pos = "title",
|
|
win = { style = "input" },
|
|
expand = true,
|
|
}
|
|
```
|
|
|
|
## 🎨 Styles
|
|
|
|
Check the [styles](https://github.com/folke/snacks.nvim/blob/main/docs/styles.md)
|
|
docs for more information on how to customize these styles
|
|
|
|
### `input`
|
|
|
|
```lua
|
|
{
|
|
backdrop = false,
|
|
position = "float",
|
|
border = "rounded",
|
|
title_pos = "center",
|
|
height = 1,
|
|
width = 60,
|
|
relative = "editor",
|
|
noautocmd = true,
|
|
row = 2,
|
|
-- relative = "cursor",
|
|
-- row = -3,
|
|
-- col = 0,
|
|
wo = {
|
|
winhighlight = "NormalFloat:SnacksInputNormal,FloatBorder:SnacksInputBorder,FloatTitle:SnacksInputTitle",
|
|
cursorline = false,
|
|
},
|
|
bo = {
|
|
filetype = "snacks_input",
|
|
buftype = "prompt",
|
|
},
|
|
--- buffer local variables
|
|
b = {
|
|
completion = false, -- disable blink completions in input
|
|
},
|
|
keys = {
|
|
n_esc = { "<esc>", { "cmp_close", "cancel" }, mode = "n", expr = true },
|
|
i_esc = { "<esc>", { "cmp_close", "stopinsert" }, mode = "i", expr = true },
|
|
i_cr = { "<cr>", { "cmp_accept", "confirm" }, mode = { "i", "n" }, expr = true },
|
|
i_tab = { "<tab>", { "cmp_select_next", "cmp" }, mode = "i", expr = true },
|
|
i_ctrl_w = { "<c-w>", "<c-s-w>", mode = "i", expr = true },
|
|
i_up = { "<up>", { "hist_up" }, mode = { "i", "n" } },
|
|
i_down = { "<down>", { "hist_down" }, mode = { "i", "n" } },
|
|
q = "cancel",
|
|
},
|
|
}
|
|
```
|
|
|
|
## 📚 Types
|
|
|
|
```lua
|
|
---@alias snacks.input.Pos "left"|"title"|false
|
|
```
|
|
|
|
```lua
|
|
---@class snacks.input.Opts: snacks.input.Config,{}
|
|
---@field prompt? string
|
|
---@field default? string
|
|
---@field completion? string
|
|
---@field highlight? fun()
|
|
```
|
|
|
|
## 📦 Module
|
|
|
|
### `Snacks.input()`
|
|
|
|
```lua
|
|
---@type fun(opts: snacks.input.Opts, on_confirm: fun(value?: string)): snacks.win
|
|
Snacks.input()
|
|
```
|
|
|
|
### `Snacks.input.disable()`
|
|
|
|
```lua
|
|
Snacks.input.disable()
|
|
```
|
|
|
|
### `Snacks.input.enable()`
|
|
|
|
```lua
|
|
Snacks.input.enable()
|
|
```
|
|
|
|
### `Snacks.input.input()`
|
|
|
|
```lua
|
|
---@param opts? snacks.input.Opts
|
|
---@param on_confirm fun(value?: string)
|
|
Snacks.input.input(opts, on_confirm)
|
|
```
|