From 0cf525a5be5d4250b2804dc2d104bdcc406052cb Mon Sep 17 00:00:00 2001 From: Jacob Abel Date: Thu, 11 Dec 2025 14:04:13 -0500 Subject: [PATCH] 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 --- modules/programs/helix.nix | 8 ++++++-- modules/programs/kakoune.nix | 8 ++++++-- modules/programs/neovim.nix | 8 ++++++-- modules/programs/vim.nix | 8 ++++++-- modules/services/emacs.nix | 18 ++++++++++++------ 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/modules/programs/helix.nix b/modules/programs/helix.nix index 2e2f78c9..74b029c0 100644 --- a/modules/programs/helix.nix +++ b/modules/programs/helix.nix @@ -49,7 +49,8 @@ in default = false; description = '' Whether to configure {command}`hx` as the default - editor using the {env}`EDITOR` environment variable. + editor using the {env}`EDITOR` and {env}`VISUAL` + environment variables. ''; }; @@ -225,7 +226,10 @@ in else [ cfg.package ]; - home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "hx"; }; + home.sessionVariables = mkIf cfg.defaultEditor { + EDITOR = "hx"; + VISUAL = "hx"; + }; xdg.configFile = let diff --git a/modules/programs/kakoune.nix b/modules/programs/kakoune.nix index becc7519..ca8e8a58 100644 --- a/modules/programs/kakoune.nix +++ b/modules/programs/kakoune.nix @@ -705,7 +705,8 @@ in default = false; description = '' Whether to configure {command}`kak` as the default - editor using the {env}`EDITOR` environment variable. + editor using the {env}`EDITOR` and {env}`VISUAL` + environment variables. ''; }; @@ -755,7 +756,10 @@ in programs.kakoune.finalPackage = lib.mkIf (cfg.package != null) kakouneWithPlugins; home.packages = lib.mkIf (cfg.finalPackage != null) [ cfg.finalPackage ]; - home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "kak"; }; + home.sessionVariables = mkIf cfg.defaultEditor { + EDITOR = "kak"; + VISUAL = "kak"; + }; xdg.configFile = lib.mkMerge [ { "kak/kakrc".source = configFile; } (mkIf (cfg.colorSchemePackage != null) { diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index a234a133..271bc150 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -289,7 +289,8 @@ in default = false; description = '' Whether to configure {command}`nvim` as the default - editor using the {env}`EDITOR` environment variable. + editor using the {env}`EDITOR` and {env}`VISUAL` + environment variables. ''; }; @@ -453,7 +454,10 @@ in home.packages = [ cfg.finalPackage ]; - home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; }; + home.sessionVariables = mkIf cfg.defaultEditor { + EDITOR = "nvim"; + VISUAL = "nvim"; + }; home.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; }; diff --git a/modules/programs/vim.nix b/modules/programs/vim.nix index 6773c878..5f919dfa 100644 --- a/modules/programs/vim.nix +++ b/modules/programs/vim.nix @@ -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; diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index 117c3b72..a7327199 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -113,7 +113,8 @@ in example = !default; description = '' Whether to configure {command}`emacsclient` as the default - editor using the {env}`EDITOR` environment variable. + editor using the {env}`EDITOR` and {env}`VISUAL` + environment variables. ''; }; }; @@ -121,11 +122,16 @@ in config = mkIf cfg.enable ( lib.mkMerge [ { - home.sessionVariables = mkIf cfg.defaultEditor { - EDITOR = lib.getBin ( - pkgs.writeShellScript "editor" ''exec ${lib.getBin cfg.package}/bin/emacsclient "''${@:---create-frame}"'' - ); - }; + home.sessionVariables = + let + editorBin = lib.getBin ( + pkgs.writeShellScript "editor" ''exec ${lib.getBin cfg.package}/bin/emacsclient "''${@:---create-frame}"'' + ); + in + mkIf cfg.defaultEditor { + EDITOR = editorBin; + VISUAL = editorBin; + }; } (mkIf pkgs.stdenv.isLinux {