vim-autoformat / vim-autoformat

Provide easy code formatting in Vim by integrating existing code formatters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All indentation of bash scripts is removed if `shfmt` is not installed.

nathan-at-least opened this issue · comments

I just started with vim-autoformat for the first time. Thanks for this useful tool!

However, it removes all indentation from my shell scripts when saving. All indentation is with spaces because I use set expandtab. I am using the :au BufWrite * :AutoFormat approach.

By using let g:autoformat_verbosemode=1 I see that shfmt is not installed. I will go install that.

It would be more user-friendly if, in the case that a specific language formatter is unavailable, the behavior on saving a file was identical to the behavior without vim-autoformat enabled. Even more userfriendly might be a message saying "The formatting command shfmt was not found on the path. Leaving file unchanged."

This is perhaps due to the fact that vim's indentfile is not quite as accurate for shell scripts. which is being used when no formatter is found.

To disable the fallback to vim's indent file, retabbing and removing trailing whitespace, set the following variables to 0.

let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0

I agree that error messages could be better, but it require interpreting errorcode and such to do it right. I'm not sure if that is easy to make robust while maintaining cross-platform support. However, pull requests improving the status quo are welcome.