Smi*_*ile 9 editor command-line environment-variables less
在运行less命令时,按下v可在编辑器中打开文件。我已通过运行命令将EDITOR环境变量设置为。viexport EDITOR=vi
它按预期工作得很好。但是,当我重新启动计算机时,编辑器不再是 Vi。我如何使它永久?
Zan*_*nna 14
我通常使用以下方法全局配置此行为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:
Run Code Online (Sandbox Code Playgroud)
我已经选择了 Vim,但nano它是 Ubuntu 默认的。3在我的示例中,如果尚未选择 Vim,您将键入以选择 Vim。
此外less,任何调用编辑器(例如sudoedit)的程序现在都应该调用选定的编辑器。
要使其永久化,只需在终端中执行以下操作:
echo "export EDITOR=vi" >> ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
这会将行添加到您的.bashrc文件中,每次打开终端窗口时都会调用该行。
要回答为什么即使在添加到之前已经有类似的行也会起作用的原因.bashrc很简单。.bashrc是一个将以线性方式读取和执行的脚本,并且此方法将此行添加为所有其他行的最后一行,因此它被执行/评估为最后一行。所以如果之前有一行,EDITOR变量的值会被你添加的行覆盖。
或者,如果您不想弄得一团糟,您也可以使用您最喜欢的编辑器(vi、vim、nano、joe 等)来进行此更改,如果不存在则添加一行,如果存在则对其进行编辑。
| 归档时间: |
|
| 查看次数: |
2344 次 |
| 最近记录: |