pointing at the second byte of a character
vim.str_utf_start('æ', 2)
<
Parameters: ~
• {str} (`string`)
• {index} (`integer`)
Return: ~
(`integer`)
vim.stricmp({a}, {b}) *vim.stricmp()*
Compares strings case-insensitively.
Parameters: ~
• {a} (`string`)
• {b} (`string`)
Return: ~
(`0|1|-1`) if strings are equal, {a} is greater than {b} or {a} is
lesser than {b}, respectively.
vim.ui_attach({ns}, {opts}, {callback}) *vim.ui_attach()*
WARNING: This feature is experimental/unstable.
Subscribe to |ui-events|, similar to |nvim_ui_attach()| but receive events
in a Lua callback. Used to implement screen elements like popupmenu or
message handling in Lua.
{callback} receives event name plus additional parameters. See
|ui-popupmenu| and the sections below for event format for respective
events.
Callbacks for `msg_show` events are executed in |api-fast| context;
showing the message should be scheduled.
Excessive errors inside the callback will result in forced detachment.
WARNING: This api is considered experimental. Usability will vary for
different screen elements. In particular `ext_messages` behavior is
subject to further changes and usability improvements. This is expected to
be used to handle messages when setting 'cmdheight' to zero (which is
likewise experimental).
Example (stub for a |ui-popupmenu| implementation): >lua
ns = vim.api.nvim_create_namespace('my_fancy_pum')
vim.ui_attach(ns, {ext_popupmenu=true}, function(event, ...)
if event == 'popupmenu_show' then
local items, selected, row, col, grid = ...
print('display pum ', #items)
elseif event == 'popupmenu_select' then
local selected = ...
print('selected', selected)
elseif event == 'popupmenu_hide' then
print('FIN')
end
end)
<
Parameters: ~
• {ns} (`integer`) Namespace ID
• {opts} (`table<string, any>`) Optional parameters.
• {ext_…}? (`boolean`) Any of |ui-ext-options|, if true
enable events for the respective UI element.
• {set_cmdheight}? (`boolean`) If false, avoid setting
'cmdheight' to 0 when `ext_messages` is enabled.
• {callback} (`fun(event: string, ...)`) Function called for each UI
event
vim.ui_detach({ns}) *vim.ui_detach()*
Detach a callback previously attached with |vim.ui_attach()| for the given
namespace {ns}.
Parameters: ~
• {ns} (`integer`) Namespace ID
vim.wait({time}, {callback}, {interval}, {fast_only}) *vim.wait()*
Wait for {time} in milliseconds until {callback} returns `true`.
Executes {callback} immediately and at approximately {interval}
milliseconds (default 200). Nvim still processes other events during this
time.
Cannot be called while in an |api-fast| event.
Examples: >lua
---
-- Wait for 100 ms, allowing other events to process
vim.wait(100, function() end)
---
-- Wait for 100 ms or until global variable set.
vim.wait(100, function() return vim.g.waiting_for_var end)
---
-- Wait for 1 second or until global variable set, checking every ~500 ms
vim.wait(1000, function() return vim.g.waiting_for_var end, 500)
---
-- Schedule a function to set a value in 100ms
vim.defer_fn(function() vim.g.timer_result = true end, 100)
-- Would wait ten seconds if results blocked. Actually only waits 100 ms
if vim.wait(10000, function() return vim.g.timer_result end) then
print('Only waiting a little bit of time!')
end
<
Parameters: ~
• {time}