Clang-format line breaks

后端 未结 4 1922
小蘑菇
小蘑菇 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:33

    Add a comma after the last string. This tells clang-format to format it vertically. Ex: https://godbolt.org/z/bZxr__ Right click > format text

    #include 
    #include 
    
    std::vector get_vec() {
      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", // comma here after last element
      };
    }
    
    int main() { auto vec = get_vec(); }
    

提交回复
热议问题