commit cf48741227a9aa77533d5adfd2379e7c16c71363
parent e42050f4aed5ee332cc95bacd622bfbc9a31dbe0
Author: Robert <robertosheagamedev@gmail.com>
Date: Tue, 21 Oct 2025 18:40:02 +0100
docs(vimfn): getcwd() behavior #36222
Diffstat:
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/runtime/doc/vimfn.txt b/runtime/doc/vimfn.txt
@@ -3594,16 +3594,19 @@ getcwd([{winnr} [, {tabnr}]]) *getcwd()*
With no arguments, returns the name of the effective
|current-directory|. With {winnr} or {tabnr} the working
directory of that scope is returned, and 'autochdir' is
- ignored.
- Tabs and windows are identified by their respective numbers,
- 0 means current tab or window. Missing tab number implies 0.
- Thus the following are equivalent: >vim
+ ignored. Tabs and windows are identified by their respective
+ numbers, 0 means current tab or window. Missing tab number
+ implies 0. Thus the following are equivalent: >vim
getcwd(0)
getcwd(0, 0)
< If {winnr} is -1 it is ignored, only the tab is resolved.
{winnr} can be the window number or the |window-ID|.
If both {winnr} and {tabnr} are -1 the global working
directory is returned.
+ Note: When {tabnr} is -1 Vim returns an empty string to
+ signal that it is invalid, whereas Nvim returns either the
+ global working directory if {winnr} is -1 or the working
+ directory of the window indicated by {winnr}.
Throw error if the arguments are invalid. |E5000| |E5001| |E5002|
Parameters: ~
diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
@@ -3226,16 +3226,19 @@ function vim.fn.getcursorcharpos(winid) end
--- With no arguments, returns the name of the effective
--- |current-directory|. With {winnr} or {tabnr} the working
--- directory of that scope is returned, and 'autochdir' is
---- ignored.
---- Tabs and windows are identified by their respective numbers,
---- 0 means current tab or window. Missing tab number implies 0.
---- Thus the following are equivalent: >vim
+--- ignored. Tabs and windows are identified by their respective
+--- numbers, 0 means current tab or window. Missing tab number
+--- implies 0. Thus the following are equivalent: >vim
--- getcwd(0)
--- getcwd(0, 0)
--- <If {winnr} is -1 it is ignored, only the tab is resolved.
--- {winnr} can be the window number or the |window-ID|.
--- If both {winnr} and {tabnr} are -1 the global working
--- directory is returned.
+--- Note: When {tabnr} is -1 Vim returns an empty string to
+--- signal that it is invalid, whereas Nvim returns either the
+--- global working directory if {winnr} is -1 or the working
+--- directory of the window indicated by {winnr}.
--- Throw error if the arguments are invalid. |E5000| |E5001| |E5002|
---
--- @param winnr? integer
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
@@ -4032,16 +4032,19 @@ M.funcs = {
With no arguments, returns the name of the effective
|current-directory|. With {winnr} or {tabnr} the working
directory of that scope is returned, and 'autochdir' is
- ignored.
- Tabs and windows are identified by their respective numbers,
- 0 means current tab or window. Missing tab number implies 0.
- Thus the following are equivalent: >vim
+ ignored. Tabs and windows are identified by their respective
+ numbers, 0 means current tab or window. Missing tab number
+ implies 0. Thus the following are equivalent: >vim
getcwd(0)
getcwd(0, 0)
<If {winnr} is -1 it is ignored, only the tab is resolved.
{winnr} can be the window number or the |window-ID|.
If both {winnr} and {tabnr} are -1 the global working
directory is returned.
+ Note: When {tabnr} is -1 Vim returns an empty string to
+ signal that it is invalid, whereas Nvim returns either the
+ global working directory if {winnr} is -1 or the working
+ directory of the window indicated by {winnr}.
Throw error if the arguments are invalid. |E5000| |E5001| |E5002|
]=],