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 y开发者_开发百科ellow 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
精彩评论