gvim:将视觉选择的文本传递到命令行 [英] gvim: passing the visually-selected text to the command line

查看:137
本文介绍了gvim:将视觉选择的文本传递到命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gvim存储我将执行的命令的配方,取决于输出。目前,我选择gvim中的文本并将命令粘贴到终端控制台中,但我敢打赌有一种方法,我可以将视觉选择的范围传递到命令行执行。

I use gvim to store recipes of commands that I will execute, depending on output. Currently, I select the text in gvim and paste the commands into a terminal console, but I bet there's a way I can pass the visually selected range into a command-line for execution.

推荐答案

假设你是指Vim命令行:



(如果你是指OS命令行, / p>

对于部分行(即没有行尾),您可以这样做:

Assuming you mean the Vim command line:

(if you mean the OS command line, see below).

For parts of lines (i.e. no end of line character), you could do something like this:

其中< C-R> Ctrl + R y 'yanks'所选文本,进入命令模式,< C -R>(最后拖放的文本)寄存器的内容拉到命令行上,并且< ENTER> ;

" Visually select lines, then: y:<C-R>"<ENTER>

如果你想做行式的东西,它有点复杂(因为命令行不喜欢 ^ M 在命令中)。我推荐这样在你的vimrc:

where <C-R> means press Ctrl+R. The y 'yanks' the selected text, the : enters command mode, <C-R>" pulls the contents of the " (last yanked text) register onto the command line and <ENTER> (obviously) runs the command.

If you want to do line-wise stuff, it's a bit more complicated (as the command line doesn't like ^Ms in the command).  I'd recommend something like this in your vimrc:

选择行(重新启动vim后),然后按,r

function! RunCommands() exe getline('.') endfunction command -range RunCommands <line1>,<line2>call RunCommands() vmap ,r :RunCommands<CR>

您可能会发现有用的另一种方法是复制所需的行, $ c> q:打开命令行窗口,将所需的行粘贴到那里,然后将光标移动到所需的行上,并按 ENTER 。这具有可以在按 ENTER 之前编辑命令的优点。

Select the lines (after restarting vim) and press ,r.

使用上面列出的函数,但不是:

Another way that you may find useful is to copy the lines you want, hit q: to open the command line window and paste the lines you want into there and then move the cursor over the line you want and press ENTER. This has the advantage that you can edit the command before pressing ENTER. It'll only run one command at a time.

Use the function I listed above, but instead of:

使用

call system(getline('.'))

或,如果您想查看结果: / p>

or, if you want to see the result:

echo system(getline('.'))

echomsg system(getline('.'))



有关详情:



For more information:

:help :echo
:help :echomsg
:help :messages

:help :vmap
:help :command-range
:help :command
:help :function

:help c_CTRL-R
:help :exe
:help getline()
:help system()

这篇关于gvim:将视觉选择的文本传递到命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆