Knowledge Base

How to set the default text editor in Linux

This article describes how to set the default text editor in the Linux command-line environment.

Setting the default text editor

You can change the default command-line text editor used by various programs, such as crontab. For example, many accounts are configured to use nano as the default text editor. However, if you are more familiar with vi, you may want to use it as the default editor instead.

To change the default command-line text editor, follow these steps:

  1. Log in to your account using SSH.
  2. Open the .bashrc file in your preferred text editor.
  3. Add the following lines to the .bashrc file. Replace both occurrences of program with the editor you want to set as the default editor:
    export EDITOR='program'
    export VISUAL='program'
    • To set vi as the default text editor, replace program with vi.
    • To set nano as the default text editor, replace program with nano.
  4. Save the changes to the .bashrc file and exit the text editor.

  5. To make the new default text editor settings take effect, log out of your account and then log back in. Alternatively, you can just type the following command:

    source .bashrc