Windows11 Ubuntu 24.04 (WSL) のデフォルトエディタを nano からviに変更する
概要
新規インストールしたUbuntuで、visudo などのコマンドを実行すると nano が起動してびっくりします。 デフォルトのエディタをnanoからviに設定する方法のメモです。
試した環境
- Windows11 pro
- Ubuntu 24.04.3 LTS(WLS)
実行方法
環境変数で一時的に変更する場合
EDITOR 環境変数を設定するか、以下のようにenvを使って実行します。
$ sudo env EDITOR=vi visudo
システムのデフォルト設定を変更する場合(恒久的)
update-alternatives コマンドを使います。
$ 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
tinyはシンプルすぎるので 理由がなければ vim.basic にするのがよいです。