Reputation: 3739
Why does :wq fail with File is read only
, but :w! then :q succeeds?
This file was opened by the command sudo vi filename
since the permissions are 550
Upvotes: 3
Views: 2643
Reputation: 14376
The sudo command allows you to override the permissions of the file 550 (rxrx-). :wq
won't override but :w!
will.
Note that the purpose of the !
is to 'force' your command w
. :wq
doesn't include the 'force' modifier.
Upvotes: 5
Reputation: 6742
:w!
will write to a read-only file if the directory is writeable, even if the file itself is not writeable. (It creates a new file, and deletes the old one)
Upvotes: 4