On Sat, Dec 29, 2001 at 11:10:13PM -0500, Benji Fisher wrote:
> yahoogroups@... wrote:
> > I have some text like this:
> > some text<tab>other text
> > line2 col1<tab>line2 col2
> > ...
> > Basically a 2 <tab> delimited columns of text.
> > I want to take the second column and move it below the first column. Like so:
> > some text
> > line2 col1
> > other text
> > line2 col2
> > I can easily do this with visual block mode yank and put, but I want to do it
> > in a script/macro, etc.
> > The ex command 'move' operates on entire lines only.
> > I can get the second part of each line into a \(..\) variable, but how to
> > combine them all together and paste them at the end.
> > Any help much appreciated.
> > Thanks
> How about something like
> :g/\t/execute "normal f\<tab>xD" | $put
This is very nice. The problem for me is that I probably
won't remember this on the rare occasions when I have to
do something this complicated. The way I would do it uses
many more commands but only about 4 more keystrokes and
requires virtually no thinking so it winds up being much
faster (for me). If this is something you have to do to
multiple files then just use "q" to record your keystrokes
into a named register and then execute the register on each
What I would do is duplicate all the lines and then in
the first half remove column 2 and in the second half
remove column 1.
FWIW, here are the keystrokes.
ggyGGmbp:1,'bs/ .*//^M:'b+1,$s/.* //^M
gg " go to first line
yG " yank all lines
G " go to last line
mb " mark with b
p " put yanked lines
:1,'bs/ .*//^M " delete from tab to
" end of line in first
" half of file
:'b+1,$s/.* //^M " delete from start of
" line up to and
" including the tab in
" the second half