Is there any way to edit read-only file on GVim?
If you use vim on console, sudo vim /path/to/file enables you to edit the read-only file. How can I edit it on already-opened MacVim window?
If you open :tabnew /path/to/file then edit it, and try to save it, then the error occurs saying xx is read-only (add ! to override). However, when you try to save it by :w!, the error still occurs saying xx Can't open file for reading.
I know, if you first change the permission of the file and edit it, and then reverts its permission, then you can edit it successfully... But I don't want to bother doing such a tedious thing...
Thanks.
MacVim comes with mvim, a command-line wrapper that allows you to launch the MacVim GUI from the command-line with $ mvim filename and the MacVim CLI executable directly in your shell with $ mvim -v filename.
Both work well with sudo so you can perfectly do $ sudo mvim filename to open filename with write privileges in a new MacVim Window or $ sudo mvim --remote filename to do the same in the current MacVim window.
Either change the permissions/owner:
:!chown myuser %
:!chmod +w %
Or write using sudo over a pipe:
:w !sudo tee %
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With