How to Specify a Editor to Open Crontab File? "Export Editor=Vi" Does Not Work

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

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

export VISUAL=vi

Is there a way of editing crontabs without using vi?

You can set the editor that you want to use to edit your crontabs using export VISUAL=nano; crontab -e. Also, each user's crontabs can be found in /var/spool/cron/crontabs and there's various cron files and folders in /etc with /etc/crontab being the global crontab file.

How to save the file after typing crontab -e

The crontab -e command invokes your default editor, which is one of the following:

  • The command specified by the $VISUAL environment variable (if it's set); or
  • The command specified by $EDITOR; or
  • /usr/bin/editor

The latter is a symbolic link to some editor. On Linux, the default appears to be nano.

If it's nano, then there should be a 2-line menu at the bottom of the screen. Type Ctrl-X to exit; if you've modified the file it will ask you whether you want to save it.

If you have a preferred editor, you should set both $VISUAL and $EDITOR to the command used to invoke it. For example, I have:

export EDITOR=vi
export VISUAL=$EDITOR

in my $HOME/.bash_profile.

This applies to the system I'm using, a recent Linux system with the Vixie cron implementation. If your system differs significantly, not all of this is necessarily applicable.

man crontab should explain how the crontab command works. If not, the documentation is also available here.

(Incidentally, I keep my crontab in a separate file under my home directory, maintained in a source control system. That lets me keep track of changes and revert to a working version if I mess something up. With crontab -e, it's easy to make mistakes and difficult to recover from them.)

Why I've got no crontab entry on OS X when using vim?

Just follow these steps:

  1. In Terminal: crontab -e.
  2. Press i to go into vim's insert mode.
  3. Type your cron job, for example:

    30 * * * * /usr/bin/curl --silent --compressed http://example.com/crawlink.php
  4. Press Esc to exit vim's insert mode.

  5. Type ZZ to exit vim (must be capital letters).
  6. You should see the following message: crontab: installing new crontab. You can verify the crontab file by using crontab -l.

Note however that this might not work depending on the content of your ~/.vimrc file.

How to change default editor for crontab in CentOS7?

The export works like you see, but if you use sudo, you're running crontab as other user, in this case as root, then you need set EDITOR as root too.

(I post as answer because I can't comment)

Git-commit unable to open vim

the problem was that i had two environment variables that pointed to /usr/bin/mate in my .bash_profile
so i edit them to point to vim



Related Topics



Leave a reply



Submit