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?
When the environment is checked with the
env
commandthere 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.
Alternatively, it can be set to your favorite editor like this:
or
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
.Not really. Per
man crontab
:/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 withls -l /etc/alternatives/editor
, and modify it withsudo update-alternatives --config editor
.in ubuntu 18.04 Right click on file select
properties
select third tabopen with
add new and set it as default.