Q:

:wq! command in vim

Recently, I read here about the :wq! command in vim. I don't understand how it can force-write a file without write permissions. This way, theoretically, one would be able to edit root files without permission. Shouldn't it be disallowed? Or does it write into a new file?
I saw a similar question, but that is about motions and is very different.
P.S. I haven't tried the command for fear of messing up system files.

A:

If you don't have permission to the file (e.g. you don't own the file), then it will not force the write. If you do have permission to the file, but it is a read-only file, then you can force-write it. It's as if you first change the file mode to writable, write your changes, and then change the file mode back to read-only.

A:

Do not be afraid, vim cannot grant you more rights than the OS would give you anyway. w! is useful to override read-only mode if you happened to open a file with the vim -R command or if you had made the file read-only before opening it with vim for yourself.

