How to change the default text editor on Linux

On Linux, a default editor is used for text editing such as crontab -e or git commit. How to change it to the editor of my own choice?

The default editor is indicated by the EDITOR environment variable. You can set this environment variable to set the default editor. For example, set it to emacs by EDITOR=emacs.

If you want to set it for all users, add this line to /etc/bashrc or /etc/profile:

export EDITOR=emacs

If you want to set it for yourself only, add this line to ~/.bashrc or ~/.profile:

export EDITOR=emacs

If you want to set it for one shell instance only, run this:

export EDITOR=emacs

If you want to set it for just one instance of a program, say crontabe -e, run this:

EDITOR=emacs crontab -e
Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *