Vim auto commands: writing a read-only file?

久未见 提交于 2019-12-10 03:54:48

问题


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?


回答1:


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 %



回答2:


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



来源:https://stackoverflow.com/questions/1681058/vim-auto-commands-writing-a-read-only-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!