3 ms·
Ask HN: basic word wrap in vim
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.
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 Hacker News can succeed where my Google-fu has failed.
- cschneid 18y agoI'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 18y agoI posted the same question at StackOverflow, which also yielded some useful advice: http://stackoverflow.com/questions/467739/how-do-you-get-vim-to-display-wrapped-lines-without-inserting-newlines http://stackoverflow.com/questions/467739/how-do-you-get-vim... Basically, my terminal app was at fault, not vim. Switching from xterm to gnome-terminal fixed the problem.