为 Bash 设置默认编辑器有什么好处?
What is the advantage of setting a default editor for Bash?
我知道我们可以通过设置 EDITOR
变量来指定默认编辑器。像vi 1.txt
或nano 1.txt
这样的文件打开时可以直接指定编辑器名称时设置这个有什么好处?
我能想到的一个用途是当你想编辑你当前的命令行(readline edit-and-execute-command
,通常绑定到 C-xC-e
),正在使用的编辑器是(引用自 manual):
$VISUAL
, $EDITOR
, and emacs as the editor, in that order.
所以如果你还没有设置VISUAL
并且不想使用emacs,你可以设置EDITOR=vim
,例如
另一个用途是fc
,它调用${FCEDIT:-${EDITOR:-vi}}
来编辑最后一个命令(参见manual),也许你不想使用vi。
所以,我想说 EDITOR
(以及相关的 FCEDIT
和 VISUAL
)的目的是在您无法做到的情况下为您提供您想要的编辑器直接在命令中指定它。
我设置为 less
(man less
):
v Invokes an editor to edit the current file being viewed. The
editor is taken from the environment variable VISUAL if defined,
or EDITOR if VISUAL is not defined, or defaults to "vi" if nei‐
ther VISUAL nor EDITOR is defined. See also the discussion of
LESSEDIT under the section on PROMPTS below.
也和使用有关emacs
as a daemon
我知道我们可以通过设置 EDITOR
变量来指定默认编辑器。像vi 1.txt
或nano 1.txt
这样的文件打开时可以直接指定编辑器名称时设置这个有什么好处?
我能想到的一个用途是当你想编辑你当前的命令行(readline edit-and-execute-command
,通常绑定到 C-xC-e
),正在使用的编辑器是(引用自 manual):
$VISUAL
,$EDITOR
, and emacs as the editor, in that order.
所以如果你还没有设置VISUAL
并且不想使用emacs,你可以设置EDITOR=vim
,例如
另一个用途是fc
,它调用${FCEDIT:-${EDITOR:-vi}}
来编辑最后一个命令(参见manual),也许你不想使用vi。
所以,我想说 EDITOR
(以及相关的 FCEDIT
和 VISUAL
)的目的是在您无法做到的情况下为您提供您想要的编辑器直接在命令中指定它。
我设置为 less
(man less
):
v Invokes an editor to edit the current file being viewed. The
editor is taken from the environment variable VISUAL if defined,
or EDITOR if VISUAL is not defined, or defaults to "vi" if nei‐
ther VISUAL nor EDITOR is defined. See also the discussion of
LESSEDIT under the section on PROMPTS below.
也和使用有关emacs
as a daemon