I want to format only a part of file and keep the rest unchanged using ALE. I imagine that its kinda possible by providing a fragment of code for example for black
formatter and replacing the selected lines with the result retrieved from black
.
Applying formatter for a large file could cause too many changes. Its way easier to track what have changed if only a part of the file is changed at once.
formatprg
is probably a better option, I think? But you need to invoke that manually.formatprg
for that, assuming thatblack
can operate on partial files:set formatprg=black
(may need flags?), select what you want to be formatted, and thengq
. Many people like to mapgq
toq
btw, which is a bit easier to type.Q
, perhaps that’s what you meant? Black does have some issues when the partial file is not syntactically correct, and it’s also noisy (needs some cleanup). And i think a stdin or - flag is required