2

Consider the three lines shown below.

    std::ostringstream ss;
    cc::write(ss, "Error parsing first magic byte of header: expected 'P', but got '{0}'.", c);
    return io_error{ss.str()};

The second line automatically breaks because it exceeds the text width (&tw), but it does so unsatisfactorily for two reasons:

  1. When the line breaks on a string, the procedure is a little more complicated than usual. Vim needs to close the string literal at the end of the broken line, and add a string literal at the beginning of the newly-created line. But it would be awkward for the line to be broken in the middle of a word, so Vim needs to back up until it finds the end of a word boundary, such that adding a " character after it would not exceed the text width. If it can find no such word boundary, then the entire string needs to be begun on the next line.
  2. When the line breaks in the middle of a string, I do not want any indentation to be inserted at the beginning of the proceeding line.

Are there are any native features of Vim or plugins that I can use to get behaviors (1) and (2), or do I have to write my own plugin?

void-pointer
  • 14,247
  • 11
  • 43
  • 61
  • Does [this answer](http://stackoverflow.com/a/2746829/148680) help? – chb Apr 02 '13 at 06:15
  • @chb I would like to get the same result as manually breaking the line when I use `gq` or let Vim break the line for me automatically as I type. Is there a way to modify that solution so that I can achieve this (along with behavior (1))? – void-pointer Apr 02 '13 at 06:20

1 Answers1

1

To have this special line breaking behavior both with auto-format and gq, you have to write a custom 'formatexpr' that takes this into account.

I'm not aware of any existing plugin, but maybe you find something to get you started on vim.org.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324