I found the following command in my .zshrc, probably copied from some website:

bindkey " " magic-space # do history expansion on space

The manpages are about as helpful as the very succinct comment:

    Perform history expansion and insert a space into the buffer. [...]

So what does magic-space actually do? Under which circumstances can I see this history expansion in action?

1 Answer 1


magic-space performs history expansion: if you type a space after a command that starts with ! (or ^) to refer to (part of) a previous command, that history reference is expanded. If you just type a space, the history reference is expanded when you press Enter.

$ zsh -f
% echo hello
% !1 world
echo hello world
hello world
% bindkey " " magic-space
% !1

At this point, press Space, and the line turns to

% echo hello ¡

where ¡ represents the posititon of the cursor.

  • Maybe this is obvious for most users of the shell, but I had to go looking for this property. It was set in .oh-my-zsh/lib/key-bindings.zsh with some misleading comment: bindkey ' ' magic-space # [Space] - don't do history expansion Apr 6, 2023 at 8:11

You must log in to answer this question.

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