1

(See my previous question for additional context).

I'm migrating to zsh from bash, and using oh-my-zsh. When my zsh history looks something like the following:


git status
git add -A
git commit

I want to be able to re-run git add -A. To do that, I could use !?git add, which should:

!?str[?] Refer to the most recent command containing str. The trailing ‘?’ is necessary if this reference is to be followed by a modifier or followed by any text that is not to be considered part of str.

The link for zsh event designators is here.

Unfortunately, I can't do this - as I'm typing !?git add, as I hit the ' ', it auto-completes the command to the most recent command matching git (ie, it auto-completes with git commit). I can't use the event designator properly because of this auto-completion as I hit the space.

I assume this is an oh-my-zsh feature. I have no idea where to look, though - greping for 'complet' in the oh-my-zsh source doesn't get me anywhere.

My question: how do I turn off this feature? Or, if that's not something that's known, where should I be looking - if I was going to implement this auto-complete when whitespace is entered, where would be a logical place to do so in the oh-my-zsh framework?

2 Answers 2

1

Look in oh-my-zsh/lib/key-bindings.zsh and you'll see the line

bindkey ' ' magic-space    # also do history expansion on space

comment it out to remove this feature.

0
0

There are a few other ways to skin this cat:

!{?git add?}

The open braces will let suppress the magic-space expansion on the first space and then if you use tab after the close brace it will expand on the same line, like magic. Of course !{?git a?} would be enough.

!?add

You don't need the git at all, in this case at least. After the second d you can either hit return or tab. If there's a lot of history between you and the command, this would find the three characters add at any point in the command so that might be a problem.

zsh history expansion is detailed in the docs at:

http://zsh.sourceforge.net/Doc/Release/Expansion.html#History-Expansion

You must log in to answer this question.

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