Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to figure out why I don't have syntax highlighting when editing my crontab.

I have both $EDITOR and $VISUAL set to /usr/bin/vim:

> echo $EDITOR
/usr/bin/vim
> echo $VISUAL
/usr/bin/vim

If I save the crontab to a file and edit it with vim syntax highlighting is enabled.

> crontab -l > saved_cronab
> /usr/bin/vim saved_crontab

And if I use :syntax on while editing the crotab nothing changes

How can I enable highlighting when editing crontab with crontab -e?

share|improve this question

migrated from serverfault.com Mar 24 '13 at 4:53

This question came from our site for system and network administrators.

up vote 0 down vote accepted

Did you export these variables (export EDITOR VISUAL)?

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – mdpc Mar 22 '13 at 0:40
    
@mdpc Actually it does answer the question, and I'll bet it's the right answer, too. – Michael Hampton Mar 22 '13 at 1:30
    
@mdpc Probably export is an answer, but you are right - I bit misunderstand "you can answer but not comment" policy. Sorry about that. Should I remove my another "clarification request" (serverfault.com/questions/490255/…) ? – dsznajder Mar 22 '13 at 5:47

vim doesn't know, that your file saved_crontab is a crontab. Therefore, you don't get a special syntax highlighting for crontabs. Setting the filetype to crontab worked for me. I used:

:set ft=crontab

You can see the value of filetype with:

:set ft?
share|improve this answer
    
You can also permanently set the modeline for this file by adding a modeline like # vim: ft=crontab to the top of the file. However modelines are disabled by default for security reasons as root and by some distributions. – Erik Apr 5 '13 at 13:39
    
Agreed: setting EDITOR or VISUAL is irrelevant, since OP ran vim directly. Further clarification would improve the answer, but the information in this question addresses the problem. – Thomas Dickey Mar 27 at 18:32

This worked for me:

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

Add this to ~/.bash_profile to enable this for current user.
Add this to /etc/profile/any_file_you_like to enable this for all users.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.