VIM执行当前行作为VIM命令

3

在由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
1个回答

5
您可以创建以下地图来执行当前行中定义的命令:
nnoremap <c-e> :exe getline('.')<cr>

将光标放在含有:help w的行上,然后按下 Ctrl+E ,即可打开帮助页面。


谢谢,它正在工作;不过我有一个快速问题。它与:exec '!'.getline('.')有什么不同?在VIM命令中,**.**是字符串连接运算符,在这些情况下它代表什么? - Vesnog
是的,在Vim的命令行中,点号“.”用于字符串连接(参见:help expr-.)。在命令后面加上一个“!”(exec!)会返回“不允许使用!”因为只有特定的命令接受“!”。请参见:help _! - builder-7000
1
@Vesnog 这将执行当前行作为shell命令。请参阅:help:! - JoL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接