vote up 1 vote down
star

I'm getting back in touch with my inner (g)vim due to an unscheduled MacBook mother(board) of a meltdown (my emergency backup Linux box won't run TextMate). All told I'm happy with vim's efficiency and power, but I'm mortified at how hard it is to get the kind of word wrap that even stupid HTML textareas achieve with no apparent effort.

Consider the text

Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis nullam.

By default, with an 80-character width vim displays this as

Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis nu
llam.

This wrapping doesn't care about whitespace, so sometimes it just slices words into pieces (nullam in this case). Of course, you can turn on word wrap, and get this:

Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis
nullam.

The problem is that vim inserts a newline at the linebreak, which I most emphatically do not want. In other words, I want the text to display exactly as vim displays it with word wrap turned on, but without inserting a newline. (This way it can be pasted into HTML textareas and email programs, among other places.)

Web searches have yielded nothing of use, despite diligent effort; I hope StackOverflow can succeed where my Google-fu has failed.

flag
I don't know that this is possible, because vim has to line things up somehow... Even if it doesn't put the newline in itself, your console app most likely will. Gvim may be able to... I don't know. If you use vim's graphical mode, again it might be possible, I don't know. – monoxide Jan 22 at 1:15
add comment

3 Answers

vote up 5 vote down

To turn on word wrapping:

:set wrap
:set linebreak

To copy & paste the original text and not any padding works for gvim. For vim in an xterm though, it copies the space padding at EOL (though not the newline). I thought this should work but it doesn't:

:set mouse=a
link|flag
add comment
vote up 0 vote down

Vim's wordwrapping does not insert newlines. Your terminal application is doing that. With vim running in OS X's Terminal.app, what you desire works just fine (copied text pastes without newlines).

link|flag
add comment
vote up 0 vote down

If vim is adding in newline characters (not just wrapping the text) then you probably have textwidth turned on ...

:set textwidth=0
link|flag
add comment

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.

Stack Overflow works best with JavaScript enabled