为Bash设置默认编辑器有什么好处?

时间:2017-01-26 04:08:00

标签: bash unix editor

我知道我们可以通过设置EDITOR变量来指定默认编辑器。当我们在打开vi 1.txtnano 1.txt等文件时直接指定编辑器名称时,设置此项的优势是什么?

2 个答案:

答案 0 :(得分:1)

我能想到的一个用途是当你想要编辑当前的命令行(readline edit-and-execute-command,通常绑定到C-xC-e)时,正在使用的编辑器是({{3}引用) }):

  

$VISUAL$EDITOR和emacs作为编辑,按此顺序。

因此,如果您尚未设置VISUAL并且不想使用emacs,则可以使用EDITOR=vim

另一个用途是fc,它调用${FCEDIT:-${EDITOR:-vi}}来编辑最后一个命令(参见manual),也许你不想使用vi。

所以,我要说EDITOR(以及相关的FCEDITVISUAL)的目的是在无法指定的情况下为您提供所需的编辑器直接在命令中。

答案 1 :(得分:1)

我将其设为lessman 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

有关
相关问题