2

我知道如何让 shell 命令在 vim 中运行,在命令模式下,输入

:!shell_command

现在,我在 Vim 中打开的文件的第 16 行有一个命令。

cp /home/debian/Downloads/rar/rar /usr/local/bin

截屏

如何在 vim 中运行这个命令,而不用输入所有命令?

当我:!打开 ex 命令行然后使用<C-r>"时,我得到了这个:

ls /tmp^m

截屏

我必须^m用退格键擦除,然后按回车键,对吗?我可以不让 ^M 显示吗?

4

2 回答 2

2

要在光标所在的行上运行命令,可以将行拉到剪贴板中。类型:!以打开 ex 命令行,然后使用<C-r>"将命令粘贴到命令行。

因此,将光标放在线型上并按 Enter。

yy:!<C-r>"

看看:h <c-r>

CTRL-R {0-9a-z"%#:-=.}                  *c_CTRL-R* *c_<C-R>*
        Insert the contents of a numbered or named register.  Between
        typing CTRL-R and the second character '"' will be displayed
        to indicate that you are expected to enter the name of a
        register.
        The text is inserted as if you typed it, but mappings and
        abbreviations are not used.  Command-line completion through
        'wildchar' is not triggered though.  And characters that end
        the command line are inserted literally (<Esc>, <CR>, <NL>,
        <C-C>).  A <BS> or CTRL-W could still end the command line
        though, and remaining characters will then be interpreted in
        another mode, which might not be what you intended.
        Special registers
于 2013-06-01T02:45:16.357 回答
1

简单的回答:

:exec '!'.getline('.')
于 2013-06-01T14:59:56.640 回答