Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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