Anthony Rusignuolo
Anthony Rusignuolo

Reputation: 131

How to edit formatting settings to increase line wrapping length?

I'm having trouble figuring out how to set line wrapping distances in the C++ formatter. Every time I format the document, if a given line is greater than 100 characters (at least it seems to be 100) the line will be split at the nearest place before the 100 character mark. I would like it to never split a line no matter the length because it's easier for me to work with VS Code's Word Wrap feature. Simple problem, but it's proving to be a headache for me.

I have tried using other formatters like Prettier and Clang, but to no avail. I can't seem to find any documentation for the Microsoft C++ extension's custom settings either. I have also set the Editor: Word Wrap Column setting greater than 200.

Pre-format:

std::cout << boost::format("Actual RX Antenna: %s") % usrp->get_rx_antenna() << std::endl << std::endl;

Post-format:

std::cout << boost::format("Actual RX Antenna: %s") % usrp->get_rx_antenna() << std::endl
              << std::endl;

Just to be clear, I don't want the lines to split during formatting.

Thanks for your help!

Upvotes: 6

Views: 7610

Answers (1)

Anthony Rusignuolo
Anthony Rusignuolo

Reputation: 131

The Microsoft VS Code C++ package is called cpptools, which uses Clang. Clang is very robust formatter that can handle a number of different languages. However, the individual settings for Clang aren't easily accessible in VS Code, so they provide the easy ability to use a number of standard settings like LLVM, Google, Chromium, Mozilla, WebKit, etc. (see BasedOnStyle section) or to specify all custom settings in a .clang-format file in the directory that the file your trying to format is saved in. So choosing a standard is nice, but wasn't very customizable, and putting a copy of a .clang-format file in every directory wasn't going to cut it. Thankfully, there is also a third option, which most robustly solved my problem, you can enter individual settings in VS Code in a json-esque format, one of which allows you to base your custom settings (BasedOnStyle) on a standard. Then I simply continued with the settings I needed. The one that solved the original problem was ColumnLimit. For clarity these are my settings in VS Code.

C_Cpp: Clang_format_style

file

C_Cpp: Clang_format_fallback Style

{ BasedOnStyle: LLVM, IndentWidth: 4, ColumnLimit: 1000 }

Upvotes: 5

Related Questions