Take the 2-minute tour ×

Does anyone know of a way to get vim to wrap long lines of text such that the position of the wrapped text is based on the indentation of the current line? I don't want to reformat my code, just for it to be displayed prettily.

For instance, if I set my settings so that the line:

print 'ProcessorError(%r, %r, %r)' % (self.file, self.index, self.message)

is displayed when wrapped as:


then if I write a block of code like this:

    def __repr__(self):

it wraps to something like this:

    def __repr__(self):

I would prefer for it to be displayed as:

    def __repr__(self):

Edit: after reading Don Werve's response, it seems that I am indeed looking for the breakindent option, but the option is still on the "Awaiting updated patches" list (see Vim TODO). So what I'd like to know is what is the easiest way to get vim working with breakindent? (I don't care what version of vim I have to use.)

share|improve this question

5 Answers 5

up vote 2 down vote accepted

You're looking for breakindent

You may want to also refer to this thread.

share|improve this answer
For recent updates to the breakindent patch, see here: retracile.net/wiki/VimBreakIndent –  talljosh Dec 28 '10 at 15:09

I asked the same question on SuperUser, eventually found this question, found the patch, and updated the patch to work with Vim 7.2.148 from Fedora 11.

You can use yumdownloader --source vim to get the source RPM. Then add a Patch3312: line and a %patch3012 -p1 line to the spec file, and build the rpm.

share|improve this answer
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:17
Thanks for maintaining the patch. I was able to successfully apply the 7.3 version on Ubuntu. –  JaseAnderson Jan 13 '11 at 6:45
I have tried downloading the patch, but there is no link for it. Where can I find it? This is probably the one thing I want most right now. –  puk Feb 23 '12 at 11:56
A major software upgrade had left some broken links. I've fixed them now. –  retracile Feb 24 '12 at 17:12

For controlling the indentation of Python code, see :h ft-python-indent. This for example will make Vim indent two times the shiftwidth if you do a newline while there's an unclosed paren:

let g:pyindent_open_paren = '&sw * 2'

However &sw * 2 is the default, so not sure why it's not working for you. It works for me with manual newlines or with textwidth-induced newlines.

The above setting needs to be in .vimrc or needs to be set somehow before Vim enters Python mode. Be sure to :setf python or that you're otherwise in Python mode.

share|improve this answer

I recommend this vimscript:


"This indentation script for python tries to match more closely what is suggested in PEP 8 (http://www.python.org/peps/pep-0008.html). In particular, it handles continuation lines implied by open (parentheses), [brackets] and {braces} correctly and it indents multiline if/for/while statements differently."

Take care, -Brian

share|improve this answer
That's certainly a useful script, but it doesn't seem to do what I was actually asking. I want something to help with the visual position of long lines rather than with the position of automatic indentation. –  talljosh Apr 18 '09 at 6:42
That script will also add newlines and correctly indent long lines, so they become nicely formatted lines under 80 characters long. –  Brian Dorsey Apr 18 '09 at 6:45

I think set textwidth=80 should do it.

share|improve this answer
This is not actually what the question was asking - the point was how Vim displays the code when it has to be wrapped to fit in the viewing window. –  talljosh Oct 31 '11 at 6:16

Your Answer


