How do I get emacs to open in the terminal when it is being used as the config editor?
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
Related videos on Youtube
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, 2022Comments
-
Eric Wilson about 1 year
I like to use emacs as my configuration editor, so it is the default for programs like
git
orcron
. So I usedsudo 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 about 10 yearsHow can I tell programs like
git
to invoke emacs in this way? -
psusi about 10 years@EricWilson,
export EDITOR='emacs -nw'
. Personally I prefer to useemacsclient
so that the file opens in my existing gui emacs window. -
steeldriver about 10 yearsFWIW I think git has its own configurable editor setting as well, e.g.
git config --global core.editor "emacs -nw"
-
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.