Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make text wrapping match current indentation level in vim?

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:

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

then if I write a block of code like this:

    def __repr__(self):
        return 'ProcessorError(%r, %r, %r)' % (self.file, self.index, self.message)

it wraps to something like this:

    def __repr__(self):
        return 'ProcessorError(%r, %r, %r)' % (self.file, self.index,
    self.message)

I would prefer for it to be displayed as:

    def __repr__(self):
        return 'ProcessorError(%r, %r, %r)' % (self.file, self.index,
            self.message)

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.)

like image 938
talljosh Avatar asked Apr 17 '09 08:04

talljosh


People also ask

What is GQ in Vim?

DESCRIPTION. Vim can reformat lines with the gq command, according to 'textwidth' and. 'formatoptions', which is very handy. But sometimes you want to format to a. different width, or just a single block in a vertical column layout.


2 Answers

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.

like image 197
retracile Avatar answered Nov 01 '22 19:11

retracile


You're looking for breakindent

You may want to also refer to this thread.

like image 28
Don Werve Avatar answered Nov 01 '22 18:11

Don Werve