Tuesday, August 25, 2009

Re: inserting a column of &s into a text table for latex

> I often have a text-table, which I need to format for latex by
> separating the column values with "&"s. Doing this by hand is really
> laborious and very slow. Is there a better way to do it?
>
> I know you can use | for going to a particular column but how could I
> use this to, for example insert a column of &'s from line 5,20 at column 12?
>
> Ideally I'd like to turn:
>
> a b c d
>
> (into)
>
> a & b & c & d

What separates your initial data? Tabs? Whitespace? Word
boundaries?

And where does the extra space on either side of the added-"&"
characters come from?

You could use any of

:'<,'>s/\s\+/&\&&/g
:'<,'>s/\t/&\&&/g
:'<,'>s/\t/ \& /g
:'<,'>s/\>\W*\</ \& /g

Tweak to taste.

-tim

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

No comments: