当 emacs 用作配置编辑器时,如何让它在终端中打开?

当 emacs 用作配置编辑器时,如何让它在终端中打开?

我喜欢使用 emacs 作为我的配置编辑器,因此它是git或等程序的默认编辑器cron。所以我使用了

sudo update-alternatives --config editor

并从列表中选择 emacs24。

与 Vim 或 nano 不同,这会将 emacs 作为新的 GUI 应用程序启动,而不是接管当前的终端窗口。

有没有办法让 emacs 在终端中作为配置编辑器打开,或者在从命令行调用它时打开,但仍然允许从启动器或 dash 将 emacs 作为独立应用程序启动?

答案1

来自@steeldriver 评论:

git config --global core.editor "emacs -nw"

答案2

大多数实用程序,包括git尊重名为 EDITOR 的环境变量,您可以将其设置为您想要的任何编辑器,包括选项。 export EDITOR='emacs -nw'将让它们在非窗口模式下运行 emacs。

对于emacs,它有一个方便的服务器模式,您可以先启动它M-x server-start,然后emacsclient作为编辑器运行,以打开已在运行的 emacs 实例中的文件。这很方便,因为它允许您保留对 emacs kill ring 和其他功能的访问权限。它还接受开关,-nw以便它将在终端窗口而不是 gui emacs 框架中打开一个新的 emacs 框架,因此它仍然看起来和感觉像一个文本模式 emacs 会话,但仍然与其他窗口共享 kill ring 和缓冲区。

答案3

你可以使用以下-nw命令调用 emacs

      -nw, --no-window-system
              Tell Emacs not to create a graphical frame.  If you  use
              this switch when invoking Emacs from an xterm(1) window,
              display is done in that window.

答案4

您可以在 ~/.gitconfig 中通过在标有 [core] 的部分下添加以下内容来更改此设置:

[core]
        editor = emacs -nw

相关内容