Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily disable BufWrite script in vim

Tags:

vim

vim-plugin

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

like image 787
isaac ellmen Avatar asked Dec 20 '16 20:12

isaac ellmen


1 Answers

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.

like image 198
Ingo Karkat Avatar answered Nov 05 '22 19:11

Ingo Karkat