7

Of course when I am in Terminal and I press the up arrow key, it goes to the previous command. However, when I hit the M-x keys and type shell an integrated shell comes up in Emacs:

Shell in Emacs

However, if I type a command and press up, this happens:

When I press the up button in Shell Emacs

How do I get back to the last command I typed?

  • You can also go up with navigation keys to the line with the command you want to execute and hit RET. Of course C-up is much easier. – giordano Oct 20 '14 at 16:21
15

The function that cycles backwards through input history, saving input. is comint-previous-input

It is bound to C-up, M-p.

4

Just found an answer on Super User:

How do you run the previous command in emacs shell?

M-p goes to the previous command.

  • This is much easier and user friendly – Billal Begueradj Apr 15 '18 at 8:56
3

My favorite commands for cycling through shell command history are comint-previous-matching-input-from-input and comint-next-matching-input-from-input. If the prompt is empty, they will behave exactly like comint-previous-input and comint-next-input cycling through all history items. Though if you have entered rake, for example, they will cycle through your shell command history of commands starting with rake.

By default these are bound to C-c M-r and C-c M-s respectively, but I find those not ideal. I'm personally binding them to M-TAB and <M-S-tab>.

3

You could use helm-eshell-history for interactive history selection, and replace the original C-c C-l:

(require 'helm-eshell)

(add-hook 'eshell-mode-hook
          #'(lambda ()
              (define-key eshell-mode-map (kbd "M-l")  'helm-eshell-history)))

;; for shell-mode
(define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring)

helm-eshell-history

1

Another possibility, if you use Icicles: Use C-c TAB (command icicle-comint-command) to choose a previously entered command with completion (or cycling).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.