How to Change the Default Editor in csh and tcsh Using VISUAL and EDITOR

Choosing the right default text editor is an important step when customizing a Unix-like system. Whether you are editing configuration files, writing scripts, or maintaining servers, having your preferred editor launch automatically can make daily tasks faster and more comfortable.

In this guide, we will explore how to set the default text editor in csh and tcsh, both temporarily and permanently. We will also look at what these shells are, where they are used, and how they compare with more common shells such as bash, zsh, and ksh.


What Is csh?

The C shell (csh) is a Unix shell originally developed at the University of California, Berkeley. It was designed with a syntax similar to the C programming language, which made it attractive to developers already familiar with C.

Some of the well-known features of csh include:

  • Command history
  • Job control
  • Alias support
  • A scripting syntax inspired by the C programming language

Because of its historical connection to BSD systems, csh has long been the default shell on many BSD operating systems, including FreeBSD and earlier BSD derivatives.

Although modern Linux distributions rarely use it as a default shell, csh is still available on many systems for compatibility and legacy workflows.

Compared to modern shells such as bash, zsh, or ksh, csh scripting is often considered less flexible. However, the shell remains important in certain Unix and BSD environments.


What Is tcsh?

tcsh (TENEX C shell) is an enhanced and largely compatible version of csh. It builds on the original shell and introduces many improvements designed to make interactive use easier.

Some of the improvements included in tcsh are:

  • Command line editing
  • Programmable tab completion
  • Improved command history
  • Better interactive usability

Because of these additions, tcsh is often preferred over the original csh by users who want the C shell environment but with modern interactive features.

Many BSD systems install tcsh by default, and in some cases it replaces csh as the primary interactive shell.


Where Are csh and tcsh Used?

Today, csh and tcsh are most commonly found on BSD-based operating systems. These include:

  • FreeBSD
  • OpenBSD
  • NetBSD

They may also appear on Unix servers or systems that rely on older scripts written specifically for the C shell.

On Linux distributions, these shells are usually optional rather than default. Systems like Xubuntu and Lubuntu typically use bash as the default shell, although users can install and use tcsh or csh if they prefer.

In modern Linux environments, the most widely used shells are:

  • bash โ€“ the standard shell for most Linux distributions
  • zsh โ€“ popular for customization and powerful features
  • ksh โ€“ the Korn shell, historically important in Unix systems

Even though these shells dominate modern Linux environments, understanding csh and tcsh can still be useful when working with BSD systems or maintaining legacy infrastructure.


Why the Default Text Editor Matters

Many command-line tools rely on environment variables to determine which text editor should open when editing files.

Examples include:

  • editing crontab entries
  • writing commit messages in version control systems
  • modifying configuration files
  • editing system scripts

While modern desktop systems often rely on graphical applications for editing files, server and terminal environments usually depend on command-line editors.

On desktop Linux systems, users frequently work with graphical applications such as Visual Studio Code, a popular development editor, OnlyOffice for editing office documents, or Pinta, a lightweight image editing program. These tools are common on desktop environments found in distributions like Xubuntu or Lubuntu.

However, when working directly inside a terminal or on remote servers accessed through SSH, graphical tools are usually not available. In these situations, lightweight terminal editors such as nano, vim, or vi are typically used.

Because many command-line tools rely on environment variables like VISUAL and EDITOR to determine which editor to launch, configuring your preferred editor ensures a consistent workflow across different Unix systems.


Setting the Default Editor Temporarily

If you only want to change the editor for the current shell session, you can set the VISUAL and EDITOR environment variables.

For example, to temporarily set nano as the default editor:

setenv VISUAL /usr/local/bin/nano
setenv EDITOR /usr/local/bin/nano

These variables tell applications which editor should be launched when text editing is required.

  • VISUAL is typically used for full-screen editors.
  • EDITOR acts as a general fallback variable.

Setting both variables to the same editor helps prevent inconsistencies between different programs.

Remember that this change only affects the current shell session. Once you close the terminal or log out, the settings will disappear.


Making the Default Editor Permanent

To make the configuration permanent, you need to add the editor settings to your shell configuration file.

For csh, the configuration file is usually:

~/.cshrc

For tcsh, the configuration file may be:

~/.tcshrc

You can add the editor configuration using the following commands:

echo "setenv VISUAL /usr/local/bin/nano" >> ~/.cshrc
echo "setenv EDITOR /usr/local/bin/nano" >> ~/.cshrc

If you are using tcsh, you may prefer to update the .tcshrc file instead:

echo "setenv VISUAL /usr/local/bin/nano" >> ~/.tcshrc
echo "setenv EDITOR /usr/local/bin/nano" >> ~/.tcshrc

After adding these lines, the editor will automatically be configured each time a new shell session starts.


Applying the Changes Without Restarting the Shell

After modifying the configuration file, you do not necessarily need to log out or restart your terminal.

Instead, you can reload the configuration file with the source command:

source ~/.cshrc

or

source ~/.tcshrc

This forces the shell to re-read the configuration file and apply the changes immediately.


Why Setting Both VISUAL and EDITOR Is Important

Different programs rely on different environment variables when deciding which editor to launch.

For example:

  • crontab -e may rely on EDITOR
  • other tools may check VISUAL first

If only one variable is configured, some programs might open a different editor than expected.

By setting both VISUAL and EDITOR to the same value, you ensure consistent behavior across command-line tools, scripts, and system utilities.

This small configuration step can make daily system administration tasks much smoother, especially when managing servers or working across multiple Unix environments.


Conclusion

Setting the default text editor in csh or tcsh is a simple but valuable customization for anyone working with Unix or BSD systems. By configuring the VISUAL and EDITOR environment variables, you ensure that your preferred editor is used whenever a program needs to edit text.

Although modern Linux users often rely on shells like bash, zsh, or ksh, knowing how to configure csh-style environments remains useful when working with BSD systems or legacy Unix infrastructure.

With just a few small configuration changes, you can make your command-line environment more consistent, efficient, and comfortable to use.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *