If I create a second window with a terminal in it like:

C-x 2; C-x o; M-x ansi-term

How can I copy text from a buffer into this terminal? I seems like the ansi-terminal has its own kill-ring (maybe the killring from readline?)

Context: I use a REPL quite often for development, sometimes it's on a remote machine.

3 Answers 3


From the doc for term-mode:

The terminal emulator uses Term mode, which has two input modes. In line mode, Term basically acts like Shell mode. In char mode, each character is sent directly to the subshell, except for the Term escape character, normally C-c.

C-c C-c send a literal C-c to the sub-shell.

From the doc for shell-mode:

The major mode for Shell buffers is Shell mode. Many of its special commands are bound to the C-c prefix, and resemble the usual editing and job control characters present in ordinary shells, except that you must type C-c first.

Into ansi-term use C-x C-j to switch terminal into line mode. In this mode you could use C-y to insert content from the emacs kill ring. Switching back to character mode could be done with C-c C-k.

This happens because ansi-term mode runs custom terminal (like /bin/bash), which have its own function for keys C-k, C-y, etc. This keys works with kill ring similar to emacs kill ring but into bash. So, if you kill string into char mode (in bash) and then try to paste it, the string will be pasted, but the kill ring will be bash kill ring.

This could be helpful: https://stackoverflow.com/questions/2886184/copy-paste-in-emacs-ansi-term-shell


I used these functions for that

;; yank in term (kill-ing)
(defun term-yank-kill-ring ()
  (flet ((insert-for-yank (string) (term-send-raw-string string)))
;; yank-pop un term (kill-ring)
(defun term-yank-pop-kill-ring ()
  (dotimes (i (- (point) (mark t)))
   (get-buffer-process (current-buffer))
   (current-kill 1)))
;; shorcuts
(setq term-bind-key-alist
      '(("C-x C-y" . term-yank-kill-ring)
        ("C-x M-y" . term-yank-pop-kill-ring)))

I switch to evil-mode by pressing C-z. Then use vim key bindings to copy/paste text.

That's also my preferred way to run other REPL (js-comint, mostly).

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.