Say you have the following text:
> someone said
> > someone else said
> > > long quoted message
> > blah blah
> blah
Place the cursor on the first line and do `gqip'. I often use this combo to conveniently reformat paragraphs.
Saturday, January 10, 2009
Subscribe to:
Post Comments (Atom)
13 comments:
Didn't work with your posted example.
I got gqip command not found error.
(the example worked for me.)
I know gq"movement" will re-justify text for me, what's the breakdown of what gqip command is saying?
I don't understand. What should happens?
This example does nothing for me:
> someone said
> > someone else said
> > > long quoted message
> > blah blah
> blah
ESC gqip
The command works, but the example text is misleading: You really have to have a longer quotes message, i.e. several lines. Then 'gqip' transforms
> someone said
> > someone else said
> > someone else said
> > someone else said
> > > long quoted message
> > > long quoted message
> > > long quoted message
> > > long quoted message
> > someone else said
> > someone else said
> > someone else said
> blah
(12 lines)
into
> someone said
> > someone else said someone else said someone else said
> > > long quoted message long quoted message long quoted message long quoted
> > > message
> > someone else said someone else said someone else said
> blah
(6 lines of text in vim; additional linebreaks inserted by blogger.com)
Still interested in why the command does that, though.
AHA
> one
>> two
>> two
>> two
>>> three
>>> three
>>> three
>> two
>> two
> one
> one
ESC gqip
> one
>> two two two
>>> three three three
>> two two
> one one
Nice, thanks
I use gqap ("a paragraph") instead of gqip, as this also moves the cursor down to the blank line after the paragraph. I can then use the dot to repeat the command, easily reformatting a series of paragraphs.
For a more powerful paragraph formatter, check-out 'par':
- http://www.nicemice.net/par/par-doc.var
- http://vim.wikia.com/wiki/Par_text_reformatter
None of the examples make any sense to me. What is the benefit of this?
Thanks.
For those of you that are confused. The command given in the tip is meant to be typed in normal mode and is not an ex (colon) command. What it's intended to do is invoke gq (format motion) on ip (inner paragraph). Vim provides a number of text-object motions, which allow a command to be applied to a given text entity. If you're not familiar with text-objects, I highly recommend doing a :help text-objects.
But the result of the command is a single paragraph as if you had written jagged text such as:
> a
> > b
> > b
> > > c
which becomes:
> a > > b > > b > > > c
That is, the text is simply rejustified, and nothing magic happens due to the presence or number of greater-than '>' character.
Also note that "gq" is the reformat action. "ip" simply specifies what to format.
You could also do a mouse selection and type "gq" (in normal mode) to reformat that.
Finally, note that "gq" works on more than just email quoted text. I often use it for reformatting source code comments. For example:
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
// lorem ipsum
... select all of the above and hit "gq" gives you ...
// lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
// lorem ipsum lorem ipsum lorem ipsum
Post a Comment