In Emacs shell, is there a command similar to M-p but which would skip repeated commands? That is, it would go to the next different command. Similar to regular Linux terminal.

So if I were to run:


and press M-p three times, I want it to go to ls command.

Or, alternatively, how can I define a command like this?

2 Answers 2


The shell you get from M-x shell is based on comint, so you can set comint-input-ignoredups to t in order to get the behaviour you want. The help even mentions bash:

comint-input-ignoredups is a variable defined in `comint.el'.


If non-nil, don't add input matching the last on the input ring.

This mirrors the optional behavior of bash.

This variable is buffer-local.

You can customize this variable.

  • awesome, exactly what I was looking for, thanks!
    – Anton
    Commented May 6, 2018 at 19:47

You can also use M-x comint-dynamic-list-input-ring and invoked by C-c C-l. You can also set C-h v comint-input-ignoredups to t to see unique commands only in above list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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