views:

358

answers:

3

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

+7  A: 

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.

ars
+1  A: 

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
neilpa
+2  A: 

add the following line to your .vimrc file :

set autoread

This will disable "read-only to writeable" warnings

Venkatram Tummala

related questions