TechBuzzPro

Change Default crontab Editor: Easy Fix

· 6 min read · Apps & Browsers

In this article
  1. Why the Default Editor Matters
  2. How the Editor Selection Works
  3. Method 1: Using select-editor (Debian/Ubuntu)
  4. Method 2: Setting EDITOR and VISUAL Variables
  5. Choosing the Right Editor for You
  6. Common Problems and Fixes
  7. Comparison: nano vs. vim for Crontab
  8. Frequently Asked Questions

To change the default crontab editor, you set the EDITOR or VISUAL environment variable in your shell profile, or use the select-editor command on Debian/Ubuntu systems. The quickest fix is running select-editor if available; otherwise, add export EDITOR=nano (or your preferred editor) to your ~/.bashrc or ~/.zshrc file.

Why the Default Editor Matters

When you run crontab -e to edit your cron jobs, the system opens a text editor. By default, many Linux distributions use nano because it's beginner-friendly, but others default to vi or vim, which have a steep learning curve. If you're not familiar with vi's modal interface, you can get stuck—typing text doesn't work as expected, and you might accidentally save or quit incorrectly. This frustration is the main reason people search for how to change the default editor.

The editor selection isn't stored in a single global config file. Instead, it's determined by environment variables that your shell reads when you start a terminal session. Understanding how these variables work gives you control not just over crontab, but over any command-line tool that launches an editor.

How the Editor Selection Works

The crontab command checks two environment variables in order: VISUAL and EDITOR. If VISUAL is set, it uses that; otherwise, it falls back to EDITOR. If neither is set, the system uses a compiled-in default (often vi or nano, depending on the distribution).

Here's the order of precedence:

  • VISUAL – used first if defined
  • EDITOR – used if VISUAL is not set
  • System default – usually vi or nano

Most documentation tells you to set EDITOR, but setting VISUAL is equally important because some systems and tools check it first. To be safe, set both to the same value.

Method 1: Using select-editor (Debian/Ubuntu)

On Debian-based distributions (Ubuntu, Mint, etc.), there's a handy command that walks you through the choice interactively. Run:

select-editor

You'll see a numbered list of installed editors, like:

Select an editor.  To change later, run 'select-editor'.  1. /bin/nano  2. /usr/bin/vim.basic  3. /usr/bin/vim.tiny  4. /bin/ed

Type the number and press Enter. This writes your choice to ~/.selected_editor, which the crontab script reads. It's the simplest method if you're on a Debian-based system.

If select-editor isn't found, you can install it (it's part of the cron package) or use the manual environment variable method below.

Method 2: Setting EDITOR and VISUAL Variables

This works on any Unix-like system. You add export lines to your shell's startup file. The file depends on your shell:

  • Bash: ~/.bashrc (or ~/.bash_profile for login shells)
  • Zsh: ~/.zshrc
  • Fish: ~/.config/fish/config.fish (use set -x instead of export)

Add these lines (replace nano with your editor of choice):

export EDITOR=nano
export VISUAL=nano

Then reload the file with source ~/.bashrc (or restart your terminal). To verify, run echo $EDITOR—it should print nano.

Choosing the Right Editor for You

Your choice depends on your comfort level and needs. Here are the common options:

  • nano – Simple, on-screen shortcuts (^X to exit, ^O to save). Great for beginners.
  • vim – Powerful but modal. You need to press i to insert, Esc to go back to command mode, then :wq to save and quit. Steep learning curve, but extremely efficient once mastered.
  • emacs – Full-featured, but heavy. Uses Ctrl+key combinations.
  • mcedit – Part of Midnight Commander; provides a menu-driven interface similar to old DOS editors.
  • code – If you have VS Code installed, you can use it, but it opens a GUI window, which might not work well over SSH without X forwarding.

For most people, nano is the safest choice because it's pre-installed on nearly every distribution and doesn't require learning special commands. If you're managing many servers and already know vim, stick with it.

Common Problems and Fixes

Even after setting the variables, you might run into issues. Here's how to troubleshoot:

  • Editor still opens vi: Check if VISUAL is set to something else. Run env | grep -E 'EDITOR|VISUAL' to see current values. Also check system-wide files like /etc/environment or /etc/profile that might override your user settings.
  • select-editor doesn't stick: The ~/.selected_editor file might be read before your shell profile. Ensure the file has the correct path. You can also manually edit it to SELECTED_EDITOR=/bin/nano.
  • Changes don't apply to cron: Cron runs with a minimal environment. If you set the variable only in .bashrc, it won't be picked up when cron runs scripts. For the interactive crontab -e command, it uses your shell environment, so it should work. If not, set the variable in ~/.profile as well.
  • Editor opens but appears blank: This can happen if the editor doesn't handle the temporary file format. Try a different editor, or check if the file has a .tmp extension that your editor ignores.

Comparison: nano vs. vim for Crontab

Let's compare the two most common choices directly:

  • Learning curve: nano is nearly zero; vim is steep.
  • Availability: nano is pre-installed on most modern distros; vim is often installed as vim.tiny (a minimal version) but full vim may need installation.
  • Keyboard shortcuts: nano shows them at the bottom; vim requires memorization.
  • Efficiency: vim is faster for heavy editing once mastered; nano is fine for occasional small edits like crontab.
  • Mistakes: In vim, a wrong key can change the file unintentionally; nano is more forgiving.

For the specific use case of editing crontab—which is usually a few lines—nano is the pragmatic choice for most users. You're unlikely to need vim's power for this task.

Frequently Asked Questions

How do I change the crontab editor permanently?

Add export EDITOR=nano and export VISUAL=nano to your shell profile (~/.bashrc for Bash, ~/.zshrc for Zsh). Then run source ~/.bashrc to apply immediately. This persists across sessions.

What if I only want to change it for one command?

You can prefix the command with the variable: EDITOR=nano crontab -e. This sets the variable only for that single execution, leaving your default untouched.

Why does crontab use vi even though I set EDITOR?

Check if VISUAL is set to something else. Since VISUAL takes precedence, if it points to vi, that's what opens. Unset it or set it to your preferred editor. Also verify your shell profile is actually being sourced (e.g., if you're using a non-login shell).

Is there a way to change it globally for all users?

Yes, you can set the variables in /etc/environment or /etc/profile, but this affects all users and requires root access. Be cautious, as some users may prefer a different editor. It's usually better to let each user set their own.

Does the editor choice affect cron job execution?

No. The editor is only used when you manually edit your crontab. The actual execution of cron jobs doesn't depend on any editor. It only matters when you run crontab -e.

Can I use a GUI editor like gedit or VS Code?

Yes, you can set EDITOR=gedit or EDITOR=code, but it only works if you're on a system with a graphical display and the application is installed. Over a pure SSH session without X forwarding, a GUI editor won't open. Stick to terminal-based editors for remote work.