I have looked for this a lot already and every answer is about Vim in Linux. Is there a way to save a read-only file right from Vim in Windows?
As on other vi/vim versions, you can use
:w! to force the write, as long as you have permissions to override the read-only property.
For example, if you have set the file as read-only, the above will work. If Windows itself or an administrator has set it read-only, you will need another option.
As @dash-tom-bang commented, one good example is within Program Files, where files are protected by default. This Microsoft knowledgebase article explains how that works in practice.
You can use my SudoEdit plugin.
There's another possibility that has not been addressed in the other answers: vim will refuse to save a file if it is open and locked by another Windows application. Many ordinary Windows apps (Office, for example) lock files that they open. If this is the problem, no amount of messing with permissions or :w! will help you. You simply need to close the file in the other app, and then you will be able to save it from vim. It is unfortunate that vim does not clearly signal this situation to the user.
For win7: Start > Run > Cmd (as Admin), and run these commands to make the dir tree writable by admin:
cd parent/folder :: /f file, /a admin, /r recurse, /d y = nopromt takeown /F . /A /R /D Y > nul: :: /t /q /c .. traverse quiet continue icacls . /t /q /c /reset icacls . /t /q /c /grant :r Everyone:F icacls . /t /q /c /setowner Administrators
Run gVim as an administrator, e.g. by right-clicking on, or using the Shift+F10 keyboard shortcut on, the gVim shortcut in your Start menu and picking Run as an administrator.
Open the file you want to edit and save your changes using
:w as normal.
:f "newfilename" in command mode then when leaving
:w to save under the new file name.