The default text editor on the Linux command line is an essential tool for developers and system administrators alike. Depending on the Linux distribution, the default editor might be nano, vi, or something else. However, you might prefer to use a different editor based on your personal preferences, features, or ease of use. Changing the default editor is a simple process, and this tutorial will guide you through the steps to do so.

Selecting the right text editor can improve productivity and make tasks such as editing configuration files or writing scripts more enjoyable. Popular text editors include Vim, Emacs, Sublime Text, and Visual Studio Code, each with its unique set of features and capabilities. It's essential to choose a text editor that aligns with your workflow and comfort level.

In this tutorial, we'll provide a step-by-step guide on how to change the default text editor on your Linux command line. The process is relatively simple and involves updating the appropriate environment variables and configuring the system's alternatives. By following these steps, you'll be able to configure your preferred text editor as the default choice for your command line operations.

Steps to set default editor for Linux command line:

  1. Install your preferred text editor, if not already installed, using your distribution's package manager.
    sudo apt install vim
  2. Check the current default editor.
    echo $EDITOR
  3. Set the environment variable $EDITOR in your shell's configuration file (e.g., ~/.bashrc, ~/.zshrc, ~/.profile) to point to the desired editor's executable.
    echo "export EDITOR=vim" >> ~/.bashrc
  4. Reload the shell configuration file to apply the changes.
    source ~/.bashrc
  5. Verify the new default editor is set correctly.
    echo $EDITOR
  6. (Optional) Check the available editors by running the following command.
    sudo update-alternatives --list editor
  7. (Optional) Update the system-wide default editor using the update-alternatives command (Debian-based distributions only).
    sudo update-alternatives --config editor
  8. (Optional) Follow the interactive prompts to select your preferred text editor.
Discuss the article:

Comment anonymously. Login not required.