aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/ui.lua
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2022-01-30 13:32:55 +0100
committerGitHub <noreply@github.com>2022-01-30 13:32:55 +0100
commitabde91ecaf338da4a0b88e383583624b5cab7b30 (patch)
tree3dc2aafed33cb7c907c93414739743a2aa6d3c20 /runtime/lua/vim/ui.lua
parent9aaf7a2b4dfe9d3f9a1861e7ca85b6bbd4e34e05 (diff)
downloadrneovim-abde91ecaf338da4a0b88e383583624b5cab7b30.tar.gz
rneovim-abde91ecaf338da4a0b88e383583624b5cab7b30.tar.bz2
rneovim-abde91ecaf338da4a0b88e383583624b5cab7b30.zip
docs: add example to vim.ui.select (#17241)
Closes https://github.com/neovim/neovim/issues/17137
Diffstat (limited to 'runtime/lua/vim/ui.lua')
-rw-r--r--runtime/lua/vim/ui.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua
index 9568b60fd0..0f2de6ce5c 100644
--- a/runtime/lua/vim/ui.lua
+++ b/runtime/lua/vim/ui.lua
@@ -18,6 +18,24 @@ local M = {}
--- Called once the user made a choice.
--- `idx` is the 1-based index of `item` within `item`.
--- `nil` if the user aborted the dialog.
+---
+---
+--- Example:
+--- <pre>
+--- vim.ui.select({ 'tabs', 'spaces' }, {
+--- prompt = 'Select tabs or spaces:',
+--- format_item = function(item)
+--- return "I'd like to choose " .. item
+--- end,
+--- }, function(choice)
+--- if choice == 'spaces' then
+--- vim.o.expandtab = true
+--- else
+--- vim.o.expandtab = false
+--- end
+--- end)
+--- </pre>
+
function M.select(items, opts, on_choice)
vim.validate {
items = { items, 'table', false },
@@ -57,6 +75,13 @@ end
--- Called once the user confirms or abort the input.
--- `input` is what the user typed.
--- `nil` if the user aborted the dialog.
+---
+--- Example:
+--- <pre>
+--- vim.ui.input({ prompt = 'Select value for shiftwidth: ' }, function(input)
+--- vim.o.shiftwidth = tonumber(input)
+--- end)
+--- </pre>
function M.input(opts, on_confirm)
vim.validate {
on_confirm = { on_confirm, 'function', false },