简体   繁体   English

无法在Vim的可视模式下从外部运行许多命令

[英]Unable to run many Commands in Vim's visual mode externally

I have the following commands in a README file: 我在自述文件中有以下命令:

./Setup ...
./Setup ...
./Setup ...

I want to run them by selecting the codes visually and then running them. 我想通过可视地选择代码然后运行它们来运行它们。

I run unsuccessfully 我跑不成功

: '<,'> !

Current code after Luc's comments in his answer Luc在回答中发表评论后的当前代码

My code in .vimrc which I have not managed to get to work: 我在.vimrc中的代码未能成功上班:

vmap <silent> <leader>v y:exe '!'.join(split(@", "\n"),';')<cr>

I am trying to make make a keyboard combination for 我正在尝试制作一个键盘组合

v yy

How can you get the above command work , such that you can run file's commands directly in Vim? 如何获得上述命令 ,从而可以直接在Vim中运行文件的命令?

  • First select your text, 首先选择您的文字,
  • then copy it with y , 然后用y复制
  • and finally, you can execute: 最后,您可以执行:

    :exe '!'.join(split(@", "\\n"),';') :exe'!'。join(split(@“,” \\ n“),';')

This might be oversimplifying things, but why not just do: 这可能使事情简化了,但是为什么不做:

:e README
:%!bash

This filters the current file through bash, executing each line as a command. 这将通过bash过滤当前文件,并作为命令执行每一行。 The current buffer is replaced by the output of running all of the commands in the file. 当前缓冲区被运行文件中所有命令的输出所代替。

It might be helpful to do a :w RESULTS to save it as another file first, so you don't accidentally overwrite the original: 首先执行:w RESULTS将其另存为另一个文件可能会有所帮助,因此您不会意外覆盖原始文件:

:e README
:w RESULTS
:%!bash

You had said you wanted to do this with a visual selection, which would work just as well After you select what you want to execute, type : . 您曾经说过,您想通过视觉选择来做到这一点,这同样适用。选择完要执行的操作后,输入: '<,'> will automatically be prepended to the current command. '<,'>将自动添加到当前命令之前。 '< is the mark of the beginning of the current selection, whereas '> is the mark at the end of the current selection. '<是当前选择的开始标记,而'>是当前选择的结束标记。 You can just run just those commands you have selected just like above: 您可以只运行选择的命令,就像上面一样:

:'<,'>!bash

This will replace just the selected commands with the output of executing those commands. 这将仅将所选命令替换为执行这些命令的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM