0

crontab -e defaults to using vi for editing.

This is not usually a problem. vi is an excellent editor, and easy to learn.


Recently I've begun to use vim which is installed by

sudo apt-get update
sudo apt-get install vim

and in order to make it show line numbers and default to proper numbers of spaces when Tab is pressed, plus syntax highlighting for Python development,

the contents of my /home/username/.vimrc file is as so:

syntax enable
set number
set ts=4
set autoindent
set expandtab
set shiftwidth=4
set cursorline
set showmatch
let python_highlight_all = 1

This works out great.


However, when I use crontab -e it gives the following error messages:

Sorry, the command is not available in this version: syntax enable

Sorry, the command is not available in this version: let python_highlight_all = 1

Press ENTER or type command to continue

Then pressing Enter allows it to continue into vi for editing of the cron table.

Questions: What version of vi is it trying to use? Is there a way to set it to the normal vim? Or to set it to another editor?

2
  • The "version of vi" is exactly the same version of vim you are running when you type vim, except it is run in vi-compatible mode.
    – fkraiem
    Nov 20, 2017 at 6:29
  • I am not sure what you mean by that. In any case, the answer below solves the problem.
    – SDsolar
    Nov 20, 2017 at 17:32

3 Answers 3

4

When the environment is checked with the env command

env

there is no default EDITOR specified.

Not wanting to waste time trying to figure out what version of vi it is trying to use, it seems better to simply solve the problem.

Thus, the solution is simple.

export EDITOR=gedit

Alternatively, it can be set to your favorite editor like this:

export EDITOR=nano

or

export EDITOR=leafpad

Once the EDITOR is specified in the environment, crontab -e uses it.

Short and sweet.


To make this change take effect at login this line can be appended to /home/username/.bashrc.

2

crontab -e defaults to using vi for editing.

Not really. Per 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 automatically. If neither of the environment variables is defined, then the default editor /usr/bin/editor is used.

/usr/bin/editor is a symlink managed by the alternatives system: it points to /etc/alternatives/editor, which is itself a symlink to the actual editor. It does not really have a "default" value, as its value at any time depends on the editors which are actually installed on the system. You can obtain its current value with ls -l /etc/alternatives/editor, and modify it with sudo update-alternatives --config editor.

1
  • Makes sense. I'm glad I can override it by exporting EDITOR to get the editor I want. Just a single line of code in the right place, without worries.
    – SDsolar
    Nov 21, 2017 at 1:09
0

in ubuntu 18.04 Right click on file select properties select third tab open with add new and set it as default.

1
  • 2
    The question is specific to the crontab files (stored in /var/spool/cron/crontabs) and the manual pages for crontab indicate that is not a good idea to edit these files directly. The method that you are proposing would do just that, however. Jan 24, 2019 at 16:18

You must log in to answer this question.

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