up vote 9 down vote favorite
2
share [g+] share [fb]

Vim/gvim will wrap long lines like this:

000000000000000000000000000000000000|
00000000000000                      |
    11111111111111111111111111111111|
111111111111111111                  |
    22222222222222222222222222222222|
222222222222222222                  |
        3333333333333333333333333333|
3333333333333333333333              |

Is there a way to get Vim to wrap those lines like this instead:

000000000000000000000000000000000000|
 00000000000000                     |
    11111111111111111111111111111111|
     111111111111111111             |
    22222222222222222222222222222222|
     222222222222222222             |
        3333333333333333333333333333|
         3333333333333333333333     |

I want the wrapped line to start a little past the indent of where that line started. (Just to be clear, I'm talking about wrap, not textwidth.)

I want the indentation of the line to be considered in the wrapping of that line so that the code structure isn't hidden by wrapped lines.

link|improve this question
feedback

2 Answers

In your .vimrc:

set wrap               " soft-wrap lines

" requires +linebreak compile-time option (not in the 'tiny' and 'small' builds); check your :version
set showbreak=----->   " prefix for soft-wrapped lines (no actual line break character)
"set linebreak          " soft-wrap lines only at certain characters (see :help breakat)

" If you like line numbers, you may want this instead:
"set number
"set showbreak=------>\  " line up soft-wrap prefix with the line numbers
"set cpoptions+=n        " start soft-wrap lines (and any prefix) in the line-number area

Or just type :set showbreak=-----> in any session.

For reference, my research trail (Vim 6.2): :help 'wrap' -> :help 'linebreak' -> ( :help 'showbreak' -> :help 'cpoptions', :help 'breakat')

link|improve this answer
Very cool, but not really what I meant. You took it a bit more literally than I intended, so my fault there. I'll see if I can clarify. – retracile Nov 20 '09 at 15:03
feedback
up vote 5 down vote accepted

So apparently this requires a patch to Vim. There is a patch by Vaclav Smilauer from back in 2007. I updated the patch to work with Vim 7.2.148 from Fedora 11. But it does seem to do the job.

link|improve this answer
+1 just for contributing to the project – whitequark Aug 14 '10 at 3:32
As Fedora releases updates to Vim, I'm updating the patch. See retracile.net/wiki/VimBreakIndent for the latest. – retracile Nov 23 '10 at 4:16
Bonus points to someone who can explain how to get this to work with MacVim. – donut Mar 29 '11 at 20:01
feedback

Your Answer

 
or
required, but never shown

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