In our C++ code base we keep 99 column lines but 79-some-odd column multiline comments. Is there a good strategy to do this automagically? I assume the modes are already known because of smart comment line-joining and leading * insertion.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Apparently both code and comments use the same
textwidthoption. As far as I can see, the only trick is to set this option dynamically:Here the critical part is detecting when we are in a comment. If you only format comments this way:
my regex should work… unless you have lines in the code starting with
*(which I guess can happen inC, less frequently inC++). If you use comments like this:the regex is even simpler to write. If you want to cover all possible situations, including corner cases, well… I guess the best thing would be to define a separate detection function and call that from the
:autocmdinstead ofmatch().