R.A. Epigonos et al.

[debian] システムのデフォルトエディタを vim に変更するには update-alternatives

contab -e などで起動するエディタは /usr/bin/editor であり、これは /etc/alternatives/editor のシンボリックリンク。これを変更するには update-alternatives を使う。

システムのデフォルトエディタを確認すると、nano が起動することが分かる。

# which editor
/usr/bin/editor
# ls -la /usr/bin/editor
lrwxrwxrwx 1 root root 24 Apr 29 14:36 /usr/bin/editor -> /etc/alternatives/editor
# ls -la /etc/alternatives/editor
lrwxrwxrwx 1 root root 9 Aug 28 17:42 /etc/alternatives/editor -> /bin/nano
# editor -h
Usage: nano [OPTIONS] [[+LINE,COLUMN] FILE]...

Option          GNU long option         Meaning
 -h, -?         --help                  Show this message
(snip)

これを変更するには update-alternatives を使う。vim に変更する。

# update-alternatives --config editor
There are 3 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path               Priority   Status
------------------------------------------------------------
* 0            /bin/nano           40        auto mode
  1            /bin/nano           40        manual mode
  2            /usr/bin/vim.nox    40        manual mode
  3            /usr/bin/vim.tiny   10        manual mode

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

変更後に シンボリックリンクの再確認。editor で vim が起動するようになったことが分かる。

# which editor
/usr/bin/editor
# ls -la /usr/bin/editor
lrwxrwxrwx 1 root root 24 Apr 29 14:36 /usr/bin/editor -> /etc/alternatives/editor
# ls -la /etc/alternatives/editor
lrwxrwxrwx 1 root root 16 Aug 28 17:44 /etc/alternatives/editor -> /usr/bin/vim.nox
# editor -h
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 10 2013 06:45:51)

usage: vim [arguments] [file ..]       edit specified file(s)
   or: vim [arguments] -               read text from stdin
   or: vim [arguments] -t tag          edit file where tag is defined
   or: vim [arguments] -q [errorfile]  edit file with first error

Arguments:
   --                   Only file names after this
(snip)

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-11-19T06:40:56+09:00
  2. Modified: 2008-11-19T06:40:56+09:00
  3. Generated: 2023-08-27T23:09:10+09:00