Temporarily disable BufWrite script in vim
Asked Answered
S

1

8

I have vim setup to run Autoformat when I write to files but periodically forget to add an extension to my blacklist before making edits to it. Now I can't save the edits since the autoformating messes up the indentation. Is there a way of saving without running the BufWrite scripts?

The line in my vimrc is:

au BufWrite * if index(blacklist, &ft) < 0 | :Autoformat

Solute answered 20/12, 2016 at 20:44 Comment(0)
F
12

There are three options:

:noa[utocmd] w[rite]

will perform a save without triggering any autocmds. As long as you don't have any other customizations / plugins using autocmds, that would be fine.

:set eventignore=BufWrite | write | set eventignore=

will temporarily turn off just the BufWrite event.

Alternatively, you could also add a conditional around your autocmd:

au BufWrite * if ! exists('g:no_autoformat') && index(blacklist, &ft) < 0 | :Autoformat

That would enable you to selectively disable just that particular autocmd via :let g:no_autoformat = 1.

PS: Your :autocmd is missing the closing | endif.

Familiarize answered 21/12, 2016 at 8:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.