I am currently using the windows version of gVim to edit source files on a networked drive mapped to a linux system, as well as local files created in cygwin.

The problem is that the windows version of gVim destroys the original file permissions on the respective systems. IE: Files on cygwin are defaulted to 077. When edited by the windows version of vim they are saved as 777.This problem doesn't even occur when using ms-notepad (as well as all other editors I've tried), so I am not quite sure why gVim does it.

A possible solution would be to use cygwin's gVim for everything, but that's rather cumbersome as it requires running an x11 environment to support it, and it causes some problems when running some commands from within gVim (or vim for that matter) when working on the networked drive.

Any ideas how I might be able to maintain the existing file permissions?

Edit: This morning while on a different machine the problem with cygwin did not occur. Cygwin & gVim were the same version, however the other machine is running WinXP while the machine the problem is occurring on runs Win7.

  • Not sure if it matters or not, but what protocol are you using to share the network drive with your Windows system? – moberley Aug 31 '10 at 5:11
  • Samba. I did find one other person with a similar problem when using in the vim mailing list - no solution however. – dborba Aug 31 '10 at 16:26
  • Out of curiosity, if you still have this problem what does :set backupcopy? backup? writebackup? give you? (See Vim FAQ, 7.3.: When I save a file with Vim, the file permissions are changed.) – peth Feb 15 '12 at 22:23

I'm pretty sure this is to do with differences in how permissions are handled on Windows and Unix/Linux. By default, files created on a Samba share from Windows always get created with 777 permissions. If backupcopy is set to no Vim saves files by creating a new file rather than writing to an existing one, so this would cause what you're seeing.

So, two possible fixes:

  • Set the backupcopy option in vim to yes
  • Set create mask = 0644 (or whatever) in the Samba configuration for the share in question

Info on file permissions in Samba

| improve this answer | |

Your best bet is that there's a setting in gVim that covers saved file permissions. If there isn't a setting for that in gVim, you may be out of luck. However, since this is arguably a bug in Windows gVim, you might consider reporting it to the developers.

| improve this answer | |
  • Doing a search on the vim reference and user manual produces no hit on "permission" so it does not seem to be a setting. I'll certainly consider reporting the bug if I can't find a viable solution. – dborba Aug 30 '10 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.