Is there a way to get vim to automatically break python strings into 79 characters?

I found this answer about wrapping strings using partners extremely useful, but is there any way in Vim to do this automatically? I want to be inside a string, print, and Vim just puts parens around my string and wraps it as needed. It will be a huge time saver for me, because I spend so much time just wrapping the long lines by hand. Thanks in advance.

Example:

  • I’ll print the following text:

    mylongervarname = "my really long string here so please wrap and quote automatically" 
  • Vim automatically does this when I click column 80 with a row:

     mylongervarname = ("my really long string here so please wrap and " "quote automatically") 
+35
python string vim wrapping textwrapping
Aug 21 '09 at 20:54
source share
1 answer

More direction than decision.

Use 'formatexpr' or 'formatprg' . When a line exceeds 'textwidth' and passes the criteria set using 'formatoptions' , they are used (if set) to break the line. The only real difference is that 'formatexpr' is a vimscript expression, and 'formatprg' filters the string through an external program.

So, if you are aware of the formatting that this conversion to python code lines can do, or you are ready to write one, this will give you a hook to execute it. And since vim supports python (see :help python ), you can even write your python formatter in python.

+12
Aug 22 '09 at 7:46
source share



All Articles