1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vimで編集したファイルがreadonlyだったけど保存したい

Posted at

どーも、ふぎとです。
今回は「vimで編集したファイルがreadonlyだった、でも
編集内容を保存したい
」問題について。

何の気なしに編集

(新米エンジニアのふぎとくん。
きょうはvimでファイルを編集したみたい。)

あれ、編集した内容が保存できひん

E45: 'readonly' option is set (add ! to override)

先輩に相談

「先輩、編集内容が保存でけへんのですが」
「あーふぎと君、これreadonlyのファイルやからな、
 原則は編集できひん仕様やねん」
「ほんまですか?ほな書き直さなあかん…??」
「いやいや安心せえ」
「『原則』言うてるやろ?」
「上のメッセージよく読んでみい」
「えーっと… "add ! to override"?」
「あ、なんか"!"マークつけたら設定変えれるってことですか?」
「せや、そん通りや」
「readonlyファイルでも編集内容を強制的に保存(上書き)する
 コマンドがあるんや」

編集内容の強制保存

「これがそのコマンドや」

:w !sudo tee %

「えらいシンプルですね」
「せやろ」
いま開いとるファイル(%)に対して"sudo tee"で
 編集内容を強制的に上書きしとる
んや」
「ほへ~そうなんですか」
「あ、それやったらsudo権限は必須てことですね」
「せやな」
「そればっかりはしゃーない」
「ほんで強制保存したら :q! で終了する」
「こんだけや」
「あっという間ですやん」
「どうもありがとうございました(´ω`)」

パク…参考にした記事

https://hacknote.jp/archives/12412/
http://tm.root-n.com/unix:command:vim:readlonly_write

今日はここまで。ではでは。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?