Default Text Editor – Command for Default In-Terminal Text Editor

defaultseditors

I often see instructions that include vim or nano, meaning to open the file in that step in your text editor of choice. Is there an agnostic command I can use in place of the specific program that would open the input in the user's default in-terminal text editor, whether it's vim, nano, or something else?

I see editor mentioned in the Similar Questions sidebar—is that still limited to Debian-based distros? And is there any alternative?

Best Answer

You can use $EDITOR, provided that it's been defined:

$EDITOR filename.txt

But I think most docs use nano because if someone's blindly following along, it's a safe bet to use. If the user has decided they actually prefer one editor over another, they'll know enough to replace it with vim, emacs, etc themselves.

edit may work well on Debian-based systems, but on others it invokes ex, which isn't recommended.

Related Question