7

In zsh with oh-my-zsh you can enter a history expansion command and press either space, tab, or enter, and it will expand out. For example:

ls /path/to/some/directory
cd !$<enter>

would expand to

cd /path/to/some/directory

But it does not actually execute the command. It remains on the prompt for further editing and you need to press enter a second time to actually run the command.

I was installing arch linux last night and found that the zsh settings the install shell comes with has history expansion on tab and space, but pressing enter runs the expanded command immediately without requiring the user to press enter again.

This is what I want because it saves me a key press. If I want to edit the expansion, I could press tab. If I want to run the command immediately I could press enter.

I think it's something to do with magic-space, and I see the following line in .oh-my-zsh/lib/key-bindings.zsh

bindkey ' ' magic-space        # [Space] - do history expansion

But I can't find where enter and tab are also bound to expansion or if there's some option to run the command immediately on enter.

1 Answer 1

7

This has been bothering me for years since I started using zsh, but I finally spent the time to keep digging until I figured it out and it's caused by the HIST_VERIFY option. The option is enabled in .oh-my-zsh/lib/history.zsh and needs to be overridden.

Adding the following line to .zshrc fixes the behaviour:

unsetopt HIST_VERIFY

From man zshoptions:

HIST_VERIFY

Whenever the user enters a line with history expansion, don't execute the line directly; instead, perform history expansion and reload the line into the editing buffer.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .