From 43b666cb272e3df8ffc724dc3d876f27b91e4118 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Jul 2026 09:00:51 +0800 Subject: [PATCH] vim-patch:770eb7d: runtime(doc): clarify expandcmd() and "~" behaviour fixes: vim/vim#20793 https://github.com/vim/vim/commit/770eb7db17c44e41fc4eb1975d67f9ec022edb58 Co-authored-by: Hirohito Higashi --- runtime/doc/vimfn.txt | 4 ++++ runtime/lua/vim/_meta/vimfn.gen.lua | 4 ++++ src/nvim/eval.lua | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/runtime/doc/vimfn.txt b/runtime/doc/vimfn.txt index 7eccc6011d..cc5e21c08c 100644 --- a/runtime/doc/vimfn.txt +++ b/runtime/doc/vimfn.txt @@ -2269,6 +2269,10 @@ expandcmd({string} [, {options}]) *expandcmd()* like with |expand()|, and environment variables, anywhere in {string}. "~user" and "~/path" are only expanded at the start. + The expansion is done in two steps: the special keywords are + evaluated first, then "~" and environment variables are + expanded in the result. Thus `expand('%:~')` keeps the "~", + while `expandcmd('%:~')` returns the full path. The following items are supported in the {options} Dict argument: diff --git a/runtime/lua/vim/_meta/vimfn.gen.lua b/runtime/lua/vim/_meta/vimfn.gen.lua index 3d9b12bbda..5bc52d2219 100644 --- a/runtime/lua/vim/_meta/vimfn.gen.lua +++ b/runtime/lua/vim/_meta/vimfn.gen.lua @@ -1993,6 +1993,10 @@ function vim.fn.expand(string, nosuf, list) end --- like with |expand()|, and environment variables, anywhere in --- {string}. "~user" and "~/path" are only expanded at the --- start. +--- The expansion is done in two steps: the special keywords are +--- evaluated first, then "~" and environment variables are +--- expanded in the result. Thus `expand('%:~')` keeps the "~", +--- while `expandcmd('%:~')` returns the full path. --- --- The following items are supported in the {options} Dict --- argument: diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 7323fef2a6..f95dc53190 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -2518,6 +2518,10 @@ M.funcs = { like with |expand()|, and environment variables, anywhere in {string}. "~user" and "~/path" are only expanded at the start. + The expansion is done in two steps: the special keywords are + evaluated first, then "~" and environment variables are + expanded in the result. Thus `expand('%:~')` keeps the "~", + while `expandcmd('%:~')` returns the full path. The following items are supported in the {options} Dict argument: