option defaultEditor: Set {env}VISUAL on true (#8322)

The defaultEditor option sets {env}`EDITOR` however strictly speaking
{env}`EDITOR` is intended for editors that are fully compatible with
teletype terminals (ex: `ed` or `vi`'s `ex` mode).

The {env}`VISUAL variable is intended for modern "visual mode"
terminal editors (ex: `vi` or `emacs`).

Technically speaking editors that are assigned to {env}`EDITOR` should
be configured to operate in teletype compatible mode (see `vi -e` and
`vim -e`).

We don't do this currently because for most users this would be
unintuitive behavior when a script or program mistakenly checks
{env}`EDITOR` instead of first checking {env}`VISUAL`.

In the future it may be worthwhile to introduce an additional option to
these modules to configure {env}`EDITOR` in a strictly conforming manner
(i.e. using the teletype/`ex` mode flags or unsetting {env}`EDITOR`
entirely).

Related Issue: #8314

Signed-off-by: Jacob Abel <jacobabel@nullpo.dev>
This commit is contained in:
Jacob Abel 2025-12-11 14:04:13 -05:00 committed by GitHub
parent 9b5ac85d79
commit 0cf525a5be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 14 deletions

View file

@ -162,7 +162,8 @@ in
default = false;
description = ''
Whether to configure {command}`vim` as the default
editor using the {env}`EDITOR` environment variable.
editor using the {env}`EDITOR` and {env}`VISUAL`
environment variables.
'';
};
};
@ -213,7 +214,10 @@ in
home.packages = [ cfg.package ];
home.sessionVariables = lib.mkIf cfg.defaultEditor { EDITOR = "vim"; };
home.sessionVariables = lib.mkIf cfg.defaultEditor {
EDITOR = "vim";
VISUAL = "vim";
};
programs.vim = {
package = vim;