Clang-format line breaks

后端 未结 4 1923
小蘑菇
小蘑菇 2020-12-04 18:42

I\'m looking for a clang-format setting to prevent the tool from removing line breaks.

For example, I have my ColumnLimit set to 120, and h

4条回答
  •  青春惊慌失措
    2020-12-04 19:48

    I'm not sure that you clang-format to do exactly what you want, but it is possible to tell clang-format to leave sections of code alone. I use this for exactly the sort of scenario you're talking about, blocks of code where a very particular formatting makes it easier to read.

    std::vector get_vec()
    {
       // clang-format off
       return std::vector {
          "this is a test",
          "some of the lines are longer",
          "than other, but I would like",
          "to keep them on separate lines"
       };
       // clang-format on
    }
    

    See: http://clang.llvm.org/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code

提交回复
热议问题