Changing The Default Editor In Linux


I recently needed to set up some cron jobs for new scripts I had been developing and found an ugly blue screen when editing the cron file with crontab -e (which opens the current user’s cron file in the default editor). I had been expecting vim (Vi Improved) but instead I was faced with "joe", which is not my editor of choice.

Fortunately, though, it is a simple enough task to change which editor is used when editing cron jobs. For anyone else in the same situation as myself, instructions are provided below on how to change the default editor. Note: This changes the editor used by all software which respects the EDITOR variable.

Firstly, open the file .bashrc (or .profile, if you prefer) in a text editor, which is usually located in your home directory. If you do not find it there then you can copy the "global" /etc/bashrc (or /etc/profile) to your home directory (e.g. cp /etc/bashrc ~/.bashrc). Next look for EDITOR in the file - sometimes this is already set, other times it is commented out by a "#", e.g. #EDITOR=/usr/bin/vim - and if it is already set change it as appropriate and/or remove the # if it is commented out. Obviously, if it does not exist add in the line EDITOR=/usr/bin/vim (or whatever the path is to your favourite text-based editor).

If you’re not sure of the path to your favourite editor you can use which vim to find the path to it (replace vim with the name of the editor, i.e. the one that you use to start it from a console).

Once EDITOR is set and the file is saved, you will need to get bash to re-read the .bashrc otherwise the variable will not be active until a new bash session is started or you logout and then log back in. Re-reading of the file can be done using the command source ~/.bashrc (or source ~/.profile). crontab -e will now use your preferred editor.

A final note - although openSUSE 10.2 is my preferred distribution, the above should work like a charm for any version of Linux (probably *BSD and several other UNIX or UNIX-like Operating Systems, too) where bash is used as the shell of choice.

Share and Enjoy:
  • Digg
  • del.icio.us
  • BlinkList
  • Furl
  • Netscape
  • Reddit
  • StumbleUpon
  • YahooMyWeb




Write a comment:

(Required, but won't be displayed)