neovim

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

commit 9910445125bbcf2d51715d5aac97d3f3db58f2de
parent 78f4994627b7d9c3b85f30028fe55ff38024a39d
Author: bfredl <bjorn.linse@gmail.com>
Date:   Fri,  1 Aug 2025 13:00:27 +0200

fix(options): make 'cdhome' take effect on any platform

Platform specific options are cringe and should either be fixed or
deleted.

In this case, the platform difference can trivially be implemented
using a conditional default value. If the user overrides the value,
then it is because the user wants that value, regardless of the
corporation who manufactured the OS that the user is running.

Possible alternative: delete the option by making it always on.

Diffstat:
Mruntime/doc/options.txt | 3+--
Mruntime/lua/vim/_meta/options.lua | 3+--
Msrc/nvim/ex_docmd.c | 6------
Msrc/nvim/options.lua | 8++++++--
4 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt @@ -1244,12 +1244,11 @@ A jump table for the options with a short description can be found at |Q_op|. This probably only matters for Turkish. *'cdhome'* *'cdh'* *'nocdhome'* *'nocdh'* -'cdhome' 'cdh' boolean (default off) +'cdhome' 'cdh' boolean (default on on Unix, off on Windows) global When on, |:cd|, |:tcd| and |:lcd| without an argument changes the current working directory to the |$HOME| directory like in Unix. When off, those commands just print the current directory name. - On Unix this option has no effect. This option cannot be set from a |modeline| or in the |sandbox|, for security reasons. diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua @@ -700,12 +700,11 @@ vim.go.cmp = vim.go.casemap --- When on, `:cd`, `:tcd` and `:lcd` without an argument changes the --- current working directory to the `$HOME` directory like in Unix. --- When off, those commands just print the current directory name. ---- On Unix this option has no effect. --- This option cannot be set from a `modeline` or in the `sandbox`, for --- security reasons. --- --- @type boolean -vim.o.cdhome = false +vim.o.cdhome = true vim.o.cdh = vim.o.cdhome vim.go.cdhome = vim.o.cdhome vim.go.cdh = vim.go.cdhome diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c @@ -6105,11 +6105,7 @@ bool changedir_func(char *new_dir, CdScope scope) // For UNIX ":cd" means: go to home directory. // On other systems too if 'cdhome' is set. -#if defined(UNIX) - if (*new_dir == NUL) { -#else if (*new_dir == NUL && p_cdh) { -#endif // Use NameBuff for home directory name. expand_env("$HOME", NameBuff, MAXPATHL); new_dir = NameBuff; @@ -6148,13 +6144,11 @@ bool changedir_func(char *new_dir, CdScope scope) void ex_cd(exarg_T *eap) { char *new_dir = eap->arg; -#if !defined(UNIX) // for non-UNIX ":cd" means: print current directory unless 'cdhome' is set if (*new_dir == NUL && !p_cdh) { ex_pwd(NULL); return; } -#endif CdScope scope = kCdScopeGlobal; switch (eap->cmdidx) { diff --git a/src/nvim/options.lua b/src/nvim/options.lua @@ -1005,12 +1005,16 @@ local options = { }, { abbreviation = 'cdh', - defaults = false, + defaults = { + condition = 'MSWIN', + if_false = true, + if_true = false, + doc = [[on on Unix, off on Windows]], + }, desc = [=[ When on, |:cd|, |:tcd| and |:lcd| without an argument changes the current working directory to the |$HOME| directory like in Unix. When off, those commands just print the current directory name. - On Unix this option has no effect. This option cannot be set from a |modeline| or in the |sandbox|, for security reasons. ]=],