开发者

Vim auto commands: writing a read-only file?

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>

I开发者_开发百科s 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?


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 %


You can give the perforce plugin a shot. I find it very useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜