7

man crontab reads:

 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  auto‐
       matically.   If neither of the environment variables is defined, then the default editor /usr/bin/edi‐
       tor is used.

I see that

echo $VISUAL $EDITOR $SENSIBLE_EDITOR $SELECTED_EDITOR

gives an empty line, so I thought it must be /usr/bin/editor that crontab will determine the path to the editor binary from.

$ file /usr/bin/editor
/usr/bin/editor: symbolic link to /etc/alternatives/editor

$ file /etc/alternatives/editor
/etc/alternatives/editor: symbolic link to /bin/nano

$ file /bin/nano
/bin/nano: ELF 64-bit LSB shared object (...)

So I thought crontab would use nano. However, when I do crontab -e, there is Vim run. Why?

My environment

crontab:

$ apt show "$(dpkg -S "$(which crontab)" | cut -d: -f1)"
Package: cron
Version: 3.0pl1-136ubuntu1
(...)

sensible-editor:

$ apt show "$(dpkg -S "$(which sensible-editor)" | cut -d: -f1)"
Package: sensible-utils
Version: 0.0.12+nmu1
(...)

PS.: sensible-editor runs Vim, and:

$ cat ~/.selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim.basic"
2
  • do you use debian or a debian based distribution such as ubuntu,mint,kali? Commented 2 days ago
  • @D'ArcyNader I use Mint. Commented 2 days ago

2 Answers 2

15

On Debian and derivatives, crontab -e uses sensible-editor to launch an editor; this wasn’t mentioned in the man page until recently (see Debian bug #1079207 for details).

sensible-editor itself looks at a number of environment variables: VISUAL, EDITOR, SENSIBLE_EDITOR, and SELECTED_EDITOR, in that order. If none of those are set, it looks for a file named .selected_editor in your home directory, and uses whatever settings are defined there. If the file doesn’t exist, it runs select-editor to ask you to choose one. If the file does exist but doesn’t set either of the SELECTED_EDITOR or EDITOR variables, sensible-editor looks for editor, nano, nano-tiny, and vi, in that order.

Since you have a .selected_editor which specifies vim.basic, that’s what crontab -e uses.

1
  • Linux packaging systems are still confusing to me, but as far as I understand them, my cron package should be launchpad.net/ubuntu/+source/cron/3.0pl1-136ubuntu1. If it be so, then judging by the patches directory in cron_3.0pl1-136ubuntu1.debian.tar.xz, it looks that it's indeed Debian (or Ubuntu?) that adds a reference to the sensible-editor command. Then, I see that /usr/bin/sensible-editor is a script, and that it sources ~/.selected_editor. And ~/.selected_editor has been created by select-editor (as indicated in the listing I put in the question). Commented yesterday
2

Some distros include a command select-editor. Simply run that and choose an editor from the list.

$ select-editor

Select an editor. To change later, run 'select-editor'.

  1. /usr/bin/vim.gtk3
  2. /bin/nano <---- easiest
  3. /usr/bin/vim.basic
  4. /usr/bin/vim.tiny
  5. /bin/ed

Choose 1-5 [2]:

Further details are available.

(I am amazed that the cron and crontab man pages do not mention select-editor. Could that be considered a bug?)

4
  • 2
    Thank you, I think I might've come across select-editor, but my first goal is to know why Vim is run, and only then how to change it. Commented 2 days ago
  • 1
    @decision-making-mike, I have read several hints that crontab -e asks for an editor, only the first time it is run. I can't remember if that was true for me. You might try asking on a Mint forum forums.linuxmint.com . Commented 2 days ago
  • 1
    My vanilla Mint (21.3 Virginia) puts me directly into Nano. I have to admit the only Nano command I know is Ctrl-X, closely follower by: export EDITOR=vi Commented 2 days ago
  • "I am amazed that the cron and crontab man pages do not mention select-editor. Could that be considered a bug?": no, since this isn't a standard tool. I've never heard of it, and it isn't standard or even common. It seems to be an Ubuntu-specific thing, so while Ubuntu derivatives might be expected to have it, that is very far from "most" distros, and it would be wrong to include it in the man page of cron. Maybe Ubuntu systems could include it there, but not others. Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.