16.04: crontab -e editor settings / Python syntax highlighting in vim
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
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
.
crontab -e
defaults to usingvi
for editing.
Not really. Per man crontab
:
The
-e
option is used to edit the current crontab using the editor specified by theVISUAL
orEDITOR
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
.