How to run 'emacs' in the terminal emulator without a separate window?

16

6

I am looking to switch to Emacs from Vim and one thing that is keeping me away is that Emacs opens up a separate window of its own when run under X. Can I get the same behavior for Emacs as it does when not run under X? That is, I want Emacs to start the session in the same terminal as the one in which its fired.

Let me know if the question is not clear. Thank in advance!

Amit Saha

Posted 2009-12-03T10:40:42.030

Reputation: 273

Answers

34

I'm no emacs expert, but this did the trick for me:

emacs -nw

Alberto Zaccagni

Posted 2009-12-03T10:40:42.030

Reputation: 586

7You're right, for the curious -nw is short for --no-window-system which tells emacs not to use its X interface. – None – 2009-12-03T10:46:06.233

@Mic: Thanks for the explanation, this way I'll remember what it stands for – Alberto Zaccagni – 2009-12-03T10:47:29.413

16

You might prefer starting emacs as emacs --daemon and then using emacsclient -t to edit files. This keeps Emacs loaded in the background, so that you can use Emacs more like vi. Editing sessions will start up instantly, and "quitting" via C-x C-c will just close the current connection. It is very nice.

jrockway

Posted 2009-12-03T10:40:42.030

Reputation: 261

5

Although your question has been answered, I would venture to say that this is not the way any regular user would use emacs. Unlike vim, emacs generally has a longer startup time and anyway tends to be running all the time with multiple open buffers. So when you want to do something with emacs in a terminal, you invoke emacsclient -nw (assuming an emacs serverhas been started). Look at How to start to use EmacsClient for details.

Raja

Posted 2009-12-03T10:40:42.030

Reputation: 151

2

If you use bash, you can always add the following to your .bashrc

alias emacs="emacs -nw"

That's saved me a lot of typing (and cursing when I forget to type the switches).

Dick Kennedy

Posted 2009-12-03T10:40:42.030

Reputation: 21

1

Combining the above answers by Dick Kenny and Alberto Zaccagni you get the following configuration which I use in .bashrc:

alias emacs='emacsclient -nw -c -a ""'

This will try to connect to a runnning emacs daemon. If none is running, it will startup a new one, and then connect using the current terminal window.

From the docs:

-a EDITOR, --alternate-editor=EDITOR
        Editor to fallback to if the server is not running
        If EDITOR is the empty string, start Emacs in daemon
        mode and try connecting again

-nw, -t, --tty      Open a new Emacs frame on the current terminal

-c, --create-frame  Create a new frame instead of trying to 
                    use the current Emacs frame

Heinrich Hartmann

Posted 2009-12-03T10:40:42.030

Reputation: 171

1When I try this command, Emacs fails to start, instead giving me a warning about there not being a server to connect to, followed by a giant dump of values and Emacs not starting. – Koz Ross – 2016-04-07T10:23:16.713