Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 78 down vote accepted

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

export VISUAL=vim


export EDITOR=vim

should do the trick.

share|improve this answer
Remember if you are editing another users's crontab, use sudo -E crontab -e where sudo -E specifies use your env vars. – MarkHu Jan 28 at 19:15

In ubuntu, try run: select-editor

share|improve this answer
Above answers didn't work...this does. – mlissner Jan 25 '13 at 19:59
This was gold! thanks. – saintali May 16 '13 at 8:50
Yup, this changes ~/.sensible_editor used by /usr/bin/sensible-editor. It seems that in the absence of the environment variables specifying the editor, crontab runs sensible-editor not editor as the former allows per-user configuration. – eel ghEEz Feb 25 '15 at 5:25
@MaxWilliams, running select-editor will not show the previously made selection, which is stored in ~/.sensible_editor. – eel ghEEz Feb 25 '15 at 5:27
Thanks @WilsonF, I just verified what you said. – eel ghEEz Jun 13 at 23:12

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
share|improve this answer

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

sudo apt-get remove nano

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

share|improve this answer
We run our cron jobs with super-user account, but login to a dev account. So from dev account I need to do sudo crontab -e. I set export EDITOR=vim in both super-user's and the dev account's .bashrc, but sudo crontab -e was still opening up in nano. After uninstalling nano, it opens vim. Thanks! – arun Jul 27 '13 at 17:06
This is the only solution that worked for me. Tried 4-5 things before this :) – Charlie Wynn Nov 24 '15 at 1:54
export EDITOR=vi && crontab -e 

works on debian squeeze

share|improve this answer
A little explanation would go a long way. – ChrisF Oct 1 '12 at 21:15
this sets the EDITOR environment variable and subsequently edits the crontab file, EDITOR=vim crontab -e will work as well, but only one time. – 0x4a6f4672 Nov 21 '12 at 16:56

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
share|improve this answer

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.

share|improve this answer
not sure why this was down voted it is exactly what I need and worked perfectly. – rob Oct 28 '15 at 13:28

for Debian, use :

sudo update-alternatives --config editor command


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!

share|improve this answer
Welcome to Super User! Please read the question again carefully. Your answer does not answer the original question. The OP already tried this (it's in the question) and it did not fix his problem. – DavidPostill Dec 19 '15 at 18:03

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.

share|improve this answer
If you don't recommend it why did you provide it? – Ramhound Jan 5 at 11:52
Just for completion and because other people may prefer that way. – André Jan 6 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .