That way, it's easy to run :w!! The above is about Vim mandatory save read-only file method, hope the content of this article to your study or work can bring 1 definite help, if you have questions, you can leave a message to communicate.
Home Linux Vim forces a method to save a read only type file. Problems found: When using vim, when we opened a file that only root users have permission to operate as normal users, we were about to save the file after editing, but found that we did not have permission to modify the file. 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! 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. Run gVim as an administrator, e. Then it started working without ever the "! I had also run attrib but that was not effective. Type :f "newfilename" in command mode then when leaving :w to save under the new file name. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Learn more. How do I save a read-only file in Vim for Windows? Ask Question. Asked 5 years, 10 months ago. Active 1 year, 8 months ago. Viewed 8k times. At this point is where the new magic can happen. We can enter a new command and successfully save the file after entering the sudo password:. At this point we will be presented with the content of the file and a prompt to press ENTER or type another command.
Thank you for this!! Too many face palm! This worked for me. Thanks, saved me three times now. First result on Yahoo search makes it easy to get back here too.
0コメント