How to make text wrapping match the current indentation level in vim?

Does anyone know how to get vim to wrap long lines of text so that the position of the wrapped text is based on the indent of the current line? I do not want to reformat my code, just to make it display beautifully.

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

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

displayed on completion as:

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

then if I write a code block as follows:

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

it wraps around like this:

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

I would prefer it to display as:

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

Edit: after reading the answer to “Don Werve”, it looks like I'm really looking for a breakindent option, but this option is still in the “Wait for updated patches” list (see Vim TODO ). So what I would like to know is the easiest way to get vim to work with breakindent ? (I don't care which version of vim I need to use.)

+13
python vim textwrapping
Apr 17 '09 at 8:41
source share
5 answers

Are you looking for breakindent

You can also refer to this thread .

+3
Apr 17 '09 at 15:38
source share

I asked the same question about SuperUser , eventually found this question, found a patch and updated the patch for working with Vim 7.2.148 from Fedora 11.

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

+7
Nov 20 '09 at 17:21
source share

I recommend this vimscript:

http://www.vim.org/scripts/script.php?script_id=974

"This python script indentation attempts to more accurately match what is proposed in PEP 8 ( http://www.python.org/peps/pep-0008.html ). In particular, it processes continuation lines implied by open (parentheses ), [brackets] and {curly brackets} are correct, and discards multi-line if / for / while expressions differently. "

+1
Apr 18 '09 at 6:37
source share

I think set textwidth = 80 should do this.

-one
Apr 17 '09 at 8:44
source share

To control the indentation of Python code, see :h ft-python-indent . This, for example, will indent Vim twice as much as shiftwidth if you make a new line while there is an open finger:

 let g:pyindent_open_paren = '&sw * 2' 

However, &sw * 2 is the default, so not sure why it does not work for you. It works for me using manual newlines or with textwidth induced newlines.

The above parameter must be in .vimrc or must be set in some way before Vim enters Python mode. Required :setf python or that you are otherwise in Python mode.

-one
Apr 18 '09 at 7:16
source share



All Articles