Ubuntu

How to Change the Default Editor on Ubuntu to Vi: A Definitive Guide


At CODE TOT, our development workflow is built on speed and precision. While Ubuntu defaults to Nano for its beginner-friendly interface, most senior developers eventually find themselves reaching for the power of Vi or Vim.

Whether you are configuring a production server or streamlining your local environment, setting your preferred editor is one of the first steps to a professional Linux setup. In this guide, we’ll walk you through the industry-standard methods to make the switch permanently.

Why Move from Nano to Vi?

Nano is great for quick edits, but as your projects grow at CODE TOT, you need an editor that handles complex text manipulation. Vi (and its improved version, Vim) offers:

  • Modal Editing: Lightning-fast navigation without leaving the home row.
  • Efficiency: Powerful regex support and macro recording.
  • Ubiquity: Vi is available on almost every Unix-like system in existence.

Method 1: System-Wide Change (The Debian Way)

Ubuntu uses the update-alternatives system to manage default applications. This is the cleanest method because it updates the symlinks for all users and system processes (like visudo or crontab -e).

Step 1: Run the configuration command

Open your terminal and execute the following with sudo privileges:

Bash

sudo update-alternatives --config editor

Step 2: Select Vi/Vim

You will see a list of installed editors. Locate /usr/bin/vim.basic or /usr/bin/vi.

  • Look for the selection number next to your choice.
  • Type the number and press Enter.

Troubleshooting: Handling “Skip Creation” Warnings

Sometimes, after selecting your editor, you might see a wall of text like this:

update-alternatives: warning: skip creation of /usr/share/man/man1/editor.1.gz because associated file... doesn't exist

What does this mean?

Don’t panic! This is not an error. It simply means the system successfully changed your default editor, but it couldn’t find the manual (help) files for specific languages (like French, Polish, or Japanese). This is very common on “minimal” Ubuntu installs or cloud VPS instances where documentation is stripped to save space.

The Fix

If you want a clean, warning-free system, you can reinstall the missing documentation components:

Bash

sudo apt update && sudo apt install --reinstall vim-common

For a complete fix on minimal cloud images, you can run sudo unminimize, though be aware this downloads several hundred megabytes of standard documentation.


Method 2: User-Specific Change (Environment Variables)

If you are working on a shared server and only want to change the editor for your profile, use environment variables.

Step 1: Edit your Bash profile

Open your .bashrc file:

Bash

nano ~/.bashrc

Step 2: Export the EDITOR variable

Scroll to the end of the file and add these lines:

Bash

export EDITOR='vi'
export VISUAL='vi'

Step 3: Apply the changes

Save the file and refresh your session:

Bash

source ~/.bashrc

Expert Summary Table

Featureupdate-alternatives.bashrc Export
ScopeSystem-wide (all users)Current user only
PermissionRequires sudoNo root access needed
Best ForPersonal machines/Local VMsShared servers/Cloud instances
ReliabilityHighest (affects system calls)High (affects shell sessions)

Final Thoughts

Switching to Vi is more than just a preference; it’s a rite of passage for web experts. While the learning curve is steeper, the productivity gains in the long run are undeniable.


Share


Categories