

Ask HN: basic word wrap in vim - mhartl

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.<p>Consider the text<p><pre><code>  Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis nullam.
</code></pre>
By default, with an 80-character width vim displays this as<p><pre><code>  Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis nu
  llam.
</code></pre>
Of course, you can turn on word wrap, and get this:<p><pre><code>  Etiam ornare mollis tortor. Suspendisse sed neque. Nullam in elit. Cum sociis
  nullam.
</code></pre>
The problem is that vim inserts a <i>newline</i> at the linebreak, which I most emphatically do <i>not</i> want. In other words, I want the text to display exactly as vim displays it with word wrap turned on, but <i>without</i> inserting a newline. (This way it can be pasted into HTML textareas and email programs, among other places.)<p>Web searches have yielded nothing of use, despite diligent effort; I hope Hacker News can succeed where my Google-fu has failed.
======
cschneid
I'm pretty sure these two lines do what you want. It keeps it as one physical
line, but wraps at word boundaries instead of at the exact character when
doing logical wrapping.

    
    
        " Break lines intelligently when wrapping
        set linebreak
        set display+=lastline

------
mhartl
I posted the same question at StackOverflow, which also yielded some useful
advice: [http://stackoverflow.com/questions/467739/how-do-you-get-
vim...](http://stackoverflow.com/questions/467739/how-do-you-get-vim-to-
display-wrapped-lines-without-inserting-newlines)

Basically, my terminal app was at fault, not vim. Switching from xterm to
gnome-terminal fixed the problem.

