Piping rectangle region of text from vim to an external program?

I am editing a large text array in vim, and I want to compute on one sub-column of it.

Simplified example of edited file:

name value name   saturation 
red  5     green  2
blue 7     yellow 7 
other text

I want to pipe column 4 through an external program calc.pl, calc.pl replaces numbers with new numbers in the input, for example:

 name value name   saturation
 red  5     green  2.4
 blue 7     yellow 7.14
 other text

When I select rectangle in column 4, using v.motion, and !perl calc.pl the whole lines gets piped to calc.pl, not just the rectangle.

A work around would be to: cut rectangle to temp file, run calc.pl on temp file, and then read output as rectangle.

Is there a straight forward solution in vim, without having to cut/shell/paste?


You might try the vis plugin by Charles Campbell

Use ctrl-v to select a column, then apply an external filter to that column. ctrl-v ..move.. :B !sort

Another plugin that might work for you is NrrwRgn by Christian Brabandt.

Use :NarrowRegion to narrow a line based selection or alternatively visually select a range and press nr

In the scratch buffer simply save it and the changes will be copied into the original file. This is only a very simple help. You should probably read the help, that is provided with the plugin. See :h NarrowRegion

链接地址: http://www.djcxy.com/p/3186.html

上一篇: 如何在Ruby on Rails网页中嵌入一个linux bash终端?

下一篇: 从vim到外部程序的文本的矩形区域?