在 Vim 的命令行模式下使用普通模式运动

问题描述:

是否可以在命令行模式下进行模态编辑?

Is modal editing possible in command-line mode?

一些例子:

  • 写完!ls ~/foo/bar我要db删除bar
  • 我执行了上面的命令,现在我想将 ls 更改为 mv 并跳回 $
  • After writing !ls ~/foo/bar I want to db to delete bar
  • I executed the above command and now I want to change ls to mv and jump back to $

默认情况下,您可以在 Vim 上按 Control + f(或查看 set cedit)command-line,它打开命令行窗口,您可以在其中使用普通模式 Vim 编辑键编辑命令.Enter 将运行命令或 Control + c 将返回标准命令行.

By default you can press Control + f (or otherwise see set cedit) when on the Vim command-line, which opens the command-line window where you can edit the command using normal-mode Vim editing keys. Enter will run the command or Control + c will return you to the standard command-line.

因此,在您的具体示例中,您可以在 Vim 命令行上按 Control + f 然后按 db ,它会执行您想要的操作.

So in your specific example, you could press Control + f on the Vim command-line then db and it would do what you want.

当我必须执行更复杂的编辑命令时,我会使用上述方法,因为我对 Vim 编辑键比对替代方法更熟悉.我还发现普通模式的 vim 键更强大.

When I have to do more sophisticated editing commands I use the above approach because I'm more familiar with Vim editing keys than I am with the alternatives. I also find the normal-mode vim keys more powerful.

更多信息见:help c_ctrl-f.