multi column

0 views
Skip to first unread message

bill lam

unread,
Dec 15, 2008, 9:28:20 AM12/15/08
to vim_use
I have to print on paper something like this,

111111111
222222222
333333333
444444444
555555555
666666666
777777777
......
(very long list)

To be environmental friendly, I would like to reformat it as

111111111 222222222 333333333
444444444 555555555 666666666
777777777 ............

Command J should be useful, but I want to know how to automate it to
process to whole file.

Thanks in advance.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩172 祖詠 望薊門
燕臺一去客心驚 簫鼓喧喧漢將營 萬里寒光生積雪 三邊曙色動危旌
沙場烽火侵胡月 海畔雲山擁薊城 少小雖非投筆吏 論功還欲請長纓

Frans Grotepass

unread,
Dec 15, 2008, 9:30:44 AM12/15/08
to vim...@googlegroups.com
bill lam wrote:
> I have to print on paper something like this,
>
> 111111111
> 222222222
> 333333333
> 444444444
> 555555555
> 666666666
> 777777777
> ......
> (very long list)
>
> To be environmental friendly, I would like to reformat it as
>
> 111111111 222222222 333333333
> 444444444 555555555 666666666
> 777777777 ............
>
> Command J should be useful, but I want to know how to automate it to
> process to whole file.
>
> Thanks in advance.
>
Set column width, Highlight all the text and use gq to reformat the text.

bill lam

unread,
Dec 15, 2008, 9:37:54 AM12/15/08
to vim...@googlegroups.com
On Mon, 15 Dec 2008, Frans Grotepass wrote:
> Set column width, Highlight all the text and use gq to reformat the text.

Pardon, how to set column width?

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

唐詩239 劉長卿 送上人
孤雲將野鶴 豈向人間住 莫買沃洲山 時人已知處

Jürgen Krämer

unread,
Dec 15, 2008, 9:40:09 AM12/15/08
to vim...@googlegroups.com

Hi,

bill lam wrote:
> I have to print on paper something like this,
>
> 111111111
> 222222222
> 333333333
> 444444444
> 555555555
> 666666666
> 777777777
> ......
> (very long list)
>
> To be environmental friendly, I would like to reformat it as
>
> 111111111 222222222 333333333
> 444444444 555555555 666666666
> 777777777 ............
>
> Command J should be useful, but I want to know how to automate it to
> process to whole file.

if you want to have exactly 3 columns in each line you can use

:g/^/normal 3J

If the original line count is not a multiple of 3 you will have to join
the last lines manually

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

Frans Grotepass

unread,
Dec 15, 2008, 9:40:17 AM12/15/08
to vim...@googlegroups.com
bill lam wrote:
> On Mon, 15 Dec 2008, Frans Grotepass wrote:
>> Set column width, Highlight all the text and use gq to reformat the text.
>
> Pardon, how to set column width?
>
set textwidth=bla

Tim Chase

unread,
Dec 15, 2008, 9:51:47 AM12/15/08
to vim...@googlegroups.com
> if you want to have exactly 3 columns in each line you can use
>
> :g/^/normal 3J

Or you can skip the normal command:

:g/^/j3

I use this all the time :)

-tim

bill lam

unread,
Dec 15, 2008, 10:08:41 AM12/15/08
to vim...@googlegroups.com
On Mon, 15 Dec 2008, Tim Chase wrote:
>
> > if you want to have exactly 3 columns in each line you can use
> >
> > :g/^/normal 3J
>
> Or you can skip the normal command:
>
> :g/^/j3

Thank you all for help. I learn three different ways :)

I found a caveat when using gp is that needs set formatoptions-=n to
work so that for my particular case :g is easier to use.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

唐詩295 杜牧 贈別二首之一
娉娉嫋嫋十三餘 豆蔻梢頭二月初 春風十里揚州路 卷上珠簾總不如

Tim Chase

unread,
Dec 15, 2008, 10:27:17 AM12/15/08
to vim...@googlegroups.com
>>> if you want to have exactly 3 columns in each line you can use
>>>
>>> :g/^/normal 3J
>> Or you can skip the normal command:
>>
>> :g/^/j3
>
> Thank you all for help. I learn three different ways :)
>
> I found a caveat when using gp is that needs set formatoptions-=n to
> work so that for my particular case :g is easier to use.

The two join methods ("norm 3J" and "j3") are for literal "I want
to join 3 lines together". The "gq" method is a generic "join
lines to fill the width I specify" which may be more or less than
3 lines joined together. Both have their place, depending on
which type of behavior you want.

As a side note, if you don't want Vim to automatically add spaces
to your joined lines, you can either use "norm 3gJ" or "j!3"

-tim


bill lam

unread,
Dec 15, 2008, 10:38:37 AM12/15/08
to vim...@googlegroups.com
On Mon, 15 Dec 2008, Tim Chase wrote:
> As a side note, if you don't want Vim to automatically add spaces
> to your joined lines, you can either use "norm 3gJ" or "j!3"

Thank you for this note, I knew gJ but j! is new to me.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

唐詩143 劉脊虛 闕題
道由白雲盡 春與青溪長 時有落花至 遠隋流水香
閑門向山路 深柳讀書堂 幽映每白日 清輝照衣裳

fritzophrenic

unread,
Dec 15, 2008, 6:20:10 PM12/15/08
to vim_use
And, from a recently added tip (http://vim.wikia.com/wiki/
Recursive_repeats_for_quick_editing_of_structured_text), yet another
fun method:

qaq (clear register "a")
qa (start recording to register "a")
3J (join 3 lines)
j (move the cursor to the next line)
@a (execute register "a" - currently empty, but once we're done this
will recursively run the macro)
q (stop recording)
@a (run the recursive macro to join the lines in the rest of the
file)

This one is a bit longer, but really simple and kind of fun. It is
admittedly a bit wasteful for in terms of keystrokes for such a simple
task, but a nice tool to have nonetheless.

Ted Pavlic

unread,
Dec 15, 2008, 7:09:47 PM12/15/08
to vim_use
NOTE: Assuming that you're on a machine with the "rs" (reshape) command,
you can position your cursor on the first line and do:

!Grs 3

and you'll get exactly what you want. That's quick and easy (but it
requires rs, and for some reason many distros don't include rs
anymore... why?).

--Ted

> 111111111
> 222222222
> 333333333
> 444444444
> 555555555
> 666666666
> 777777777
> ......
> (very long list)
>
> To be environmental friendly, I would like to reformat it as
>
> 111111111 222222222 333333333
> 444444444 555555555 666666666
> 777777777 ............


--
Ted Pavlic <t...@tedpavlic.com>

Tim Chase

unread,
Dec 15, 2008, 7:48:01 PM12/15/08
to vim...@googlegroups.com
Ted Pavlic wrote:
> NOTE: Assuming that you're on a machine with the "rs" (reshape) command,
> you can position your cursor on the first line and do:
>
> !Grs 3
>
> and you'll get exactly what you want. That's quick and easy (but it
> requires rs, and for some reason many distros don't include rs
> anymore... why?).

Sounds like you can get exactly the same thing using the more
standard "pr" command:

:%!pr -3 -t -a

that's "-3" columns without header/footer information ("-t") and
done across ("-a") rather than columnarly. I use "pr -4 -t"
pretty regularly to columnize stuff while working at the
command-line, so it's become second-nature (so much so that I had
to double-check that the "-t" really did suppress headers/footers).

-tim

Reply all
Reply to author
Forward
0 new messages