vi -- save file with root rights

vi -- save file with root rights

knutwalker

54 года назад

9,300 Просмотров

Ever opened a file and reckoned upon saving, that you should have opened it with sudo in the first place?

use the following save command:

:w !sudo tee % # /dev/null

! replace # with the greater-than sign.

That'll save your file with root rights.

Bonus feature:
Add this to tour .vimrc

noremap %leader#W :w !sudo tee % # /dev/null%CR#

! same here -- replace # with greater-than and % with less-than.


and use ,W as sudo-save-command (note: no colon required, it's a comma now)

Тэги:

#vi_vim_sudo_save
Ссылки и html тэги не поддерживаются


Комментарии: