Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I insert directly the text displayed in the echo area? (also wrongly called the minibuffer).

When I for example run (+ 2 2) in a buffer and execute it with C-x C-e it correctly displays the result '2' in the echo area. There is also a '2' in the Messages buffer. I'd like this '2' inserted below the line executed, in the same buffer, or something like that.

Is there a command to, for example, pipe the echo area into the buffer or copy the last line of the Messages buffer into the present working buffer?

share|improve this question
C-u C-x C-e will insert the result into the buffer. Not what you ask, but what you'd like in 2nd paragraph. – Juancho Feb 2 '14 at 17:52
@Juancho: yes, that is what I'd like. – Quora Feans Feb 2 '14 at 17:59
up vote 2 down vote accepted

In lisp-interaction-mode which is the default mode for the *scratch* buffer you can use eval-print-last-sexp bound to C-j.


In any buffer you can switch to lisp-interaction-mode with M-x: lisp-interaction-mode [RET]

Now C-j should be bound by default to eval-print-last-sexp unless the binding is shadowed by another mode. You can check the quick description of the current major-mode with C-h m.

If it is shadowed or simply not bound you can eval

(global-set-key (kbd "C-c p") 'eval-print-last-sexp)

with C-x C-e. That will bind the command to C-c p.

To make the change permanent write it in your .emacs file.

share|improve this answer
Isn't the default mode for *scratch* Fundamental? It is on my system. Or is that just a name for lisp-interaction-mode? Your eval-print-last-sexp works fine in Fundamental but C-j us not bound. – terdon Feb 2 '14 at 17:38

You need to use one of the EMACS insert commands. To accomplish what you illustrated in your simple example you would need to do the following.

(insert-string (number-to-string (+ 2 2)))
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.