【问题标题】:Emacs: edit root files with no trampEmacs:编辑根文件没有流浪汉
【发布时间】:2012-09-22 05:51:47
【问题描述】:

这是一种在非 root 运行 emacs 中打开 root 文件的方法:

 erf () { SUDO_EDITOR="emacsclient -n -a emacs" sudoedit $@; } ;; erf = Emacs Root Foreground

它会询问一个 root 密码,一旦你输入它,它就会在/tmp 中打开一个文件副本。示例:

$ cd /etc/apt
$ erf sources.list

打开:sourcesXXiOSmYN.list。所以我编辑了这个东西,并用C-x C-s 保存它——但它没有保存:

$ sudoedit: sources.list unchanged

如何让它保存东西? (功能会很整洁)

编辑

 erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $@; } ;; erf = Emacs Root Foreground

解决它。保存文件,然后 - 终止缓冲区或 C-x #。它有效。

【问题讨论】:

  • @thisirs:让它成为一个答案,这样我就可以接受它了。

标签: linux ubuntu emacs sudo kubuntu


【解决方案1】:

删除 -n 选项。我使用的 FWIW,

alias E="SUDO_EDITOR=\"emacsclient -c -a emacs\" sudoedit"

在某个地方...

【讨论】:

    【解决方案2】:

    我不使用emacs,但是有什么问题

    export EDITOR=emacs
    # or export VISUAL=emacs
    sudoedit some-root-file
    

    ?将导出行放在你的 .bashrc 中,你就完成了。

    【讨论】:

    • 我刚刚使用export EDITOR=emacsclient 尝试了您的解决方案(需要emacsclient 而不是emacs 以便在运行的emacs 中打开文件)。它似乎正在工作。
    猜你喜欢
    • 1970-01-01
    • 2011-10-20
    • 2015-12-21
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多