Bash 的 vim 模式,而不是 vi
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23230990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash's vim mode, not vi
提问by mesmerizingr
I was fascinated when I discovered vi-like bash's editing mode. One can easily toggle it by issuing set -o vi
command. But is there any way to toggle vim-like mode?
当我发现类似 vi 的 bash 的编辑模式时,我着迷了。可以通过发出set -o vi
命令轻松切换它。但是有没有办法切换类似 vim 的模式?
I mean when you are in a vi-like mode you can press v
key and edit your commands in a fully functional vi editor's window but I would like to know how to force bash to start vim
editor instead of vi
because of the perks vim
provides us (visual selection, additional commands etc)?
我的意思是,当您处于类似 vi 的模式时,您可以v
按键并在功能齐全的 vi 编辑器窗口中编辑您的命令,但我想知道如何强制 bash 启动vim
编辑器而不是vi
因为vim
我们提供的特权(视觉选择,附加命令等)?
采纳答案by Kent
If you set EDITOR
variable, in bash you can press Ctrl-x ctrl-e
to edit your current command line in your EDITOR
e.g. vim
如果您设置EDITOR
变量,则在 bash 中您可以按下Ctrl-x ctrl-e
以在您的EDITOR
eg 中编辑当前的命令行vim
EDIT
编辑
the ctrl-x ctrl-e
is for emacs mode commandline editing, which is the default one. If you have already set it to vi mode, you could do what you have said, pressing the v
. If you want to open the cmd line in vim, you have to set the EDITOR
variable (in your .bashrc for example)
的ctrl-x ctrl-e
是emacs模式命令行编辑,这是默认的。如果您已经将其设置为 vi 模式,则可以按照您所说的操作,按v
. 如果你想在 vim 中打开 cmd 行,你必须设置EDITOR
变量(例如在你的 .bashrc 中)
Personally I edit command line in emacs mode, even though vim is my main (and only) editor.
我个人在 emacs 模式下编辑命令行,即使 vim 是我的主要(也是唯一的)编辑器。
回答by merlin2011
In your .bashrc
, put the following line:
在您的 中.bashrc
,放置以下行:
export VISUAL=/usr/bin/vim
If you want vim
in many other contexts too, such as in git
, you should also set EDITOR
:
如果您也想vim
在许多其他上下文中使用,例如 in git
,您还应该设置EDITOR
:
export EDITOR=/usr/bin/vim