26 Jan 2026
Getting Eshell nth History to Work
As much as I enjoy using Eshell, it is not without its annoyances. In this case, I’m writing about the common shell convention of using !n to recall a previously entered command.
In Eshell, entering the history command will show you all of your previously entered commands alongside a number n.
The problem is in attempting to use !n to recall a specific command in Eshell as one would do in bash or zsh. By default it will not work as described in Info (eshell) History without configuring eshell-expand-input-functions first. (My current configuration is GNU Emacs 30.2.)
To get !n to work requires adding the function eshell-expand-history-references to the customizable variable eshell-expand-input-functions.
The following configuration Elisp will achieve this.
1 2 | |
A nice feature of eshell-expand-history-references is that it will expand using the content of an actual command instead of a number reference. So !foo will invoke the last command that you entered the string “foo” in.
It’s not clear to me whether coupling nth history support to eshell-expand-history-references is intentional or a bug. If the former, then I’d consider this yet another example of staying “on brand” with Emacs’ tendency to ship with questionable defaults. That shade aside, Eshell is still an amazing package that I could not imagine using Emacs without.
Links
Past Articles
| 22 JAN 2026 |
Announcing Casual EWWAnnouncing Casual support for EWW, a web browser within Emacs. read more |
| 6 JAN 2026 |
Announcing Casual HTML & CSSAnnouncing Casual support for the HTML and CSS editing modes in Emacs. read more |
| 4 JAN 2026 |
Moment - Thursday January 01, 2026 00:06 PSTPhoto taken Thursday January 01, 2026 00:06 PST. read more |
| 30 DEC 2025 |
F16 F17 F18Binding the function keys above the number pad to window management has been a total win for me. Perhaps it might be the same for you. read more |
| 17 DEC 2025 |
Export Org to Markdown with the ClipboardA companion post to my last one on importing Markdown to Org, but the other way around. read more |
| 4 DEC 2025 |
Import Markdown to Org with the Clipboard in EmacsImport Markdown from other apps into your Org files easy. read more |
| 24 NOV 2025 |
Announcing Casual CSVIf you need to work with CSV files in Emacs, Casual with |
| 13 NOV 2025 |
Thoughts on Funding Free Software Development“I don’t like to dream about getting paid.” read more |
| 3 NOV 2025 |
Prototyping a Toolbar UI for EdebugWhere a prototype toolbar UI for Edebug is made available for public scrutiny. read more |
Page 1 / 17 >