在使用 Emacs 通过 SSH 和 Sudo读取打开文件后,我可以通过 sudo 编辑远程文件,
/ssh:username@hostname|sudo:username@hostname:/the-file
但我不能 sudo 编辑本地文件,Emacs 的tramp 提示密码为root@hostname,因为在 Ubuntu 上不存在 root 的密码(请参阅RootSudo)。
那么有没有办法在 Ubuntu 上 sudo 编辑本地文件?
总结:如果你想用 Emacs 编辑远程/本地文件,@ phils在Open file via SSH 和 Sudo with Emacs 中有一个很好的答案
;如果您使用了弹丸(版本<=0.12.0)并且无法 sudo 编辑本地文件(例如Tamp: sending password或挂起),您可以尝试以下代码来解决我的问题:
(when (package-installed-p 'projectile)
(defun projectile-project-root ()
"Retrieves the root directory of a project if available.
The current directory is assumed to be the project's root otherwise."
(let …Run Code Online (Sandbox Code Playgroud)