11

When using multi-term to run a terminal within emacs, I would like to be able to paste a command into the multi-term window, and then run it. Currently, when I do so, the pasted item does appear in the multi-term input window, however, if I hit enter, the command is ignored. It also doesn't show up in the terminal's history. For example, I'm pasting

echo "hello"

It looks like it worked--I see the text following the prompt. But when I hit enter it doesn't execute. I'm using multi-term: http://www.emacswiki.org/emacs/MultiTerm

2 Answers 2

15

The default function yank doesn't work with multi-term or more precisely with term-mode because the yank isn't « really » inserted. To paste, you've to use the function term-paste which is bound to S-insert by default. Of course, you can bind C-y to use it in term-mode

(add-hook 'term-mode-hook (lambda ()
                            (define-key term-raw-map (kbd "C-y") 'term-paste)))
4
  • 1
    I added this to my .emacs, but no joy.
    – ebeland
    Jan 14, 2012 at 14:45
  • @ebeland: I've tried it with -q and it works, thus something must be wrong with your configuration. To try it: emacs -q then switch to the *scratch* buffer and paste (or write) the previous snippet in and evaluate it (with C-x C-e or M-x eval-buffer RET) then load multi-term.el and start a new term with M-x multi-term.
    – Daimrod
    Jan 14, 2012 at 15:23
  • I'll give it a shot on Monday when I get in. Thanks for the help!
    – ebeland
    Jan 14, 2012 at 15:29
  • The key piece of info here I needed was term-raw-map not term-mode-map.
    – Andy
    Nov 19, 2015 at 6:44
10

In term-mode (which multi-term uses) there are two input modes:

  • line mode
  • char mode

You can switch to line mode with C-cC-j then yank the text, switch back to char mode C-cC-k and run the command. I think of char-mode as the input mode that works like you would expect terminal input to work. For example, if you type something on the command line and cut it with C-x, then C-y will paste what you cut from the command line. I think of line-mode as the input mode that you would expect from a text buffer in emacs.

For details about the two input modes check this page

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.