Windows 11 Ubuntu 24.04 (WSL): Change the Default Editor from nano to vi

Overview

When you run a command such as visudo on a newly installed Ubuntu system, it can be surprising to see nano start up. This is a note on how to change the default editor from nano to vi.

Test Environment

  • Windows 11 Pro
  • Ubuntu 24.04.3 LTS (WSL)

How to Change It

Temporarily Change It with an Environment Variable

Set the EDITOR environment variable, or run the command with env as shown below.

$ sudo env EDITOR=vi visudo

Change the System Default Setting (Permanent)

Use the update-alternatives command.

$ sudo update-alternatives --config editor
There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    15        manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode

vim.tiny is too minimal, so unless you have a specific reason not to, vim.basic is the better choice.

Sponsored links
Follow ☆Geha☆