Home > bash > Crontab and vim – No syntax highlighting

Crontab and vim – No syntax highlighting

Problem:
crontab -e displays the cron jobs but there is no syntax highlighting. But .vimrc has syntax on. When I run vim otherfile.sh the syntax highlighting kicks in. So the issue was with the editor that crontab uses.

shell> man crontab

-e This 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.

Solution:
Check if the EDITOR variable is set to vim. If not, then that is where the problem is.

1. How to check?

shell> set | grep EDITOR

If it returns blank or points to a different editor apart from vim then change it. Note that by default if the variable is not set, it will use vi. And that might be why the syntax does not show. There are also stripped down versions of vim eg vim-tiny that does not have syntax highlighting. (Unfortunately, I was not able to discover what editor crontab used.)

shell> which vim
/usr/bin/vim
shell>EDITOR="/usr/bin/vim"
shell>export EDITOR
shell> set | grep EDITOR
EDITOR=/usr/bin/vim
_=EDITOR

That should set your Editor to be vi for that session only. If you log out and log in your changes will be lost.

Making your change permanent.
1. Add the following to ~/.bash_profile (For that particular user) or to /etc/profile (For all users).

EDITOR="/usr/bin/vim"
export EDITOR

Source
http://www.netadmintools.com/art395.html

NB. I had this problem on a Red Hat server.

Advertisements
Categories: bash Tags: ,
  1. July 6, 2011 at 5:55 pm

    My crontab uses vim, but I specifically set vim as my editor.

  2. July 6, 2011 at 6:53 pm

    I think that is what I am going to start doing as well on new servers. Making it explicit.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: