Open terminal from emacs

The combination M-! allows you to launch shell commands. You could use it to launch a separate urxvt.

M-! urxvt RET

I just tried it with xterm (I don't have urxvt) and it did open in the same directory as the file in the buffer.

If you want to define a shortcut add something similar in your init file:

(global-set-key (kbd "C-c s") (kbd "M-! urxvt RET"))

In my case I bound the shortcut to: Ctrl+C - S.


I usually use M-x term.

You can also checkout:

  • M-x terminal
  • M-x shell

M-x term is effectively launching a terminal emulator written in elisp. From the help:

term
M-x ... RET Start a terminal-emulator in a new buffer. (term PROGRAM)

term is an interactive compiled Lisp function in `term.el'.

Start a terminal-emulator in a new buffer. The buffer is in Term mode; see `term-mode' for the commands to use in that buffer.

Type C-c b to switch to another buffer.


The emacs command M-x shell will start a shell in a new buffer (or switch to an existing shell buffer, if there is one). If it's a new shell buffer, it'll be started in the directory of the file being visited in the current buffer. If it's an existing shell buffer, it'll still be in the directory where you left it after last using it. In order to always get the behaviour you want, remember to kill the shell buffer when you're done with it (C-x k)

If M-x shell is too much typing, you can set a global key to start a shell for you. Something like (global-set-key (kbd "C-x S") 'shell) in your startup file should do it (but be careful not to mask another useful command with your shortcut!)

Also, be aware this is a "dumb terminal" so some commands like git commit need options like -m and passwords will be in plaintext on your screen.