Search code examples
vimeditorhomebrewfish

Fail to set Homebrew formula editor to vim in fish shell


I have a problem with Homebrew editor: Atom is used instead of Vim

$ brew edit a_brew_formula
Editing /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/a_brew_formula.rb
Warning: Using atom because no editor was set in the environment.
This may change in the future, so we recommend setting EDITOR,
or HOMEBREW_EDITOR to your preferred text editor.

EDITOR and HOMEBREW_EDITOR are well set in config.fish:

set EDITOR vim
set HOMEBREW_EDITOR vim

I checked in the shell:

$ echo $EDITOR
vim

Why my editor choice is not taken into account?


Solution

  • You haven't exported the variable, so external processes (like homebrew) don't see it.

    Use set -x, but preferably set -gx to also define global scope on the variable.

    E.g.

    set -gx EDITOR vim
    

    To see what an external process sees, you can use env. If called without arguments, it will print its environment as VAR=VALUE lines.

    If that doesn't show EDITOR=, you know that you've not exported your $EDITOR.