Rodrigo Gurgel
Rodrigo Gurgel

Reputation: 1736

How to reload file's properties in vim without loose the changes

Sometimes when editing a code on VIM when I hit :w I discover that the file is not checked out on source server (read only on FS).

So I go on svn|Teamprise Explorer then checkout the file (making the file writable), but after that when :w is executed it gives the same message, seems like vim doesn't check that the permissions has been changed.

Now the problem, if I hit :e the file is reloaded but I'll loose every change, using :w! is not so elegant, it can turn you into a lazy programmer, always doing that then comparing to the 'latest version'.

Does exist some how to reload only the permissions?

Upvotes: 4

Views: 442

Answers (1)

Karl Bielefeldt
Karl Bielefeldt

Reputation: 49038

I don't know how to load only the permissions, but there are a couple other things to try.

One is to prevent modification when the file is read only, using the script from here:

function UpdateModifiable()
  if !exists("b:setmodifiable")
    let b:setmodifiable = 0
  endif
  if &readonly
    if &modifiable
      setlocal nomodifiable
      let b:setmodifiable = 1
    endif
  else
    if b:setmodifiable
      setlocal modifiable
    endif
  endif
endfunction
autocmd BufReadPost * call UpdateModifiable()

The other is to get or write a plugin for your source control. We use perforce at work and I found a plugin that lets me checkout from perforce straight from the vim menu. Also, if I try to edit a file that isn't checked out, vim prompts me to ask if I want to do so.

Upvotes: 3

Related Questions