Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim auto commands: writing a read-only file?

Tags:

vim

perforce

I'm using Perforce with Vim on Windows. I currently have an auto command set up to open a read-only file for edit when changing it:

au FileChangedRO * !p4 edit <afile>

Is there any way to set up a similar auto command to execute p4 edit when attempting to write a read-only file rather than edit it?

like image 752
Dominic Dos Santos Avatar asked Nov 05 '09 14:11

Dominic Dos Santos


1 Answers

You can use an auto command attached to the BufWritePre event, that checks whether the file is read only or not and executes p4 edit on demand. Something like:

autocmd BufWritePre * :if &readonly | !p4 edit %
like image 151
f3lix Avatar answered Sep 28 '22 10:09

f3lix