Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy/Paste in emacs ansi-term shell

Tags:

shell

emacs

I have configured my emacs to run zsh shell within ansi-term. However, copy/paste no longer works i.e. nothing is getting pasted from kill-ring to the terminal. Changing the TERM to vt100, or eterm doesn't solve the problem.

Would appreciate any ideas or solution.

To provide context I have configured ansi-term as follows:

(global-set-key "\C-x\C-a" '(lambda ()(interactive)(ansi-term "/bin/zsh"))) (global-set-key "\C-x\ a" '(lambda ()(interactive)(ansi-term "/bin/zsh"))) 
like image 374
Sandeep Avatar asked May 21 '10 23:05

Sandeep


People also ask

How do I copy and paste 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.

Can you copy and paste in emacs?

To cut the text, press C-w . To copy the text, press M-w . To paste the text, press C-y .


2 Answers

You may want to simply switch between character mode and line mode while using the terminal. C-c C-j will run term-line-mode, which treats the terminal buffer more like a normal text-buffer in which you can move the cursor and yank text. You can switch back to character mode by running term-char-mode with C-c C-k.

like image 53
Kirk Kelsey Avatar answered Oct 04 '22 23:10

Kirk Kelsey


As described in this lovely blog snippet, there's a function, term-paste, in term.el, that does exactly what you want. By default it's bound only to S-insert but the blog's recommended C-c C-y seems like a good suggestion.

like image 22
Glyph Avatar answered Oct 04 '22 23:10

Glyph