What is multi-term.el ?

MultiTerm is a mode based on term.el, for managing multiple terminal buffers in Emacs.

Why the need for multi-term.el ?

By default, term.el provides a great terminal emulator in Emacs. But I have some troubles with term-mode:
    1. term.el just provides commands ‘term’ or ‘ansi-term’ for creating a terminal buffer. There is no special command to create or switch between multiple terminal buffers quickly.
    2. By default, the keystrokes of term.el conflict with global-mode keystrokes, which makes it difficult for the user to integrate term.el with Emacs.
    3. By default, executing the *NIX command “exit” from term-mode will leave an unused buffer.
    4. term.el won’t quit running sub-process when you kill terminal buffer forcibly.
    5. It doesn’t have a dedicated window for a debugging program.
And multi-term.el is enhanced with those features.


Put Lisp:multi-term.el in your load-path, then add
        (require 'multi-term)
in ~/.emacs .
        (setq multi-term-program "/bin/bash")
in ~/.emacs .
Or any shell program you like. 😊
That’s all.


I found that some some people like to run emacs-within-emacs by calling “emacs -nw” inside a multi-term.el (though surely this is just for bragging rights!). However, by default the prefix keys “C-x” and “C-c” are unbound by multi-term (that is, they are processed by the host Emacs). But this means that you can’t quit your nested emacs session with “C-x C-c”. If if you want to do this, remove “C-x” and “C-c” from option ‘term-unbind-key-list’, and remove “C-c C-c” from the option ‘term-bind-key-alist’.

You may have to experiment to get the behavior you want.


multi-term.el provides the following interactive functions:


                (defun multi-term-foo ()
                  "Make a multi-term buffer running foo."
                  (let ((multi-term-program "/bin/foo"))


All options below can be customized by: M-x RET customize-group RET multi-term RET .

“multi-term-program” default is nil, so when create a new terminal buffer, it will try to take the shell path from an environment variable (“SHELL”, “ESHELL”, and finally default to “/bin/sh”). If you failed to create a terminal buffer, make sure setup this option with a valid shell program.
“multi-term-default-dir” default is “~/”. This is only used when the current buffer is not in a real directory.
“multi-term-buffer-name” is the base name of terminal buffer, with format *terminal<index>*.
“multi-term-scroll-show-maximum-output” if non-nil, show maximum output when the window is scrolled. Otherwise, don’t show.
“multi-term-scroll-to-bottom-on-output” if non-nil or ‘all’, scroll all windows to bottom. If ‘this’, scroll only the selected window. If ‘others’ scroll only those that are not the selected window.
“multi-term-switch-after-close” try to switch to another ‘multi-term’ buffer after closing the current one. If you don’t like this feature just set it with nil.
The keystroke list to unbind when terminal is created.
The format is ‘(“KEY-A” “KEY-B” “KEY-C”)
The keystroke alist to bind when terminal is created.
The format is ‘((“KEY-A” . COMMAND-A) (“KEY-B” . COMMAND-B) (“KEY-C” . COMMAND-C))
“multi-term-dedicated-window-height” is the height of the dedicated terminal window.
“multi-term-dedicated-max-window-height” is the maximum height limit for the dedicated terminal window.
“multi-term-dedicated-skip-other-window-p” controls whether to skip dedicated terminal window when using the command ‘other-window’ to cycle through windows. This useful when you have complex window layout for programming. Note that you can use the command “multi-term-dedicated-select” to select the dedicated window in any time.
“multi-term-dedicated-select-after-open-p” Default, multi-term won’t focus terminal window after you open dedicated window. Please make this option with t if you want focus terminal window.


Have many people asked “How to setup color of multi-term?”, option ‘term-default-bg-color’ and ‘term-default-fg-color’ control foreground color and background color, so just setup like below:
     '(term-default-bg-color "#000000")        ;; background color (black)
     '(term-default-fg-color "#dddd00"))       ;; foreground color (yellow)
The plain old ‘term’ command never creates a new term buffer, if one already exists. On the other hand, ‘multi-term’ always creates a new one. Both behaviors are limiting when it comes to keybindings. For most of the time, when a user presses a button to get himself a terminal, he expects one he was working with before (otherwise he would probably close it earlier), but sometimes he wants a fresh new one. The following code either switches to the term buffer used last or creates a new one, if a term buffer is already selected.
    (defun last-term-buffer (l)
      "Return most recently used term buffer."
      (when l
  (if (eq 'term-mode (with-current-buffer (car l) major-mode))
      (car l) (last-term-buffer (cdr l)))))

    (defun get-term ()
      "Switch to the term buffer last used, or create a new one if
    none exists, or if the current buffer is already a term."
      (let ((b (last-term-buffer (buffer-list))))
  (if (or (not b) (eq 'term-mode major-mode))
    (switch-to-buffer b))))