禁用 VIM 中的警告?

发布于 2024-07-26 07:09:24 字数 113 浏览 4 评论 0原文

有没有办法禁用 VIM 中的警告?

特别是,当文件从只读变为可写时,我想禁用警告 12。 我有一个脚本可以打开文件进行编辑,但 vim 认为文件已更改并发出警告。

谢谢

Is there a way to disable warnings in VIM?

In particular, I want to disable Warning 12 when a file turns from read-only to writable. I have a script which opens the file for edit in perforce, but vim thinks the file has changed and issues a warning.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一紙繁鸢 2024-08-02 07:09:25

我已经使用 FileChangedRO 一段时间了,在开始编辑文件时自动检出文件,并发现 W12 警告也很烦人。 问题是 p4 edit 更新文件属性以删除只读标志。 如果作为初始编辑的一部分,您还更改了文件,Vim 会将其视为冲突,因为它不再是只读的。 这是我使用的解决方案,该解决方案对于使用 FileChangedShell 更为保守,以防文件因其他原因在外部发生更改。

let s:IgnoreChange=0
autocmd! FileChangedRO * nested
    \ let s:IgnoreChange=1 |
    \ call system("p4 edit " . expand("%")) |
    \ set noreadonly
autocmd! FileChangedShell *
    \ if 1 == s:IgnoreChange |
    \   let v:fcs_choice="" |
    \   let s:IgnoreChange=0 |
    \ else |
    \   let v:fcs_choice="ask" |
    \ endif

I've been using FileChangedRO for a while now to automatically checkout files when starting to edit them and found the W12 warning annoying as well. The problem is that p4 edit updates the file attributes to remove the read only flag. If as part of the initial edit you also change the file, Vim sees this as a conflict since it's no longer read only. Here's the solution I use which is a bit more conservative about using FileChangedShell in case the file was changed externally for some other reason.

let s:IgnoreChange=0
autocmd! FileChangedRO * nested
    \ let s:IgnoreChange=1 |
    \ call system("p4 edit " . expand("%")) |
    \ set noreadonly
autocmd! FileChangedShell *
    \ if 1 == s:IgnoreChange |
    \   let v:fcs_choice="" |
    \   let s:IgnoreChange=0 |
    \ else |
    \   let v:fcs_choice="ask" |
    \ endif
策马西风 2024-08-02 07:09:24

我的 .vimrc 中有以下内容; 你应该只需要第二个。 它将消息回显到状态栏,而不是弹出对话框。

autocmd FileChangedRO * echohl WarningMsg | echo "File changed RO." | echohl None
autocmd FileChangedShell * echohl WarningMsg | echo "File changed shell." | echohl None

尝试 :help FileChangedShell 了解更多信息。

I have the following in my .vimrc; you should only need the second one. It echoes the message to the status bar instead of popping up a dialog.

autocmd FileChangedRO * echohl WarningMsg | echo "File changed RO." | echohl None
autocmd FileChangedShell * echohl WarningMsg | echo "File changed shell." | echohl None

Try :help FileChangedShell for more information.

江湖彼岸 2024-08-02 07:09:24

将以下行添加到您的 .vimrc 文件中:

set autoread

这将禁用“只读到可写”警告

add the following line to your .vimrc file :

set autoread

This will disable "read-only to writeable" warnings

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文