Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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?

like image 885
mosh Avatar asked Oct 14 '10 18:10

mosh


1 Answers

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

like image 116
Peter Rincker Avatar answered Nov 09 '22 02:11

Peter Rincker