vim: how to gq a visual block?

81 views
Skip to first unread message

ping

unread,
Oct 3, 2012, 3:22:29 PM10/3/12
to vim...@googlegroups.com
as in subject, suppose we have a gq'ed block already:

0 1 2
12345678901234567890123456789
lsdjflsdlksjfsdlfjsld 123
lsjfsdfksdjfldsfsdlsl 456
lsjdlfsdlfjsalfslfsjs 789


now I want to re-format the character blocks , for example, extend them
from current length 21 to some other length, say, 25, or squeeze to 18,
without affacting the "digit blocks".

is it possible at all with any command or plugins?

ping

unread,
Oct 4, 2012, 11:29:40 AM10/4/12
to vim...@googlegroups.com
guys,
any better solution on this?
b.t.w currently I'm working around with 3 steps:

1) visual selecting right (digit) block and remove them
2) gq to re-format with a new 'tw' on the left (letter) block
3) add the removed right (digit) block back on the right

Charles Campbell

unread,
Oct 4, 2012, 12:04:56 PM10/4/12
to vim...@googlegroups.com
Not a perfect solution, because the righthand side digits may move (as a
column) a bit, but:

* set tw=(new value here)
* ctrl-v block of characters
* :B norm! gqap

That also assumes that the text within is a paragraph, too.

The ":B" is supported by my vis plugin:

You can get vis.vim from:

http://vim.sourceforge.net/scripts/script.php?script_id=1195 (stable)
http://www.drchip.org/astronaut/vim/index.html#VIS (cutting
edge)

Regards,
C Campbell

ping

unread,
Oct 4, 2012, 2:04:49 PM10/4/12
to vim...@googlegroups.com, Charles Campbell
thanks! I was just thinking to look at your vim website for some help...

but it looks not always work well, sometime it even change the text
sequences, is there any internal "sort" in the process flows?


the example text:

LUCY CRAFT: Japan and China 'normal
40 years ago and i n terms of econom
relations, are lit erally 'joined'
their cross-border trade reaching $
last year. Their p olitical relation
meanwhile, has bee n a constant sour
And yet while anti -Japanese 'hostil
has 'flared up' re peatedly over the
the recent widespr ead 'fury' target
government offices and businesses o
week, 'blindsided' many here - like
72-year-old 'green grocer' Hiroko Iw



I set tw=50, c-v selected the left block, move cursor to the bottom CHAR
'n', then :B normal! gqap
and I got this:



Their p meanwhile, has and China 'normal n terms
bee And yet while anti of econom erally 'joined'
has 'flared up' re the trade reaching $ olitical
recent widespr relation n a constant sour
government offices week, -Japanese 'hostil peatedly
'blindsided' 72-year-old over the ead 'fury' target
'green and businesses o many here
- like grocer' Hiroko Iw
LUCY CRAFT: Japan 40
years ago and i
relations, are lit their
cross-border last year.


so the text block that I applied the gqap just got indented, making them
looks like 50 textwidth, but not re-wrap the whole block?

ping

unread,
Oct 4, 2012, 2:20:24 PM10/4/12
to vim...@googlegroups.com, Charles Campbell
oh I got it, I have to test it with these text, making it "within a
parag"...

LUCY CRAFT: Japan and China 'normalized ties'
40 years ago and in terms of economic
relations, are literally 'jo ined' 'at the hip';
their cross-border trade rea ching $340 billion
last year. Their political r elationship,
meanwhile, has been a consta nt source of 'tension'
And yet while anti-Japanese 'hostility' in China
has 'flared up' repeatedly o ver the years,
the recent widespread 'fury' targeted at Japanese
<\n> <---- must have a new line here


it work!

on the other hand, sometime it doesn't work well...

see I have this texts:

LUCY CRAFT: Japan and China 'normalized ties' aaaaaaaaaaa
40 years ago and in terms of economic aaaaaaaaaaa
relations, are literally 'joined' 'at the hip'; aaaaaaaaaaa
their cross-border trade reaching $340 billion aaaaaaaaaaa
last year. Their political relationship, aaaaaaaaaaa
meanwhile, has been a constant source of 'tension'. aaaaaaaaaaa
And yet while anti-Japanese 'hostility' in China aaaaaaaaaaa
has 'flared up' repeatedly over the years, aaaaaaaaaaa
the recent widespread 'fury' targeted at Japanese aaaaaaaaaaa
government offices and businesses over the last aaaaaaaaaaa
week, 'blindsided' many here - like aaaaaaaaaaa
72-year-old 'greengrocer' Hiroko Iwasaki. aaaaaaaaaaa


now I set tw=60 and a :B normal! gqap turned it into:

LUCY CRAFT: Japan and China 'normalized ties' 40 aaaaaaaaaaa
years ago and in terms of economic relations, aaaaaaaaaaa
are literally 'joined' 'at the hip'; their aaaaaaaaaaa
cross-border trade reaching $340 billion last year. aaaaaaaaaaa
Their political relationship, meanwhile, has aaaaaaaaaaa
been a constant source of 'tension'. And yet while aaaaaaaaaaa
anti-Japanese 'hostility' in China has 'flared up' aaaaaaaaaaa
repeatedly over the years, the recent aaaaaaaaaaa
widespread 'fury' targeted at Japanese government offices aaaaaaaaaaa
and businesses over the last week, 'blindsided' many
aaaaaaaaaaa
here - like 72-year-old 'greengrocer' aaaaaaaaaaa
Hiroko Iwasaki. aaaaaaaaaaa

now look at:
'normalized ties' 40
economic relations,
hip'; their
....


why there are many gaps between the last word of each line to the
previous word?


thanks!

ping

unread,
Oct 4, 2012, 3:04:20 PM10/4/12
to vim...@googlegroups.com, Charles Campbell
ok that is the 'old' version in www.vim.org

I tested with the cutting version and it looks better.

I'll try using it at my work and feedback issues if I have.
thanks!

regards
ping
Reply all
Reply to author
Forward
0 new messages