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 11


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.

  • 9
    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 '16 at 19:15

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

# Generated by /usr/bin/select-editor
  • 4
    Above answers didn't work...this does. – mlissner Jan 25 '13 at 19:59
  • 2
    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
  • 2
    @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
  • 5
    @eelghEEz - Do you mean ~/.selected_editor? That's what's on my system and what I've seen elsewhere. – Wilson F Jun 13 '16 at 18:03
  • 1
    works for debian too – JSBach Sep 3 '17 at 17:46

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).

  • 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
  • 1
    This is the only solution that worked for me. Tried 4-5 things before this :) – Charlie Wynn Nov 24 '15 at 1:54
  • This is by far the best solution if, as the OP implies, you never need nano. Not sure why it didn't occur to me before - probably that I didn't realise crontab would just default to the next available editor! Awesome – Luke Mar 20 '17 at 16:08

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
    A little explanation would go a long way. – ChrisF Oct 1 '12 at 21:15
  • 3
    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
  • 3
    Why is it better to change the setting for other users, who did not asked for the change? – ceving Apr 25 '17 at 15:37

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.

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

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.

  • not sure why this was down voted it is exactly what I need and worked perfectly. – rob Oct 28 '15 at 13:28
  • Ubuntu does not seem to know emacsclient. – ceving Apr 25 '17 at 15:35

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!

  • 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

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


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
  • No, don't mess with anything in /usr/bin manually; these locations are managed by dpkg and should not be manipulated directly. – tripleee Apr 12 '18 at 11:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.