Temporarily disable BufWrite script in vim

I have a vim installation to run Autoformat when I write to files, but occasionally forget to add the extension to my blacklist before making changes to it. Now I can’t save the changes, as autoforming ruined the indent. Is there a way to save without running BufWrite scripts?

The line in my vimrc is:

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

+4
source share
1 answer

There are three options:

:noa[utocmd] w[rite]

will save without starting any auto-recordings. Unless you have other settings / plugins using autocmds, this will be fine.

:set eventignore=BufWrite | write | set eventignore=

temporarily disable the event BufWrite.

Alternatively, you can also add a conditional expression around your autocmd:

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

autocmd :let g:no_autoformat = 1.

PS: :autocmd | endif.

+5

Source: https://habr.com/ru/post/1664343/


All Articles