How to Set the Default Text Editor in csh and tcsh

Choosing your default text editor is an important part of customizing your Unix or BSD system environment. Whether you are editing configuration files or writing scripts, having your preferred editor available by default can make your workflow much more efficient. In this guide, we will explore how to set the default text editor in the C shell (csh) and the TENEX C shell (tcsh), both temporarily and permanently.

The default shell in systems like FreeBSD and PC-BSD is often the C shell (csh), making this information especially useful for *BSD users. Although Linux users typically work with bash, zsh, or other shells, knowing how to configure csh or tcsh remains valuable for certain environments or legacy systems.

Setting the Default Text Editor Temporarily

If you want to set the default text editor for just the current session, you can do so by setting the VISUAL and EDITOR environment variables. Here is how you can temporarily set nano as the default editor:

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

The VISUAL and EDITOR environment variables are both used by programs to determine which editor to launch. While VISUAL is often prioritized for visual editors (like nano or vim), EDITOR is used more generally. Setting both variables to the same value helps prevent inconsistencies across different programs and scripts that rely on these variables.

Remember that setting the editor this way is temporary. Once you close the shell or log out, these settings will be lost.

Making the Default Editor Permanent

To make your preferred text editor setting permanent across shell sessions, you need to add the setenv commands to your shell configuration file. In csh and tcsh, this is typically the ~/.cshrc file, or the ~/.tcshrc file if you are using tcsh.

You can add the following lines to ~/.cshrc:

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

Or, if you are using tcsh and the ~/.tcshrc file exists, you should add them there instead:

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

After editing the configuration file, either log out and log back in, or reload the configuration by sourcing the file manually:

$ source ~/.cshrc

or

$ source ~/.tcshrc

This will apply your new settings immediately without the need to restart the terminal.

Why Setting Both VISUAL and EDITOR Matters

You might wonder why it’s necessary to set both VISUAL and EDITOR. Some programs respect only one of these environment variables, and different programs may prioritize them differently. For example, crontab -e may use EDITOR, while a graphical program that launches a terminal editor may check VISUAL first. Setting both ensures consistent behavior across the system.

Moreover, if you prefer using more advanced editors like vim or simpler ones like nano, setting both variables avoids confusion, especially when dealing with scripts, cron jobs, version control systems, or remote server administration tasks.

Conclusion

Customizing your environment by setting the default text editor in csh and tcsh is a straightforward but important step for anyone using BSD or similar Unix systems. By setting both VISUAL and EDITOR environment variables—temporarily for a session or permanently for all future sessions—you ensure a smoother and more predictable editing experience.

Remember to always set both variables to the same path to avoid inconsistencies and unexpected behavior. Whether you are a seasoned system administrator or a beginner exploring *BSD systems, mastering these small configuration tweaks can significantly enhance your productivity and comfort.

1 Comment

Leave a Reply

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