How to Change Default Crontab Editor from vi to nano in FreeBSD for Easier Cron Job Editing


2 views

When working with cron jobs in FreeBSD, you'll notice that crontab -e always opens the vi editor by default. While vi is powerful, many developers (especially those coming from Linux backgrounds) prefer nano for its simpler interface and immediate usability.

The system selects the editor based on these environment variables in order of priority:

  1. VISUAL
  2. EDITOR
  3. Fallback to vi

This explains why simply setting EDITOR often doesn't work - VISUAL takes precedence.

In FreeBSD's tcsh default shell, you need to use setenv instead of export:

# For current session only
setenv VISUAL /usr/local/bin/nano

# To make permanent, add to ~/.cshrc
echo 'setenv VISUAL /usr/local/bin/nano' >> ~/.cshrc

For bash/sh users or system-wide configuration:

# In ~/.profile or ~/.bashrc
export VISUAL=/usr/local/bin/nano
export EDITOR=$VISUAL

# System-wide configuration (not recommended)
# Add to /etc/csh.cshrc or /etc/profile

After making changes, verify with:

echo $VISUAL
crontab -e  # Should now open in nano
  • Ensure nano is actually installed: pkg install nano
  • Check executable path with which nano
  • Some systems may require both VISUAL and EDITOR set
  • Try opening a new terminal session after changes

To set this as default for all users (use cautiously):

# For tcsh users
echo 'setenv VISUAL /usr/local/bin/nano' >> /etc/csh.cshrc

# For sh/bash users
echo 'export VISUAL=/usr/local/bin/nano' >> /etc/profile
echo 'export EDITOR=$VISUAL' >> /etc/profile

When working with cron jobs in FreeBSD, many developers find the default vi editor unintuitive and prefer more user-friendly alternatives like nano. While FreeBSD traditionally defaults to vi for crontab editing, changing this behavior requires understanding several environment variables.

Three key environment variables control editor preferences:

  • EDITOR: The traditional variable for text editor preference
  • VISUAL: Originally meant for visual editors (versus line editors)
  • CRONTAB_EDITOR: Some systems support this specific variable

Many guides suggest simply exporting EDITOR, but this often doesn't work because:

  1. The crontab command may prioritize VISUAL over EDITOR
  2. Shell configuration files might not be sourced when cron runs
  3. FreeBSD's default configuration may override user settings

For FreeBSD specifically, the most reliable method is:

setenv VISUAL /usr/local/bin/nano

Alternatively, for permanent configuration in your shell initialization file (~/.cshrc for tcsh or ~/.bashrc for bash):

# For tcsh/csh
setenv VISUAL /usr/local/bin/nano

# For bash/sh
export VISUAL=/usr/local/bin/nano

After making changes, verify with:

echo $VISUAL
which nano

If nano isn't installed (common on minimal FreeBSD setups), install it first:

pkg install nano

If the above doesn't work, try these additional methods:

# Method 1: Create an alias
alias crontab="VISUAL=nano crontab"

# Method 2: Use a wrapper script
#!/bin/sh
export VISUAL=/usr/local/bin/nano
/usr/bin/crontab "$@"
  • Check nano's full path with which nano
  • Ensure your shell initialization file is being sourced
  • Try both VISUAL and EDITOR in combination
  • Verify permissions on /usr/local/bin/nano