11

When I edit the crontab using crontab -e it opens the crontab in vi. I'd prefer it to use nano. How can I change this?

EDIT:

For some reason the export command returns command not found. And changing the EDITOR env value didn't work for crontab -e.

The following command worked on my system:

setenv VISUAL /usr/local/bin/nano

HopelessN00b
  • 54,273
Ian
  • 1,538

5 Answers5

15

For sh based shells:

export EDITOR=/path/to/nano

For C shell based:

setenv EDITOR /path/to/nano

Remember that unless you save these setting to your login profile script (/home/user/.bash_profile for example), you lose the setting at log out.

If I remember correctly, FreeBSD uses C shell as the default user shell.

David
  • 3,655
2

Should be

export EDITOR=/usr/bin/nano

adjust for your location of nano (use 'which' to find). You can put that command in your .bashrc or similar profile script to have it in effect all the time.

Kevin Kuphal
  • 9,194
1
  1. GNU nano is not part of the base system. You need to install it first. The most convenient option is installing a binary package:

    pkg install editors/nano # run as `root`
    

    Should this be your first invocation of the pkg command, pkg is bootstrapped first; after that you can re‑run the same command (now actually performing the installation).

    Alternatively, if you simply cannot cope with vi’s cryptic commands and mode‑ness, the “easy editor” ee is comparable to GNU nano and shipped as part of the base system since FreeBSD version 2.1.5.

  2. As the POSIX™ standard dictates, the value of the EDITOR environment variable is used to determine which editor to use for crontab -e, and if it is unset or null, vi is used as a fallback. Your question therefore boils down to “how do I set the environment variable?”

    To answer the question you need to assess where the particular environment variable’s value shall apply:

    • Is it system-wide for all users?
    • Is it system-wide for all users authenticating via a certain PAM service stack (e. g. only sshd)?
    • Is it system-wide for users logging in via certain channels (e. g. only ttyv4)?
    • Is it system-wide for all users using a particular shell (e. g. only zsh)?
    • Is it system-wide for one class of users?
    • Is it for one user?
    • Is it for one user using a particular shell?
    • Is it just for one invocation?

    Elaborating all options takes too long, so without knowing your specific requirements I claim you want to change ~/.login_conf:

    1. Ensure the EDITOR environment variable is not already set.
      printenv EDITOR
      
      If this prints a value, you should first try to track down where it gets set. If it is set via the global /etc/login.conf, you are good to go, because ~/.login_conf takes precedence. If it is set via some script sourced by your login shell, you need to amend this file first. Otherwise the next step would not make a difference.
    2. Now you can edit the file. Presuming ~/.login_conf did not already exist, simply write
      cat > ~/.login_conf << 'EOT'
      me:setenv=EDITOR=nano:
      EOT
      
      This has no immediate effect to the current session; you need to log‑in again to observe changes.

    The ~/.login_conf applies to the particular user only, but regardless of the shell used and regardless the specific login method (with respect to the default PAM configuration). It is ideal for preferences based on taste (like the EDITOR) or the human factor in general (natural language).

-1

Probably by setting the environment variable EDITOR.

I.e.

export EDITOR=/path/to/nano
-4

There is a symbolic link under /etc/alternatives/editor that can be pointed to /path/to/nano

You can use the update-alternatives utility to do this as well - although I am not too familiar with using it.

(note - I'm speaking from an 'ubuntu' point-of-view. not sure if this is the same for FreeBSD)

Brent
  • 24,065