1

I want to be able to copy paste using C-c and C-v when I edit a file and in multi-term. After more than a few hours I gave up. I would be thankful if anyone could tell me what the recommended way for doing something like this is. Here are some of the things I tried:

  1. Putting

    (local-set-key (kbd "C-c") 'kill-ring-save)
    (local-set-key (kbd "C-x") 'kill-region)
    (local-set-key (kbd "C-v") 'yank)
    

in my find-file-hook. This works for C-x and C-v but doesn't work for C-c. (I think this is because of the C-c C-... keybindings, but I don't know if there is some way to just overwrite those).

  1. Defining a function that uses

    (if (or (eq major-mode 'term-mode) (eq major-mode 'eshell-mode)) 
    

to detect whether we are in a terminal or a file and then deactivates cua-mode or activates it. I added this function to some hooks but it got buggy, because this function was either called not enough or too often. Also

(add-to-list 'term-bind-key-alist '("some binding" . some command))

works for C-v and C-x but not for C-c.

Note: I know that C-c is normally terminal interrupt, but I put a stty intr ^J in my .bashrc.

  1. Using eshell instead of multi-term: The Problem with the eshell is, that it's autocompletion is not as good as the autocompletion of bash. Bash can e.g. autocomplete git chec to git checkout.

Note: I know that normal Emacs users use M-w and and C-y to copy-paste, but this would mess up my muscle memory when working with programs that use C-c C-v top copy-paste.

UPDATE: The following works:

(global-set-key (kbd "C-v") 'yank)
(global-set-key (kbd "C-x") 'kill-region)
(define-key input-decode-map (kbd "C-c") (kbd "M-w"))
(add-to-list 'term-bind-key-alist '("C-v" . term-paste))

Why is emacs so unnecessarily complicated?

4
  • 1
    1. There are multiple questions in this question. Please post separate questions for them. 2. For C-c, C-x, C-v you likely want to use cua-mode -- C-h r g cua-mode.
    – Drew
    Jun 9, 2019 at 19:00
  • There is just one question in this post. How to make C-c C-v copy paste in a file and in multi-term. I know that I can activate cua-mode, but cua-mode does not work in multi-term. Jun 9, 2019 at 19:21
  • 2
    Considering that multi-term is a terminal, you'll want your shell and software you use in it set up to treat C-c and C-v the way you expect. This doesn't sound like an Emacs problem to me.
    – user12563
    Jun 9, 2019 at 20:20
  • Copy and paste is not handled by bash, but by emacs. E.g. in gnome-terminal copy is ctrl-shift-c. Jun 9, 2019 at 21:24

2 Answers 2

0

I was able to force this binding by reading the comments on the wiki. Editing the multi-term.el file (if installed via M-x package-install) (located ~/emacs.d/elpa/multi-term-1.2/multi-term.el

Remove "C-c" from the term-unbind-key-list:

(defcustom term-unbind-key-list
  '("C-z" "C-x" "C-h" "C-y" "<ESC>")
  "The key list that will need to be unbind."
  :type 'list
  :group 'multi-term)

Change the term-bind-key-alist defaults, here I'm using C-c maybe you want C-c-c:

> (defcustom term-bind-key-alist  
>    '(
>     ("C-c" . kill-ring-save)
>     ("C-p" . previous-line)
>     ("C-v" . term-paste)
>       .....

Recompile: M-x byte-recompile-directory

Restart emacs and Ctrl-V and Ctrl-C work as you want them to while in multi-term.

1
  • This works for multi-term, but I want to use C-c and C-v both in multi-term and when editing a file. Once I put a (cua-mode t) in my init.el I can't copy paste in multi-term. Jun 10, 2019 at 14:27
0

The following works:

(global-set-key (kbd "C-v") 'yank)
(global-set-key (kbd "C-x") 'kill-region)
(define-key input-decode-map (kbd "C-c") (kbd "M-w"))
(add-to-list 'term-bind-key-alist '("C-v" . term-paste))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.