4

My .vimrc has,

autocmd FileType rust autocmd  BufWritePre <buffer> call LanguageClient#textDocument_formatting_sync()

This works great, unless my LanguageClient crashes. Then I can't write the buffer. Is there an easy method to write a file and skip the autocmd, you'd think :w! but alas, even that is blocked by autocmd

1
  • 1
    PS instead of Filetype autocommands, consider ftplugins – D. Ben Knoble May 7 at 11:14
6

Generally speaking, that's exactly what the :noautocmd command modifier is for. Just prefix your command with that and all autocommands should be disabled for just the run of that command.

:noautocmd w

Of course, this is the scorched earth approach. If there are other autocommands that you need to keep enabled and you're trying to ignore just the one you mentioned than a different approach is required. If this is the case I'd suggest explicitly mentioning it in your question, though there are few things I can mention right now...

First, want to see which, if any, autocommands are being run? Try this:

:9verbose w

Speaking for myself, I have two plugins that have actions that are triggered by an autocommand associated with :w. They aren't what I'd call critical but I may still want to keep them intact. They are not associated with BufWritePre, though, so for me an alternative to :noautocmd would be to disable just the BufWritePre event, do the write, then re-enable that event:

:set eventignore+=BufWritePre | w | set eventignore-=BufWritePre

That could easily be wrapped up in a mapping or user command.

2

Just ignore all errors from LanguageClient

silent! call LanguageClient#textDocument_formatting_sync()

Note: the last error message is still available as echo v:errmsg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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