149

I'm using Ubuntu 11.10 (Oneiric Ocelot). When I type the command "emacs" in the terminal, it opens Emacs as a separate window. How can I open it inside the terminal, like the nano editor?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jyriand
  • 2,434
  • 3
  • 23
  • 28
  • As always when I see a such question, I wonder why you would want to do that. With a graphical emacs you could use every fonts you want, nice colorscheme, use the image support, etc … – Daimrod Jan 05 '12 at 19:40
  • 34
    @Daimrod: sometimes a new window popping up harrasses the concentrated mind. Sometimes you want to do a quick one in an existing window and sometimes you want to reserve a whole room for your thing. – mike3996 Jan 05 '12 at 22:24
  • 11
    @Daimrod because sometimes you're editing files across two ssh hops on a slow link and the X version of emacs is too much for your connection. – Trebor Rude Mar 05 '15 at 22:07
  • 3
    Also, one might want to practice using Emacs in terminal mode. – cammil Oct 30 '16 at 09:50
  • 2
    @Daimrod it's also useful for pairing across a service like tmate – Paul Byrne May 11 '19 at 05:45
  • I keep a session log of every terminal session I run so that I leave an audit trail for myself. When emacs launches in a separate window, everything goes out-of-band. When I run emacs within the terminal, I'm more able to discern when I left it and what I did. – Tom Stambaugh Oct 05 '21 at 14:26
  • If I want to use a graphical editor or IDE, I'll do so. I use emacs when I want to edit plain text with NO magic. – Tom Stambaugh Oct 05 '21 at 14:28

8 Answers8

250

Emacs takes many launch options. The one that you are looking for is emacs -nw. This will open Emacs inside the terminal disregarding the DISPLAY environment variable even if it is set. The long form of this flag is emacs --no-window-system.

More information about Emacs launch options can be found in the manual.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jeff Foster
  • 43,770
  • 11
  • 86
  • 103
53

Just type emacs -nw. This won't open an X window.

topskip
  • 16,207
  • 15
  • 67
  • 99
34

In the spirit of providing functionality, go to your .profile or .bashrc file located at /home/usr/ and at the bottom add the line:

alias enw='emacs -nw'

Now each time you open a terminal session you just type, for example, enw and you have the Emacs no-window option with three letters :).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2820579
  • 3,261
  • 7
  • 30
  • 45
14

If you need to open Emacs without X:

emacs -nw
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
speeves
  • 1,358
  • 9
  • 10
5

I didn't like the alias solution for my purposes. For one, it didn't work for setting export EDITOR="emacs -nw".

But you can pass --without-x to configure and then just the regular old Emacs will always open in terminal.

curl http://gnu.mirrors.hoobly.com/emacs/emacs-25.3.tar.xz
tar -xvzf emacs-25.3.tar.xz && cd emacs-25.3
./configure --without-x
make && sudo make install
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eric Ihli
  • 1,722
  • 18
  • 30
2
emacs hello.c -nw

This is to open a hello.c file using Emacs inside the terminal.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
muhe
  • 109
  • 7
1

It can be useful also to add the option --no-desktop to avoid launching several buffers saved.

adolflow
  • 51
  • 3
1

Try emacs —daemon to have Emacs running in the background, and emacsclient to connect to the Emacs server.

It’s not much time overhead saved on modern systems, but it’s a lot better than running several instances of Emacs.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2497
  • 111
  • 3