将 emacs -nw 设置为默认编辑器

gsi*_*011 15 emacs default-programs update-alternatives

编辑文件时sudoers,我想使用 emacs 而不是 nano。所以我运行了这个命令

sudo update-alternatives --config editor
Run Code Online (Sandbox Code Playgroud)

And I selected emacs. The only issue is I like emacs in no window mode (the -nw flag) and I've aliased emacs as emacs='emacs -nw' so that I can use no window mode in normal use, but I don't know how to get my default editor to be in no window mode.

In other words, I need to get the command sudo visudo and similar commands that open up editors to open the file with emacs -nw. How can I do this? I'm on Ubuntu 12.04.

McN*_*sse 8

创建一个以 -nw 标志启动 emacs 的脚本,例如 /usr/local/bin/emacs-nw。

#!/bin/sh

emacs -nw "$@"
Run Code Online (Sandbox Code Playgroud)

使用 update-alternatives --install 安装它。

sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/emacs-nw 2
Run Code Online (Sandbox Code Playgroud)

将编辑器配置为您的新脚本。

sudo update-alternatives --set editor /usr/local/bin/emacs-nw
Run Code Online (Sandbox Code Playgroud)

  • 对于那些不使用 update-alternatives 特色系统的人,`.bashrc` 中的 `chmod +x /usr/local/bin/emacs-nw` 和 `export EDITOR='emacs-nw'` 可以解决问题。 (2认同)

haz*_*ziz 8

将以下内容添加到您的~/.bashrc文件(如果不是 Bash,则添加到您的 shell 的配置文件)。

export EDITOR="emacs -nw"

这应该设置(并导出)一个 env 变量,将您的默认编辑器设置为非图形模式下的 Emacs。

  • @Manolete 您可以使用 `command emacs`,这将运行没有别名等的 Emacs。当然你也可以为一个会话`unalias emacs`。 (2认同)