VSCode in WSL: how to sudo a root file so I can edit it

后端 未结 5 1223
逝去的感伤
逝去的感伤 2021-02-12 13:21

WSL v.1 -- VSCode v1.40.1 (using \'Remote - WSL\' extension 40.3)

How to open a root-owned file for edit using sudo and VSCode? (without running as root)

5条回答
  •  遇见更好的自我
    2021-02-12 13:33

    Set environment variable:

    export VISUAL="code -nw"
    

    Then you can edit any file like this:

    sudo -e file
    

    It will automatically make a copy of file, and, when you close the editor, copy it back.

提交回复
热议问题