wizurd
wizurd

Reputation: 3739

Why does :w! work but not :wq? File is read only error

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

Answers (2)

KevinDTimm
KevinDTimm

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

Chris Lear
Chris Lear

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

Related Questions