0

In Terminal, I can erase the entire input by Ctrl-U, without invoke it. Is there such a command in Eshell?

Nick
  • 8,451
  • 13
  • 57
  • 106

1 Answers1

1

You're looking for eshell-kill-input, which is bound to C-c C-u by default.

I don't think that eshell natively supports killing the entire input string (it only kills the text between point and the prompt), but some advice should take care of that:

;;; For Emacs 24.4 and later
(defun eshell-kill-input--go-to-eol ()
  "Go to end of line before killing input"
  (end-of-line))

(advice-add 'eshell-kill-input :before #'eshell-kill-input--go-to-eol)

;;; For Emacs versions before 24.4
(defadvice eshell-kill-input (before go-to-eol ())
  "Go to end of line before killing input"
  (end-of-line))
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Almost, `C-c C-u` just kills the text before I move the cursor. For example, when I type `a bad command`, and `C-a` to the beginning, modify the input as `not a bad command`. `C-c C-u` just kills `not`, while in a Terminal, `C-u` kills all. – Nick Nov 30 '14 at 00:00
  • @Nick, good point. I've updated my answer to include some advice that can be used to kill the entire input string. – ChrisGPT was on strike Nov 30 '14 at 18:33
  • Thank you. Since I need to go to the end of line before I can kill-input, the keystroke would be: `C-e C-c C-u`. I'd use `C-a C-k` instead. By the way, is there major improvement in Emacs 24.4? I'm using 24.3. – Nick Dec 01 '14 at 03:00
  • @Nick, the advice I put in my answer should make `eshell-kill-input` automatically handle your use case. You don't need to `C-a C-k` or `C-e C-c C-u`; simply `C-c C-u` will work. – ChrisGPT was on strike Dec 01 '14 at 03:01
  • I put your code in my `.emacs` and restarted Emacs, unfortunately, it didn't work. (I'm using `GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-08 on lamiak, modified by Debian` , and I used the second part of your code: `for Emacs version before 24.4....`) Thank you for your kindly help all the same. – Nick Dec 01 '14 at 08:54
  • @Nick, strange, that snippet works just fine for me on almost the exact same version of Emacs. Perhaps something else in your config is conflicting? Try it from `emacs -Q`. – ChrisGPT was on strike Dec 01 '14 at 12:34
  • Yes, you're right. I tried `emacs -Q`, and evaluated your code, this time, `C-c C-u` worked. There must be some conflicts in my `.emacs` file:( – Nick Dec 01 '14 at 13:45
  • I moved your code in front of other configurations related to `Eshell`, and it works. The order is important. Thank you! – Nick Dec 01 '14 at 13:52