How do I get emacs to open in the terminal when it is being used as the config editor?

5,497

Solution 1

Most utilities, including git respect an environment variable named EDITOR which you can set to any editor you want, including options. export EDITOR='emacs -nw' will have them run emacs in non windowed mode.

In the case of emacs, it has a handy server mode you can start with M-x server-start and then run emacsclient as an editor to open a file in the already running emacs instance. This is handy since it allows you to retain access to the emacs kill ring and other features. It also accepts the -nw switch so that it will open a new emacs frame in the terminal window rather than in the gui emacs frame, so it will still look and feel like a text mode emacs session, but still share the kill ring and buffers with the other window(s).

Solution 2

From @steeldriver comment:

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

Solution 3

You can invoke emacs with the -nw option

      -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.

Solution 4

You can change this in ~/.gitconfig by adding the following under the section labeled [core]:

[core]
        editor = emacs -nw
Share:
5,497

Related videos on Youtube

Eric Wilson
Author by

Eric Wilson

Software developer, experienced in Java and Python in Linux environments, formerly a professor of mathematics. I'm a father of five children, and a husband of one wife.

Updated on September 18, 2022

Comments

  • Eric Wilson
    Eric Wilson about 1 year

    I like to use emacs as my configuration editor, so it is the default for programs like git or cron. So I used

    sudo update-alternatives --config editor
    

    And chose emacs24 from the list.

    Unlike Vim or nano, this launches emacs as a new gui application, rather than taking over the current terminal window.

    Is there a way to make emacs open in the terminal as a configuration editor, or maybe when it is invoked from the command line, but still allow for launching emacs as a stand-alone application from the launcher or dash?

  • Eric Wilson
    Eric Wilson about 10 years
    How can I tell programs like git to invoke emacs in this way?
  • psusi
    psusi about 10 years
    @EricWilson, export EDITOR='emacs -nw'. Personally I prefer to use emacsclient so that the file opens in my existing gui emacs window.
  • steeldriver
    steeldriver about 10 years
    FWIW I think git has its own configurable editor setting as well, e.g. git config --global core.editor "emacs -nw"
  • Eric Wilson
    Eric Wilson about 10 years
    @psusi your comment is really the answer to my question (the first sentence). I'd accept it if it were given as an answer.