1

When I use ansi-term mode in Emacs, and run a program such as cat, ^D does not end the input like it normally does. If fact, it doesn't seem to do anything at all.

^C still works.

I have Evil installed

Functino
  • 1,939
  • 17
  • 25

2 Answers2

5

ansi-term has two different input submodes. To send a literal C-d in the default (character) mode, just press C-d. However, if you are in line mode, you need C-c C-d. Or you can switch to character mode with C-c C-k (and back to line mode with C-c C-j).

See also the documentation.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Unfortunately, C-c C-d drops me into a "List directory (brief):" prompt, and C-c C-k just kills my keyboard input. Maybe having Evil installed messed it up (probably should have mentioned that)? In any case, it looks like I'm not going be using much Emacs, but thanks for answering! – Functino Dec 01 '14 at 19:58
  • See also now http://stackoverflow.com/questions/28567522/use-ctrl-x-commands-while-in-terminal-in-emacs/28567771#28567771 where this answer fits better. – tripleee Feb 17 '15 at 17:50
1

Try adding these to your config (after you load evil):

(delete 'term-mode evil-insert-state-modes)
(add-to-list 'evil-emacs-state-modes 'term-mode)

On my emacs with this modification, cat followed by ^D in ansi-term char-mode ends the input and bring me back to the prompt. Make sure you know the difference between char-mode and line-mode like tripleee mentioned!

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
  • I completely forgot about this question, and haven't used Emacs in a long time. Thanks for providing the solution, though! – Functino Apr 02 '15 at 00:59
  • This will completely disable evil while in term-mode. To instead change the behavior of '^D' to insert that character while in evil-insert-state (in any mode), use `(define-key evil-insert-state-map (kbd "C-d") 'self-insert-command)`. – Skyler Ferris Dec 20 '20 at 01:02