vim-clang-format
vim-clang-format copied to clipboard
:ClangFormat always folds code when run
Is there a way to run the formatter without triggering automatic code folding? Presumably this happens because I have vim setup to fold code when opening a C++ file and :ClangFormat
reopens the file after it has done its thing. It would be great if vim-clang-format had some way to disable this so as to avoid having to drill down through a bunch of folds.
I noticed that it's hard to maintain folding between the before and the after of formatting. For example, when a formatter found unnecessary { ... }
block (e.g. body of if
statement), it would remove the block. Removing block means the change of folding level. We can't detect it from Vim and vim-clang-format can't know which fold level it should open.
However, closing all folds after formatting is annoying as you pointed. I think I can try to implement some heuristics to reduce the problem, although it's not perfect.
I added code to maintain fold level at cursor line as much as possible in 1cf402c. Please try the latest and check the behavior is what you want.
I haven't noticed any difference in behavior, but that could easily be due to other settings I have. Do you have an example I can check?