5

In ansi-term mode, is there a way to copy the command output? This is quite easy in eshell, but sometimes eshell behavors not exactly the same with bash. For example:

  1. eshell doesn't know how to auto-complete sudo apt-... command.
  2. eshell requires to input password each time I run a sudo command.

So I have to use ansi-term from time to time.

Nick
  • 4,423
  • 4
  • 24
  • 41
  • If your only problems are those two listed above you can also use `shell` instead of `eshell`. I only use `ansi-term` when I run ncurses applications. –  Jan 15 '15 at 10:06

1 Answers1

5

C-c C-j to activate term-line-mode, then, the terminal buffer act more like a normal text-buffer. Switch back to character mode with C-c C-k.

You may be intersted by this function that will help you toggle, between the two modes:

(require 'term)

(defun jnm/term-toggle-mode ()
  "Toggles term between line mode and char mode"
  (interactive)
  (if (term-in-line-mode)
      (term-char-mode)
    (term-line-mode)))

(define-key term-mode-map (kbd "C-c C-j") 'jnm/term-toggle-mode)
(define-key term-mode-map (kbd "C-c C-k") 'jnm/term-toggle-mode)

(define-key term-raw-map (kbd "C-c C-j") 'jnm/term-toggle-mode)
(define-key term-raw-map (kbd "C-c C-k") 'jnm/term-toggle-mode)

Courtesy of Joel's Journal

Nsukami _
  • 6,341
  • 2
  • 22
  • 35
  • Wow, `C-c C-k` and `C-c C-k` solved my problem well. The function mean no matter in what mode, just use `C-c C-j` toggle the two mode. (and `C-c C-k` works the same way), right? But the default Emacs `C-c C-k` always go back to term-mode is more straight forward. – Nick Dec 20 '14 at 14:13
  • @Nick I don't really understand your point :\ – Nsukami _ Dec 20 '14 at 16:30
  • My apologize. I made a typo in the previous comment. I mean since `C-c C-j` and `C-c C-k` toggle the two mode well, why Joel write a function to map them in both mode? Does he want to toggle no matter whether `C-c C-j` or `C-c C-k` are pressed? – Nick Dec 21 '14 at 00:36
  • @Nick, yes, that is exactly what he wants, toggle whatever the command used, probably because it may be hard to remember what command to use. It is just a suggestion, you're not obliged to use this. – Nsukami _ Dec 21 '14 at 01:23
  • I see. Thank you for you answer and explanation. Really helpful! – Nick Dec 21 '14 at 01:30