> Is it possible to format a paragraph (i.e.
> justify it) of text or comments while in insert
> mode? The way I do it now is to visually
> highlight the paragraph and then press "g" and
> then "q".
>
> What I'd like is to be able to press Ctrl-q (or
> something) to format the paragraph (and the
> cursor left in the place it was before the
> command, rather than at the start of end or
> something inconvenient).

While keeping the cursor in the same place is a
lot of work, you can easily reformat the current
paragraph with something like

        inoremap <f4> <c-o>gqip

though this has the unfortunate side effect of
placing your cursor at the end of the paragraph.
Alternatively, you can use

        inoremap <f4> <esc>gqip

which will do the same thing, only leave you in
normal mode when done.

To return to where you were typing, you might have
to insert some unique text, reformat things,
and then go back and change that unique text.
Something like

        inoremap <f4> XUNIQX<esc>gqip?XUNIQX<cr>"_cfX

where XUNIQX is some unique text that won't appear
in your document.  However, because it's inserting
that marker into your text, there are some side
effects:

1) the paragraph will be reformatted with this
extra N characters taken into consideration
(thus, shorter is better)

2) your "last inserted text" has this crazy
"XUNIQX" appended, so if you use ^A or ^@ in
insert mode to reinsert the last inserted text,
you may not get quite what you expect.  I don't
know if it also causes problems with the "."
operator (the "repeat the last action" operator)

With those caveats in mind, I hope this helps,

-tim






Reply via email to