Remove a file's "read only" attribute in vim after editing it and saving with :w! Remove a file's "read only" attribute in vim after editing it and saving with :w! unix unix

Remove a file's "read only" attribute in vim after editing it and saving with :w!


The v:cmdbang is what you are looking for.

function! g:ChmodOnWrite()  if v:cmdbang    silent !chmod u+w %  endifendfunctionautocmd BufWrite * call g:ChmodOnWrite()


You should be able to use just *:

autocmd BufWrite * !chmod u+w %

It may be better to use BufWriteCmd instead. I think that if the chmod fails, Vim will not attempt to write.


The shell command chmod u+w <name of file> does what you want. I don't know offhand how to invoke that from inside vim.