【问题标题】:VIM executing current line as VIM commandVIM 执行当前行作为 VIM 命令
【发布时间】:2018-05-05 23:02:34
【问题描述】:

是否可以在 VIM 打开的文本文件中执行 VIM 命令?例如,我们可以有以下文本,我们想在不输入的情况下执行:help w

  Read the text in the help window to find out how the help works.
  Type  CTRL-W CTRL-W   to jump from one window to another.
  Type    :q <ENTER>    to close the help window.

  You can find help on just about any subject, by giving an argument to the
  ":help" command.  Try these (don't forget pressing <ENTER>):

    :help w
    :help c_CTRL-D
    :help insert-index
    :help user-manual

【问题讨论】:

    标签: vim command


    【解决方案1】:

    您可以创建以下映射来执行当前行中定义的命令:

    nnoremap <c-e> :exe getline('.')<cr>
    

    将光标放在:help w 所在的行并输入Ctrl+E 将打开帮助页面。

    【讨论】:

    • 感谢它正在工作;不过,我有一个快速的问题。它与:exec '!'.getline('.') 有何不同? .VIM 命令中的字符串连接运算符,在这些情况下它代表什么?
    • 是的,点 . 用于 Vim 命令行中的字符串连接(参见 :help expr-.)。在命令 (exec!) 之后放置 ! 将返回 No ! allowed,因为只有某些命令接受 !。见:help _!
    • @Vesnog 这会将当前行作为 shell 命令执行。见:help :!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 2012-02-03
    • 2013-03-20
    • 1970-01-01
    相关资源
    最近更新 更多