9

I would like to edit crontab with vi once. My default editor is nano, and I want to keep it that way. I only want to edit with vi one time. I don't want to change the default to vi then back to nano after editing. Can this be done?

12

crontab should respect the EDITOR environment variable, so you can just do (for the root crontab for example)

sudo EDITOR=vi crontab -e

From man crontab

The -e option is used to edit the  current  crontab  using  the  editor
specified  by  the  VISUAL  or EDITOR environment variables.  
| improve this answer | |
  • I don't think you want sudo here unless you want to edit really fundamental tasks. Most people run cron jobs at user-level. Also, on Mac OS X if you use sudo it gives an error. Without it it works fine. – Sridhar Sarnobat Dec 5 '17 at 23:58
0

Specify nano as the editor for crontab file

export VISUAL=nano; crontab -e

Specify vim as the editor for crontab file

export VISUAL=vim; crontab -e
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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