Sunday, March 25, 2012

Change the Default Editor

In some linux distros, the default editor is automatically called when a script you're running decides you need to modify some script it is about to call. The default editor tends to be vi or vim. Which is an exceptionally powerful text editor, but if you don't use frequently it is very easy to completely forget how to do some very basic things, like actually edit the script in question or just plain exit the editor. A different command line editor by the name nano is much easier to use for the infrequent user. To correct this problem, you can easily make a minor modification to one file to use nano instead.

At the command line, enter

nano .bashrc

Make sure you're in your in home directory when you do this by typing:

cd ~

Once the editor is up, look for instances of vim and replace them with nano. The locations will say things like:

export EDITOR=vim

When you're done, do a ctrl-x to exit, say yes to save the updated file, and enter to confirm the save. Then log out of your terminal session and back in. To check that it is working you can type the following to see what comes back.

echo $EDITOR

If it is vim, then you didn't do something right, so you'll need to try again.

If you can't log out of the terminal session for some reason, you can apply the changes immediately. You can either dynamically set the $EDITOR or you can apply your bash resource file. To apply your bash resource file without closing your terminal session, type the following line.

source ~/.bashrc

Now, you're all done. Enjoy your new default editor.

No comments: