Eshell and YASnippet: Making TAB Work

2026-07-06

After reading the following blog posts, I wanted to try using yasnippet in eshell.

Unfortunately, in 2026, it wasn't a simple matter of just enabling yas-global-mode to get YASnippet to work. I can manually M-x yas-expand but TAB only did eshell's default completion. To make the TAB key perform yas-expand while in eshell, I had to add the following Elisp ot my config.

(defun enable-yas-completion-at-point ()
  "Add `yas-expand' to `completion-at-point-functions'."
  (interactive)
  (add-to-list 'completion-at-point-functions #'yas-expand))

;; Make eshell try yas-expand before it does tries its other completions.
(add-to-list 'eshell-mode-hook #'enable-yas-completion-at-point)

Previously, I had bound yas-expand to a free keybinding that wasn't TAB, but that didn't feel right. This new way feels better. Now TAB in eshell will try to yas-expand first and then fall back to eshell's default completion behavior.