vim-win32-installer
vim-win32-installer copied to clipboard
Can't exit vim editing file with no write access for user
I'm not sure whether to log this with Vim or here.
I am logged in as UserA and have read-only access to a folder that is owned by Administrator. If I open a file in gvim, I can edit it. However, when I try to save it, the following message appears:
File permissions of [filename] are read-only. It may still be possible to write it. Do you wish to try?
The options are Yes or No. Whichever I choose, I get asked again. The only way to exit this infinite loop is to kill the gvim process from Task Manager or equivalent.
so this happens also with gvim --clean? I have never noticed that
Hm, if I try this here, I get:
E45: 'readonly' option is set (add ! to override)
if I then try using :w! I get:
E212: can't open file for writing
But I never get that prompt. Hm, perhaps the 'backupcopy' could make difference?
Are those file permissions for that file special?
Note: already when opening, I see an indicator [readonly] in the status bar.
There are NTFS permissions set on the folder, which the files in it inherit. This is different from setting the read-only attribute on the file. The administrator has "full control" NTFS permission and UserA has "read-only" NTFS permission. To set the NTFS permission, I right-click folder in File Explorer > Properties > Security tab > set permissions.
The read-only attribute has not been set.
I do have the backup files option enabled in vim. I'll try in gvim clean mode tomorrow when I'm by PC.
I ran gvim --clean and the problem went away. I noticed that no dialog box appeared. I tried with a minimal vimrc, adding set confirm and the dialog box appears but the problem doesn't ie the dialog appears once then not again after I click 'No'.
Then I tried gvim --noplugin ie with my vimrc and the problem didn't appear. So it looks like a plugin is causing the issue.
For backup, swap and undo directories, I set directory, backupdir, and undodir to a directory that UserA has write access to.
I will investigate further and see if I can narrow down the issue.
I've narrowed it down to the following minimalist vimrc:
set confirm
if has("autocmd")
augroup PK2
autocmd!
autocmd BufLeave,FocusLost * silent! wall
augroup END
endif
The culprit seems to be set confirm. If that's commented out, there is no infinite prompting to save a file.
Steps to reproduce:
- Save above in
c:\temp\vimrc cd c:\temp- create a file
test.txt - make file read-only:
attrib +r test.txt - run:
gvim --clean .\test.txt -u c:\temp\vimrc - edit
test.txt - save it:
:w
The attempt to save test.txt will result in a dialog box repeatedly appearing.
In the above example, I'm using the read-only attribute but the same happens with NTFS permissions.
Obviously this is not a big issue since I can comment out the focuslost command or the set confirm command to work around the issue.
Edit: my guess is that the appearance of a Windows dialog box, even if it's created by vim causes a FocusLost event, which results in the confirm kicking in, which shows the dialog box, which, and so on. Is the answer not to treat vim-generated dialog boxes as a loss of focus?