LoginSignup
0
0

More than 1 year has passed since last update.

【Vim】readonlyのファイルをsudoで強制的に保存する方法

Posted at

はじめに

設定ファイルなどを保存しようとしたときにsudoで開くのを忘れて書き込みができないことがありますよね。

以下コマンドを実行することでsudo を使って強制的に保存できます。sudo 権限は必須なのでご注意ください。

Vimのコマンドモードで以下コマンドを実行

:w !sudo tee %

tee コマンドで現在開いているファイルを、強制的に上書きします。

w : ファイルの保存
!sudo tee : !sudo tee コマンド
% : 現在開いているファイル

:q!で終了

:q!

上記手順で編集内容が保存されています。

0
0
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
0
0