google / vim-codefmt

Vim plugin for syntax-aware code formatting
Apache License 2.0
1.11k stars 114 forks source link

Is there a way to exclude lines from being auto-formatted? #235

Closed davidzchen closed 7 months ago

davidzchen commented 7 months ago

Are there annotations that can be added to the code to omit certain lines from autoformatting?

davidzchen commented 7 months ago

Never mind. Looks like this is a feature specific to formatters: https://stackoverflow.com/questions/33258159/how-to-make-clang-format-skip-sections-of-c-code

dbarnett commented 7 months ago

Yes exactly. For example clang-format does support clang-format off directives: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#clang-format-style-options. YMMV with different formatters.

You're not going to want to embed formatting rules in anything specific to a vim plugin because they'd be blown away when you format the file outside vim.

OTOH, #9 to format lines more selectively could be helpful here to not have the formatter fighting you quite so aggressively when you are unlucky enough to be fighting the formatter.