Vim: Inter-String Line Breaking

给你一囗甜甜゛ 提交于 2019-12-12 09:55:58

问题


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?


回答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.



来源:https://stackoverflow.com/questions/15757298/vim-inter-string-line-breaking

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!