`edit` doesn't obey EDITOR set it variable from `/etc/environment`

My /etc/environment file contains the following lines:

EDITOR=micro
SUDO_EDITOR=micro
VISUAL=micro

However, running edit tmp opens a temporary file in the vi editor instead of micro, even after a reboot, and regardless of which shell I use (fish or bash). How do I fix this?


The micro editor is installed and on the path:

~> whereis micro
micro: /usr/bin/micro /usr/share/man/man1/micro.1.gz

The output of printenv looks correct:

~> printenv | grep micro
SUDO_EDITOR=micro
VISUAL=micro
EDITOR=micro

And the problem happens even if I inline the environment variable:

~> env EDITOR=micro edit tmp

still opens in vi.

First, welcome to the forum!

Second. edit is a program that is part of vi. Since you are explicitly running the program edit, it will always open in edit

1 Like

Aha, that’s confusing, I always assumed edit was just the non-sudo equivalent of sudoedit. Thank you. Is there a generic edit command that will always use my chosen EDITOR? Should I just use the ef function defined in the default .bashrc for this?

1 Like

To be honest, I am a bit confused as to why you would need that. The purpose of those variables is so that programs that use an editor know which editor you prefer.

If you just want to open a file directly, why not just call the editor directly? Presumably you know what your preferred editor is.

That being said, you could easily create a function in your bashrc or a shell script that would do that.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.