On 07/12/06, Karsten Gerloff <[EMAIL PROTECTED]> wrote:
On Wed, Dec 06, 2006 at 02:32:12PM +0000, A. S. Budden wrote:
> On 06/12/06, Karsten Gerloff <[EMAIL PROTECTED]> wrote:
> >Hi,
> >
> >I'm currently writing a lot of text in vim that will later need to
> >transfer to a word processor (OpenOffice 2.0 in this case).
> >
> >Since it makes reading easier, I want to make lines wrap at 66
> >chars; this has long worked fine with
> >
> >        set textwidth=66
> >
> >But this inserts hard line breaks (<EOL>), which I don't want to
> >show up later in the word processor. No luck at vim.org. So I
> >tried the vim FAQ at
> >
> >        http://vimdoc.sourceforge.net/vimfaq.html
> >
> >and it told me to put the following into my .vimrc:
> >
> >    :set wrap
> >    :set linebreak
> >    :set textwidth=0
> >    :set showbreak=>>>
> >
> >which works nicely as far as the EOLs are concerned. But the lines
> >still run over the whole width of the screen. Setting textwidth=66
> >re-introduces the unwanted EOLs.
> >
> >Any hints?
>
> I find that the easiest way is to set tw to whatever you want it to
> be, write the text and then (just before pasting into OpenOffice):
>
> :set tw=10000
> gggqG
> gg"+G
>
> To reformat the text with long lines.  Assuming formatoptions is set
> to something sensible, this works a treat.

It does indeed! Thanks for this great hint -- especially useful
since I already have large amounts of text I need to move into
OpenOffice.

To make it still more convenient, I turned it into a macro and
mapped it to F4:

        map <F4> :set tw=10000<CR>gggqGgg"+G

The only thing I haven't managed yet is to set textwidth back to
66 after that. Simply appending
        :set tw=66<CR>

I haven't tried it, but I imagine you'd need:

map <F4> :set tw=10000<CR>gggqGgg"+G:set tw=66<CR>gggqG

see:

:he gg
:he gq
:he G

to ensure that the reformatting is done again.  You could make it even
more clever by adding something like mq on the start and `q on the
end: it should then return the cursor to it's initial position.

:he m
:he `

Good luck,

Al

Reply via email to