Reputation: 61
There is a particular file on my computer that Vim insists on opening in readonly mode. I checked the permissions on the file (I have full control), and if I do :w!, writes happen just fine. However, whether I open the file with :e or from NERDTree, the file opens as readonly. All other files I open work just fine.
I just want to know how to turn off readonly mode on this file, before or after I open it.
I'm on Windows, using gVim
EDIT: Its probably not a permissions issue, since :w! works just fine.
Upvotes: 6
Views: 38877
Reputation: 2857
The solution is pretty simple, this happens only if you don't have the write permission as a user.
go to the terminal and enter the following command:
1] chmod u+wx filename filename is the name of the file that you are trying to edit.
Upvotes: -1
Reputation: 9876
The following added to your vimrc will cause vim to change the file to read-only once it is edited. It works by calling the windows attrib
tool
"Change read/only files to read/write when they are edited
au FileChangedRO * !start attrib -r %
au FileChangedRO * :let s:changedRO = 1
au FileChangedRO * :set noro
"Don't ask about the modified read-only file
au FileChangedShell * call s:HandleChangedROFile()
function s:HandleChangedROFile()
if exists('s:changedRO') && s:changedRO == 1
let s:changedRO = 0
let v:fcs_choice='reload'
else
v:fcs_choice='ask'
endif
endfunction
Inspired by: http://vim.wikia.com/wiki/Setting_file_attributes_without_reloading_a_buffer
Upvotes: 1
Reputation: 69
Actually, it can be a permission issue.
I've just hit this case on XP, with Administrator privileges. After making a file writable (readonly attribute clear, cygwin correspondingly shows it as writable), VIM still shows it as readonly.
In my case, the issue was under Advanced permissions. Looking under Windows Explorer at the file, right-click to get Properties, under the General tab the readonly bit is clear. Now going to the Security tab, it shows that I only have read permission. Clicking on the Advanced button, under the Permissions tab, with my user account selected, it shows I have Special permissions not inherited from anywhere, instead of "Full Control" inherited from the containing directory as I see for my other files.
One fix is to click Edit... to edit permissions in the Permissions tab. However, it is much simpler (at least in the case where you have Administrator privileges) to just do :w! in VIM as others have suggested. This fixes the file's permissions to be writable ("Full Control").
(I'm unclear how this particular file ended up in this "Special" read-only state. Leaving that as outside the scope of your question.)
Upvotes: 2
Reputation: 600
The mode that's annoying you is controlled by the readonly option. To clear it, type :set readonly!
once you've launched the editor.
Upvotes: 8
Reputation: 7426
Have you tried: Right click -> Properties -> see if the 'readonly' attribute is checked?
Upvotes: -1
Reputation: 35341
Maybe there is a vim setting in the file to make the file load as read only :
Check for a line like : (substitute the comment char of your file instead of //)
// vim:set ro:
Vim looks for these settings in the first or last 5 lines of the file.
Upvotes: -1
Reputation: 313
Simply force the file to be written-to by using :w!. You should be golden
Upvotes: -1