I use ansi-term on Emacs and need to paste some words there. "Paste" only works with mouse mid-button. I know that with C-x C-j
and C-c C-k
, we can switch between char run
and line run
, but it is inconvenient. I prefer to use C-y
or C-c y
to do the job. Searched online but the solutions didn't work with my emacs23.
Asked
Active
Viewed 735 times
4

snowgoose
- 165
- 1
- 9
-
My comments are in following one. – snowgoose Feb 27 '13 at 01:39
-
I found this solution works for me: [link: paste into multi-term](http://stackoverflow.com/questions/8729462/in-emacs-how-can-i-paste-into-multi-term) – snowgoose Feb 27 '13 at 01:41
1 Answers
2
There's two options here: use the inferior process or Emacs.
To use the inferior process (probably something that uses readline), just send raw C-y
characters.
(define-key term-raw-map (kbd "C-k") 'term-send-raw)
(define-key term-raw-map (kbd "C-y") 'term-send-raw)
Then C-k
and C-y
get sent directly to the terminal, where they function like they would in any other terminal (e.g. kill to end of line and yank, respectively). Since the inferior process is receiving and interpreting the keypresses, Emacs will have nothing to do with the kills and yanks.
To use Emacs's kill ring, use term-paste
.
(define-key term-raw-map (kbd "C-c C-y") 'term-paste)
Personally, I like to treat term-mode
buffers like regular terminals, so I usually use the mouse to copy/paste and C-k
/C-y
when I'm editing a command line.
FWIW, I use multiterm, and I do
(with-eval-after-load "multi-term"
(dolist
(bind '(("C-k" . term-send-raw)
("C-y" . term-send-raw)
("C-c C-y" . term-paste)
))
(add-to-list 'term-bind-key-alist bind)))

jpkotta
- 9,237
- 3
- 29
- 34
-
There are two problems with this: `term-mode-map` should be `term-raw-map`, and `term-send-raw` should be `term-paste`. Then binding `C-y` (and `s-v` if you're on OS X) will work as expected. – Andy Nov 19 '15 at 06:47
-
Without diving into it, you seem right about the map. As for the binding, I guess it depends on what you want. I'll update the answer. – jpkotta Nov 20 '15 at 16:35