ThisUpdate: OP asked about using this only on designated buffers rather than any and all buffers. My suggestion was to repurpose b:blockwrite
as a user-controlled flag. It is not heavily testeddefined by default and manually set to 1 for buffers to be protected. That responsibility fallswould require just a few changes to you as "payment"the function. The first conditional block is removed and the second conditional is modified. That gives us...
func! CheckWriteBlock(bufname)
" Flag not defined or it's disabled (equal to 0)
if !exists("b:blockwrite") || !b:blockwrite
" Write the file and unset modified flag
w
set nomodified
return
endif
" Last block remains the same so
...snip...
endfunc
I'd also create a convenience mapping for receiving this codetoggling the flag, e.g. :) I will, of course, look at anything that isn't working and help refine it as needed...
nnoremap <leader>b :let b:blockwrite = exists("b:blockwrite") ? !b:blockwrite : 1<cr>