Open a file with su/sudo inside Emacs

前端 未结 9 927
我寻月下人不归
我寻月下人不归 2020-12-12 08:32

Suppose I want to open a file in an existing Emacs session using su or sudo, without dropping down to a shell and doing sudoedit or

9条回答
  •  庸人自扰
    2020-12-12 09:25

    Not really an answer to the original question, but here's a helper function to make doing the tramp/sudo route a bit easier:

    (defun sudo-find-file (file-name)
      "Like find file, but opens the file as root."
      (interactive "FSudo Find File: ")
      (let ((tramp-file-name (concat "/sudo::" (expand-file-name file-name))))
        (find-file tramp-file-name)))
    

提交回复
热议问题