Vim 自动命令:写入只读文件? [英] Vim auto commands: writing a read-only file?

查看:77
本文介绍了Vim 自动命令:写入只读文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上使用 Perforce 和 Vim.我目前有一个自动命令设置为在更改时打开只读文件进行

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>

当试图写入一个只读文件而不是编辑它时,有没有办法设置一个类似的自动命令来执行p4 edit?

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?

推荐答案

您可以使用附加到 BufWritePre 事件的自动命令,该命令检查文件是否只读并执行 p4 编辑 按需.类似的东西:

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 %

这篇关于Vim 自动命令:写入只读文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆