Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

magic-space
    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
add comment

1 Answer 1

up vote 3 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
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
add comment

Your Answer

 
discard

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.