From 6346c61b0c2b3c014b2f0f49dfb6ec5fe3e0c06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Sun, 3 Mar 2024 14:06:58 -0600 Subject: [PATCH] vim,neovim: set EDITOR to full binary path when `defaultEditor` is used Prior to this change the `EDITOR` variable was set only to the name of the program that should be looked up in `PATH` to use as the editor, but this will only work for user-level stuff, for stuff like `sudo -e` it won't work as the `PATH` will not contain the location of such programs. This makes it so that when the `defaultEditor` variable is set to `true` then `EDITOR` will point to the full binary location of the `vim` and `nvim` packages accordingly. This is similar to how we set `defaultEditor` in the Emacs module. This change is also made for `vim`. --- modules/programs/neovim.nix | 5 ++++- modules/programs/vim.nix | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index a3b87ea24..142d56d7c 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -390,7 +390,10 @@ in { home.packages = [ cfg.finalPackage ]; - home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; }; + home.sessionVariables = mkIf cfg.defaultEditor { + EDITOR = getBin + (pkgs.writeShellScript "editor" "exec ${getBin cfg.package}/bin/nvim"); + }; xdg.configFile = let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs; diff --git a/modules/programs/vim.nix b/modules/programs/vim.nix index 2f13caeee..138e24151 100644 --- a/modules/programs/vim.nix +++ b/modules/programs/vim.nix @@ -174,7 +174,10 @@ in { home.packages = [ cfg.package ]; - home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "vim"; }; + home.sessionVariables = mkIf cfg.defaultEditor { + EDITOR = getBin + (pkgs.writeShellScript "editor" "exec ${getBin cfg.package}/bin/vim"); + }; programs.vim = { package = vim;