我知道如何在vim中运行shell命令,在命令模式下输入
:!shell_command
现在,我在Vim打开的文件的第16行有一个命令。
cp /home/debian/Downloads/rar/rar /usr/local/bin
如何在vim中运行此命令而不键入所有命令?
当我点击:!
打开ex命令行然后使用<C-r>"
时,我明白了:
ls /tmp^m
我必须用退格键擦除^m
,然后按回车键,是吗?
我不能让^ M出现吗?
答案 0 :(得分:2)
要在光标所在的行上运行该命令,可以将该行拉入剪贴板。键入:!
以打开ex命令行,然后使用<C-r>"
将命令粘贴到命令行。
所以将光标放在线型上并点击回车。
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
答案 1 :(得分:1)
简单回答:
:exec '!'.getline('.')