1
0

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 1 year has passed since last update.

「sudo vi の時に .vimrc が適応されない」の対処法

Last updated at Posted at 2023-04-07

概要

これ困ってる人いそうだなと思って記事書きました。

問題

僕が直面した問題は以下の通りです。

  • ユーザーayatoで.vimrcを作った。
  • vim開いて設定が適応されていた。
  • sudo vimしたら設定が適応されてない。
    例えば、sudo vi /etc/hostsとかで見ずらい!

理由

sudo vimをしたら、rootの方の設定を読み込むようになっている。

対処法1

Kaliなどで一人で使っている、かついつもはrootで作業をしない時に使えます。

$ sudo ln -s /home/ユーザー名/.vimrc /root/.vimrc

rootの.bashrcが呼ばれた場合に、現在のユーザーへのリンクを提供してやればOKです!

対処法2

rootを他の人が使ってる場合に有効です。

sudo -E vi ファイル名

sudoコマンドの-E オプションを使用して環境変数を引き継ぎます。

まとめ

役立てていただければ幸いです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?