How to specify a editor to open crontab file? "export EDITOR=vi" does not work

LinuxVim

Linux Problem Overview


I'm using Red Hat Enterprise Linux 5, and I want to set the vim editor to edit the crontab file.

If I run echo $EDITOR, I get vim. But when I run crontab -e, I get different editor.

Linux Solutions


Solution 1 - Linux

Very probable that your VISUAL environment variable is set to something else. Try:

export VISUAL=vi

Solution 2 - Linux

To quote the man:

> The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables

Most often if you run crontab -e from X, you have VISUAL set; that's what is used. Try this:

VISUAL=vi crontab -e

It just worked for me :)

Solution 3 - Linux

If the above methods don't work (as they didn't work on my Ubuntu 13.04 installation) try:

There are a number of alternative ways:

1) Run select-editor

select-editor

2) Manually edit the file: ~/.selected_editor specifying your preferred editor. With this option you can specify editor parameters.

# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/emacs -nw"

3) You can specify on the fly on the commandline with:

env VISUAL="emacs -nw" crontab -e

Solution 4 - Linux

You can use below command to open it in VIM editor.

export VISUAL=vim; crontab -e

Note: Please make sure VIM editor is installed on your server.

Solution 5 - Linux

I think you might need to use the full path:

export EDITOR=/usr/bin/vim

Solution 6 - Linux

export EDITOR=vim worked for me

Solution 7 - Linux

It wasn't working for me. I run crontab with sudo, so I switched to root, did the above suggestions, and crontab would open in vim, but it still wouldn't from my user account. Finally I ran sudo select-editor from the user account and that did the trick.

Solution 8 - Linux

This worked for me :

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

Add this to ~/.bash_profile or ~/.bashrc to enable this for current user.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionantonjsView Question on Stackoverflow
Solution 1 - LinuxbmkView Answer on Stackoverflow
Solution 2 - Linux9000View Answer on Stackoverflow
Solution 3 - LinuxL. D. JamesView Answer on Stackoverflow
Solution 4 - LinuxParveen ShukhalaView Answer on Stackoverflow
Solution 5 - LinuxAlex HowanskyView Answer on Stackoverflow
Solution 6 - LinuxChemaView Answer on Stackoverflow
Solution 7 - LinuxfelwitheView Answer on Stackoverflow
Solution 8 - LinuxWalkView Answer on Stackoverflow