Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Change default text editor for crontab to vim

Writer Andrew Mclaughlin

I'm using ubuntu 9.10 and the default text editor is nano, which i hate. (doesn't everyone?)

Normally it's not a problem as i just vi or gedit everything but crontab -e is opening with nano. I tried changing it to vim using sudo update-alternatives --config editor and selecting option 3 ("/usr/bin/vim.basic"). This has changed it for sudo and non-sudo alike. But crontab -e still opens nano. Any ideas? max

11 Answers

The crontab -e command will check the environment variables $EDITOR and $VISUAL for an override of the default text editor, so...

export VISUAL=vim

or

export EDITOR=vim

should do the trick.

1

In ubuntu, try run: select-editor, which interactively creates ~/.selected_editor:

# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim.basic"
6

If you hate nano so much you can just uninstall it:

sudo apt-get remove nano

crontab should then just default to the next EDITOR (for me it was vim.basic).

3

From man crontab:

The -e option is used to edit the current crontab using the editor
specified by the VISUAL or EDITOR environment variables. After you
exit from the editor, the modified crontab will be installed automati‐
cally. If neither of the environment variables is defined, then the
default editor /usr/bin/editor is used.

Add to your ~/.bashrc:

export EDITOR=vim
export EDITOR=vi && crontab -e 

works on debian squeeze

2

The better choice is to set alternative of editor (not just one user) :

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim 100
1

Unfortunately I can not comment or vote.

On Ubuntu the configuration file is called ~/.selected_editor

With the following command you can select the default editor again:

$ select-editor

Removing the file in your home directory also works.

$ rm ~/.selected_editor

Only setting the variables $VISUAL or $EDITOR will work but is only persistent if you write it to a script which is executed in your environment.

Add to your rc file

$ echo "export VISUAL=/usr/bin/vi" >> ~/.bashrc

But i wouldn't recommend to use the last solution.

2

You should best remove the ~/.sensible_editor file and then running crontab -e will prompt you to choose the preferred editor.
From then on your preference will be remembered in the ~/.sensible_editor file.

2

Easiest would be to get rid of the product you don't want in its entirety. All other config changes would be automatical.

apt-get install vim -y && apt-get remove nano -y

for Debian, use :

sudo update-alternatives --config editor command

and

 ----------------------------------------------------------
06 * 0 /bin/nano 40
07 1 /bin/nano 40
08 2 /usr/bin/vim.basic 30
09 3 /usr/bin/vim.tiny 10 

select '2' and press enter. Got it!

1

On older machines like some Debian ones, this works also and is the most portable solution.

mv /usr/bin/editor /usr/bin/.editor
ln -s $(which vim) /usr/bin/editor
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy