Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yanking text into a terminal running in Emacs

I am unable to yank text into a terminal running in Emacs.

This is my procedure:

I killed the string "date" from one buffer and yanked it into the terminal in another buffer and hit return.

The terminal behaves as if I typed nothing. It just returns the prompt back.

I am using OS X 10.5.8 and Emacs 23.1. I have tried this procedure on Aquamacs, Carbon Emacs, and the release from http://emacsformacosx.com/. They all show this weird behaviour even in their default configurations with my .emacs file empty. What could possibly be causing this?

like image 416
hekevintran Avatar asked Jun 05 '10 03:06

hekevintran


People also ask

How do you yank text in Emacs?

Ctrl-y - This command will yank back the text which was deleted most recently with the above command. The text will be placed at the current emacs cursor location. You can yank back the text as many times as you wish. Meta-y - When you kill or copy a region of text, it doesn't forget about previous kills.

How do you copy text in Emacs terminal?

When you copy and paste text, the terminal does it : you're taking the text that the terminal displays and not the text that is in your emacs app. That's why you have to use terminal keybindings : Ctrl-Shift-C and Ctrl-Shift-V to copy and paste text.

How do I copy and paste in emacs terminal?

Copying in EmacsCopying can be achieved by doing a cut (kill) followed either by an undo (C-x u) or by a yank (paste) (C-y), or by selecting text (either with mouse or keyboard) then doing kill-ring-save (M-w).

How do I copy text from Emacs to clipboard?

An Emacs copy is the command kill-ring-save (usually bound to M-w ). A system copy is what you typically get from pressing C-c (or choosing "Edit->Copy" in a application window). An X copy is "physically" highlighting text with the mouse cursor. An Emacs paste is the command yank (usually bound to C-y ).


1 Answers

By "in a terminal" I assume you mean you're running Emacs's built-in terminal emulator. Ordinarily, the terminal emulator transmits most keys exactly as typed to the shell process. Type C-c C-j in the terminal buffer to put it into a state where ordinary Emacs key bindings are available. You'll see the mode line change from (Term: char run) to (Term: line run).

Addendum:

Yanking text without leaving char mode is a little tricky; the relevant function, however, is term-paste (not yank, which merely inserts the text into the terminal buffer without sending it to the inferior process). term-paste will immediately send the most recent kill to the inferior process, but doesn't provide the fancy yank functionality you're probably used to (like M-y to cycle through prior kills). You could run term-paste as an extended command: C-c M-x term-paste RET.

Probably the easiest solution is just to temporarily go into line mode (C-c C-j) when you have something to paste, and then immediately go back into char mode (C-c C-k). Or even easier, just stay in line mode all the time. I often do this when I have a terminal logged into an Oracle SQL*Plus session. I rarely notice the difference, but I get all sorts of convenient Emacs functionality, like being able to type M-p to cycle through a long, previously-typed SQL statement.

I would have assumed that you could always start off in line mode like this:

(add-hook 'term-mode-hook 'term-line-mode)

...but it doesn't work for me. Don't know why.

like image 50
Sean Avatar answered Nov 16 '22 00:11

Sean