115

I am trying to change the default editor from nano to vim.

I have run the following commands:

sudo update-alternatives --config editor

and

update-alternatives --config editor

Both now output:

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

I have restarted my ssh session and restarted sshd but crontab -e still opens in nano

What else do I need to do?

106

Try your ssh session followed by

export EDITOR=vim

or possibly

export EDITOR=/usr/bin/vim.basic

The format of setting of the EDITOR variable depends on which shell you are using.

In Ubuntu you can set the EDITOR environment variable on logon by adding the above to the ~/.profile

Your SSH session will read a similar file (if it exists) on the remote host called ~/.ssh/environment. This has to be specifically defined by the ssh daemon config. See man sshd_config and look for PermitUserEnvironment for more details.

  • 1
    This works in CentOS too – machineaddict May 11 '16 at 11:35
  • Any reason you wouldn't want to use .bashrc here? seems to work for me, or is .profile better? – Nate Mar 27 '17 at 23:08
  • 1
    The select-editor answer below is a better answer – mcarans May 23 '18 at 12:02
183

Just simply run select-editor, this will let you choose any editor you want.

  • 8
    Better answer I think than what was picked. Don't have to change my bash profile to set the editor. Verified by logging out and logging back in. – Paul Carlton Mar 8 '16 at 16:15
  • 3
    Should be the accepted answer. Thanks Mostafa! – DylanYoung Jul 20 '16 at 14:55
  • 2
    Definitely should've been the accepted answer! This helped a lot! :D – Fadi Apr 26 '17 at 15:10
  • 2
    This was the only answer that worked for me – cjohansson Sep 1 '17 at 4:00
  • 2
    Best answer. ... – We are Borg Sep 13 '17 at 7:43
24

My personal preference...

cd /bin
mv nano nano_must_die
ln -s /usr/bin/vim nano
  • I love it, worked out well enough for me after update-alternatives didnt work. – Cole Busby Jan 28 '14 at 19:13
  • 4
    I wouldn't know what's wrong with nano for admins who don't see value in learning vi commands just to tweak some config files. – Max Apr 27 '17 at 9:04
  • I guess do whatever you like on your own personal machine. But on a machine shared with anyone else, this suggestion essentially disables nano for all users in a way that when a user specifically requests nano, they get vim instead. What's the point of that? If they wanted vim, they would ask for it. If the issue here is that the system is configured to automatically invoke nano in some circumstance where you personally prefer vim, then change the configuration. – gwideman Sep 5 '18 at 0:30
13

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.

Perhaps you have the EDITOR enivronment variable set to nano?

11

If you only want to choose the editor temporarily, you can do the following

EDITOR=nano crontab -e

This sets the EDITOR environment variable for the command

10

On my Ubuntu 12.04 computer, crontab uses the ~/.selected_editor file, which contains the path of the selected editor. Edit it:

nano ~/.selected_editor

I have edited it directly or used select-editor, which is a script to do the same thing. Edit the following line:

SELECTED_EDITOR="/usr/bin/vim.basic" 

IHMO people should not be changing anything in /etc or /bin to do this. It is a user level thing, not a system wide task.

  • for gedit: SELECTED_EDITOR="/usr/bin/gedit" – xinthose Sep 20 '16 at 19:37
2

I was having difficulties with select-editor and update-alternatives, my solution was to simply edit the link:

  1. sudo rm /etc/alternatives/editor
  2. sudo ln -s /usr/bin/vim /etc/alternatives/editor

editor now opens Vim

2

I've had the same problem - crontab -e relies on select-editor, visudo relies on the config of "alternatives"

My solution:

run both commands as root

# update-alternatives --install /usr/bin/editor editor /usr/bin/sensible-editor 50

# select-editor 

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/sensible-editor
  3. /usr/bin/vim.basic
  4. /usr/bin/vim.tiny

Choose 1-4 [1]: 3

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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