neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 049de6f11925131364d2820ed53327b1c32af012
parent 848c7a7894709a5bf73cd09d5612c35426994c0e
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Thu, 21 Aug 2025 08:32:46 +0800

vim-patch:partial:308a313: runtime(doc): Update help for the items() function

closes: vim/vim#18021

https://github.com/vim/vim/commit/308a3130be89148cdaf83bfaf00e3e7c69ed2133

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>

Diffstat:
Mruntime/doc/vimfn.txt | 24++++++++++++++----------
Mruntime/lua/vim/_meta/vimfn.lua | 24++++++++++++++----------
Msrc/nvim/eval.lua | 24++++++++++++++----------
3 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/runtime/doc/vimfn.txt b/runtime/doc/vimfn.txt @@ -5424,22 +5424,26 @@ isnan({expr}) *isnan()* Return: ~ (`0|1`) -items({dict}) *items()* - Return a |List| with all the key-value pairs of {dict}. Each - |List| item is a list with two items: the key of a {dict} - entry and the value of this entry. The |List| is in arbitrary - order. Also see |keys()| and |values()|. +items({expr}) *items()* + Return a |List| with all the key/index and value pairs of {expr}. + Each |List| item is a list with two items: + - for a |Dict|: the key and the value + - for a |List| or |String|: the index and the value + The |List| is in arbitrary order. + + Also see |keys()| and |values()|. + Example: >vim + let mydict = #{a: 'red', b: 'blue'} for [key, value] in items(mydict) - echo key .. ': ' .. value + echo $"{key} = {value}" endfor + echo items([1, 2, 3]) + echo items("foobar") < - A List or a String argument is also supported. In these - cases, items() returns a List with the index and the value at - the index. Parameters: ~ - • {dict} (`table`) + • {expr} (`table|string`) Return: ~ (`any`) diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua @@ -4908,22 +4908,26 @@ function vim.fn.islocked(expr) end --- @return 0|1 function vim.fn.isnan(expr) end ---- Return a |List| with all the key-value pairs of {dict}. Each ---- |List| item is a list with two items: the key of a {dict} ---- entry and the value of this entry. The |List| is in arbitrary ---- order. Also see |keys()| and |values()|. +--- Return a |List| with all the key/index and value pairs of {expr}. +--- Each |List| item is a list with two items: +--- - for a |Dict|: the key and the value +--- - for a |List| or |String|: the index and the value +--- The |List| is in arbitrary order. +--- +--- Also see |keys()| and |values()|. +--- --- Example: >vim +--- let mydict = #{a: 'red', b: 'blue'} --- for [key, value] in items(mydict) ---- echo key .. ': ' .. value +--- echo $"{key} = {value}" --- endfor +--- echo items([1, 2, 3]) +--- echo items("foobar") --- < ---- A List or a String argument is also supported. In these ---- cases, items() returns a List with the index and the value at ---- the index. --- ---- @param dict table +--- @param expr table|string --- @return any -function vim.fn.items(dict) end +function vim.fn.items(expr) end --- @deprecated --- Obsolete name for |chanclose()| diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua @@ -6057,22 +6057,26 @@ M.funcs = { args = 1, base = 1, desc = [=[ - Return a |List| with all the key-value pairs of {dict}. Each - |List| item is a list with two items: the key of a {dict} - entry and the value of this entry. The |List| is in arbitrary - order. Also see |keys()| and |values()|. + Return a |List| with all the key/index and value pairs of {expr}. + Each |List| item is a list with two items: + - for a |Dict|: the key and the value + - for a |List| or |String|: the index and the value + The |List| is in arbitrary order. + + Also see |keys()| and |values()|. + Example: >vim + let mydict = #{a: 'red', b: 'blue'} for [key, value] in items(mydict) - echo key .. ': ' .. value + echo $"{key} = {value}" endfor + echo items([1, 2, 3]) + echo items("foobar") < - A List or a String argument is also supported. In these - cases, items() returns a List with the index and the value at - the index. ]=], name = 'items', - params = { { 'dict', 'table' } }, - signature = 'items({dict})', + params = { { 'expr', 'table|string' } }, + signature = 'items({expr})', }, jobclose = { args = { 1, 2 },