Your Default Editor
Various shell commands will run an editor when necessary, and by default the editor is
vim. For example, a text-based email program may invoke an editor to compose a new message,
and less
invokes an editor if you type “v”. But what if
you don’t want vim to be your default editor? Set the environment variables VISUAL
and EDITOR
to your
choice, for example:
➜EDITOR=emacs
➜VISUAL=emacs
➜export EDITOR VISUAL
Optional
Both variables are necessary because different programs check one
variable or the other. Set EDITOR
and
VISUAL
in your $HOME/.bash_profile startup file, then close
and reopen your Terminal window, if you want your choices made
permanent.
Regardless of how you set these variables, all system administrators should know at least basic vim and Emacs commands in case a system tool suddenly runs an editor on a critical file.
Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.