![如何更改 Debian (squeeze) 發行版中的預設文字編輯器](https://rvso.com/image/23931/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9%20Debian%20(squeeze)%20%E7%99%BC%E8%A1%8C%E7%89%88%E4%B8%AD%E7%9A%84%E9%A0%90%E8%A8%AD%E6%96%87%E5%AD%97%E7%B7%A8%E8%BC%AF%E5%99%A8.png)
「喬自己的編輯」對我來說並不自然。如何改為使用 nano 或 vim?
我試過了
export EDITOR=nano
但似乎並沒有受到尊重。我visudo
也想尊重這一點。
答案1
若要在系統層級變更預設編輯器:
sudo update-alternatives --config editor
然後按照螢幕上的提示進行操作。
答案2
更改帳戶預設編輯器的方法是設定EDITOR
環境變數。如果這對你不起作用,那麼你就做了一些不尋常的事情。檢查您是否還定義了VISUAL
,或者如果定義了,請為這兩個變數指定相同的值(請參閱VISUAL 與 EDITOR – 有什麼不同?)。將這些行添加到您的~/.profile
(注意:不~/.bashrc
):
EDITOR=nano
VISUAL=$EDITOR
export EDITOR VISUAL
在下面Debian 政策,所有程式都應該支援EDITOR
並VISUAL
設定預設編輯器。
在 Debian 及其衍生版本下,您可以使用替代機制設定係統範圍的預設編輯器,正如史蒂夫·羅比拉德所提到的:update-alternatives --config editor
以 root 身分運行。
答案3
上面提到的解決方案有效,但不可編寫腳本。如果您想以可編寫腳本(非互動式)的方式執行此操作,您應該使用 --set:
# update-alternatives --set editor /usr/bin/vim.basic
您可以透過以下方式取得選項清單:
$ update-alternatives --list editor
答案4
我遇到了同樣的問題,但是透過 update-alternatives 設定它並不能完全解決 Raspbian Buster (10.2) 上的問題。雖然我將 vim.basic 設定為預設編輯器(手動使用 update-alternatives --config 編輯器),但它的優先權只有 30,而 nano 的優先權為 40。
root@rsyslog:~/scripts# 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:
我開始查看常用的設定檔和點文件,並發現了以下文件:
root@rsyslog:~/scripts# cat /root/.selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/bin/nano"
root@rsyslog:~/scripts#
設定 vim.basic 之後通過/usr/bin/選擇編輯器,該文件包含 vim.basic:
root@rsyslog:~/scripts# /usr/bin/select-editor
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]: 2
root@rsyslog:~/scripts# cat /root/.selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim.basic"
root@rsyslog:~/scripts#
現在我可以再次使用 VIM 執行 crontab -e :)。