Sudoedit a file in a writable directory when using vimdiff

permissionsrootsudosudoeditvim

When I want to vimdiff root files, I use the following alias, as per this suggestion.

alias sudovimdiff='SUDO_EDITOR=vimdiff sudoedit'

I can then use the following command.

$ sudovimdiff /root/a /root/b

However, if one of the files is writable by my user, the command fails.

$ sudovimdiff /root/a /tmp/b
sudoedit: /tmp/b: editing files in a writable directory is not permitted

Is there a way to vimdiff one root and one non-root file, using my user's environment settings (i.e. sudoedit)?

Best Answer

May be useful related to that sudoedit error message:

sudoedit: ... editing files in a writable directory is not permitted

Please try a modification to sudoers file using sudo visudo, add a line:

Defaults  !sudoedit_checkdir

More here.