简体   繁体   中英

Paste a word at ansi-term on Emacs

I use ansi-term on Emacs and need to paste some words there. "Paste" only works with mouse mid-button. I know that with Cx Cj and Cc Ck , we can switch between char run and line run , but it is inconvenient. I prefer to use Cy or Cc y to do the job. Searched online but the solutions didn't work with my emacs23.

There's two options here: use the inferior process or Emacs.

To use the inferior process (probably something that uses readline), just send raw Cy characters.

(define-key term-raw-map (kbd "C-k") 'term-send-raw)
(define-key term-raw-map (kbd "C-y") 'term-send-raw)

Then Ck and Cy get sent directly to the terminal, where they function like they would in any other terminal (eg 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 Ck / Cy 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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM