Disable warning in VIM?

余生长醉 提交于 2019-12-03 13:55:23

问题


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


回答1:


add the following line to your .vimrc file :

set autoread

This will disable "read-only to writeable" warnings




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/1095708/disable-warning-in-vim

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