Yanking text into a terminal running in Emacs

前端 未结 3 634
北荒
北荒 2021-01-04 10:26

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

相关标签:
3条回答
  • 2021-01-04 10:59

    In the buffer with the terminal running, put the terminal into line mode with C-c C-j. To paste in your text, now press S-Insert (that's Shift-Insert). If you need the terminal to go back to char mode afterwards, it's C-c C-k.

    0 讨论(0)
  • 2021-01-04 11:10

    When all else fails I just highlight the text and click Edit->Copy then right click in the other emacs buffer and click paste.

    0 讨论(0)
  • 2021-01-04 11:18

    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.

    0 讨论(0)
提交回复
热议问题