21

I've used git config --global core.editor emacs to set my git editor as emacs but when I do that and commit something the editor opens up a new window instead of opening emacs within the terminal. I want to use emacs as if -nw were given to it but writing this -> git config --global core.editor emacs -nw is not the solution.

I do need to use basic git for now.

3
  • 2
    Do you know about magit? It makes basic git operation a breeze from within Emacs. magit.vc
    – Tyler
    Commented Mar 29, 2016 at 2:04
  • 2
    Yep. Can't use it for now. After the class is over I'll level up to magit.
    – MarMar
    Commented Mar 29, 2016 at 2:14
  • You should describe what happens when you add "-nw" instead of simply stating that it "is not the solution". It works for me, when the command is escaped properly.
    – asjo
    Commented Mar 29, 2016 at 10:55

2 Answers 2

38

When you run git config --global core.editor emacs -nw, your shell splits the command line into words before invoking git. Git thus sees "emacs -nw" as two separate arguments. It only needs one to put into the config file, so the other is ignored. (Actually, that's a lie but you can check the man page for details.) You can put quotes around a series of words to tell your shell not to break them up: git config --global core.editor "emacs -nw" will give "emacs -nw" to git as a single argument which will do what you want.

3

You do not specify what's wrong with opening a new GUI emacs window. If the problem is the long startup time you may consider using emacsclient as your editor. In a nutshell you run (server-start) in your emacs init file and keep your regular GUI emacs open, and then tell git to use an editor called emacsclient. What happens is that the edited file pops up in a new buffer in your running emacs. After you are done with it you press C-x # to finish the emacsclient session and then git (or other shell process that started the editor) knows that the editor "emacsclient" is done with the file and continues with its thing. ("emacsclient" is also one word, so it solves your immediate problem too)

Even when your editing has to be done in the terminal window you can run emacsclient -nw and eliminate the long startup time. There are more possibilities, man emacsclient is a good read.

4
  • 1
    (would've been better as a comment on the above answer, but not allowed to post comments ) Commented Mar 31, 2016 at 9:34
  • I've been looking everywhere for this, totally happy it's an answer :)
    – AER
    Commented Apr 11, 2018 at 3:43
  • The main issue I have is that it doesn't always return the focus to the terminal after exiting emacs. There are situations where the focus is never returned, like when you have a window set as always on top, that window seems to snag the focus after exiting emacs.
    – rtaft
    Commented Sep 16, 2020 at 18:01
  • I could save and close only with C-x C-c instead. The # is on a shift-position, perhaps the shortcut does not work then? Commented Dec 13, 2021 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.