简体   繁体   English

如何让 zsh prompt vi 模式使用我的 .vimrc?

[英]How to make zsh prompt vi mode use my .vimrc?

I am very fond of Vim, and have defined a lot of keymappings to make editing text smoother and easier.我非常喜欢 Vim,并且定义了很多按键映射,使编辑文本更加流畅和轻松。 And since the zsh prompt has a vi mode, which uses the default configs of vi, I was wondering if one could tell zsh to use vi as configured in one's .vimrc.而且由于 zsh 提示符有一个 vi 模式,它使用 vi 的默认配置,我想知道是否可以告诉 zsh 使用 .vimrc 中配置的 vi。

Ideas, anyone ?想法,有人吗?

Many applications offer "vi mappings";许多应用程序提供“vi 映射”; often, these are limited to common navigations ( hjkl ) and simple editing operations ( <Cw> , <Cu> ).通常,这些仅限于常见的导航 ( hjkl ) 和简单的编辑操作 ( <Cw><Cu> )。 These applications do not actually run vi / Vim;这些应用程序实际上并不运行 vi/Vim; they just offer similar key bindings.他们只是提供类似的键绑定。 The most comprehensive support I've seen is in "vi plugins" for IDEs like Eclipse that offer customization via :map commands.我见过的最全面的支持是 Eclipse 等 IDE 的“vi 插件”,它通过:map命令提供自定义。 However, all of that falls short of the full Vimscript syntax that is available in your ~/.vimrc , and all of the plugins that you may have installed.但是,所有这些都没有达到~/.vimrc可用的完整 Vimscript 语法,以及您可能已安装的所有插件。

As others have already commented, the best you can achieve is reconstructing simple remappings from your ~/.vimrc by defining corresponding zsh key bindings (and keeping them in sync whenever you adapt or add some).正如其他人已经评论过的那样,您可以实现的最佳目标是通过定义相应的 zsh 键绑定(并在您调整或添加一些时保持它们同步)从您的~/.vimrc重建简单的重新映射。

Alternative: Launch external Vim替代方案:启动外部 Vim

Another way to get back your editing efficiency is actually using Vim to edit the command-line.另一种恢复编辑效率的方法实际上是使用 Vim 来编辑命令行。 I don't know about zsh in particular, but Bash offers the fc command for the previous command-line, can edit the current one (in set -o vi mode) via <Esc>v , and also offers a binding to edit-and-execute-command for insert mode, to be configured in ~/.inputrc :我不特别了解 zsh,但 Bash 为前一个命令行提供了fc命令,可以通过<Esc>v编辑当前命令(在set -o vi模式下),并且还提供对edit-and-execute-command的绑定edit-and-execute-command用于插入模式,在~/.inputrc配置:

$if Bash
# Ctrl-F        Invoke the editor on the current command line.
#           Like c_CTRL-F in Vim.
#           Related: fc does the same for the _previous_ command.
Control-f: edit-and-execute-command
$endif

I guess at least some of these options are also available in zsh.我想至少其中一些选项在 zsh 中也可用。 The only downside to them is that the launch and quitting of Vim introduces some delay and additional keys to type, so it's only worthwhile for more complex edits of longer command-lines.它们唯一的缺点是 Vim 的启动和退出引入了一些延迟和额外的键入键,因此仅对更长的命令行进行更复杂的编辑才值得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM