I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer).

I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I tried:

au VimLeave <buffer> :%!fmt -9999 | w

But surprisingly when I leave I am stopped by a confirmation message, and my buffer has been overwritten by

22:39  up 14 days, 23:53, 3 users, load averages: 2.88 2.68 2.72
USER     TTY      FROM              LOGIN@  IDLE WHAT
joshfriedlander console  -                10Mar21 14days -
joshfriedlander s000     -                10Mar21 14days /Users/joshfriedlander/anacon
joshfriedlander s001     -                22:07       - w

However when I use an aucmd not related to leaving, such as

au InsertLeave <buffer> :%!fmt -9999

it works as expected.

What is going on here? How can I fix this?

1 Answer 1


The :! sees the bar as part of its argument (I forget the help-reference; edits appreciated).

So you have to write

execute '%!fmt -999' | write

The extra output is from the w program run by the shell, which is similar to who.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.