Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Emacs, how can I paste into multi-term

Tags:

emacs

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

like image 280
ebeland Avatar asked Jan 04 '12 15:01

ebeland


People also ask

What is the command to paste the lines in the buffer into the text after the current line in Emacs?

In a GUI version of Emacs, click the Edit menu (or hit F10 if it's not visible), then move the mouse over “Paste from Kill Menu”, and you will see many of the recent entries. You can click on one to paste it. In a text-only version of Emacs, you achieve the same thing by navigating with keys instead of a mouse.

How do you copy and paste in Doom Emacs?

If you would only like to copy the selected region, this can be done by hitting Alt + w. To cut, or kill, the text, you can use the keys Ctrl + k to kill a particular line, or the Ctrl + w command to kill the entire selected region. To paste, or yank, the text, press the keys Ctrl + y.


2 Answers

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)))
like image 133
Daimrod Avatar answered Oct 05 '22 22:10

Daimrod


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

like image 39
jrm Avatar answered Oct 05 '22 23:10

jrm