Piping a rectangular area of ​​text from vim to an external program?

I am editing a large text array in vim and I want to compute it in one column.

A simplified example of an edited file:

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

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

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

When I select the rectangle in column 4 using v.motion and! perl calc.pl all lines are transmitted through channels in calc.pl, and not just in a rectangle.

The work around will be to: cut out the rectangle for the temporary file, run calc.pl in the temp file, and then read the output as a rectangle.

Is there a direct solution in vim, without for cropping / wrapping / pasting?

+7
vim
source share
1 answer

You can try vis plugin 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 the linear selection or alternative visual range selection and press nr

In the zero buffer, just save it and the changes will be copied to the source file. This is a very simple help. You should probably read the help provided by the plugin. See: h Narrow reg.

+3
source share

All Articles