views:

123

answers:

2

This is very similar to:

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

Except that in addition to the solution presented there, I want vim to only ask for confirmation if the file is still read-only.

In other words, if I do :w, I do not want vim to say that the file is read-only. It should automatically open the file for edit using perforce, and only if the file is still read-only should it then ask for confirmation.

A: 
autocmd! bufreadpost * :if &readonly && confirm('File is read only. Open for edit?', "&Yes\n&No", 1) == 1 | setlocal noreadonly writeany
Nikolay Frantsev
This must be in addition to the BufReadPre handler from the other answer, I assume?
ephemient
no, it must works as is
Nikolay Frantsev
OP wants to try checking out with Perforce (p4) first.
ephemient
I want this to occur at bufwrite, not bufread, sorry.
Arafangion
+2  A: 

You might also be interested in the Perforce plugin for vim.

jhwist
This is still the best answer I've seen here, so I've accepted it - in practice, however, I'm just living with the unneccessary confirmation dialogue and continuing with normal mode mappings, in combination with having vim reload the file if it has changed.
Arafangion