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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:16:54  来源:igfitidea点击:

Bash's vim mode, not vi

bashvimvi

提问by mesmerizingr

I was fascinated when I discovered vi-like bash's editing mode. One can easily toggle it by issuing set -o vicommand. 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 vkey and edit your commands in a fully functional vi editor's window but I would like to know how to force bash to start vimeditor instead of vibecause of the perks vimprovides us (visual selection, additional commands etc)?

我的意思是,当您处于类似 vi 的模式时,您可以v按键并在功能齐全的 vi 编辑器窗口中编辑您的命令,但我想知道如何强制 bash 启动vim编辑器而不是vi因为vim我们提供的特权(视觉选择,附加命令等)?

采纳答案by Kent

If you set EDITORvariable, in bash you can press Ctrl-x ctrl-eto edit your current command line in your EDITORe.g. vim

如果您设置EDITOR变量,则在 bash 中您可以按下Ctrl-x ctrl-e以在您的EDITOReg 中编辑当前的命令行vim

EDIT

编辑

the ctrl-x ctrl-eis 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 EDITORvariable (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 vimin many other contexts too, such as in git, you should also set EDITOR:

如果您也想vim在许多其他上下文中使用,例如 in git,您还应该设置EDITOR

export EDITOR=/usr/bin/vim