0

So by default, when I use Zsh for the first time shortcuts like !! (for previous command), !$ (for last argument of previous command), !v (for last command starting with v), and so on, work like they do in Bash, ie I could do:

rm -rf /
sudo !!

(No trailing whitespace at the end of those two lines except for just hitting enter after the last character)

for instance. However I have a zshrc with oh-my-zsh and a couple of plugins that come with OMZ, as well as using the powerline10k theme, and whenever I copy my config to a new machine, after copying it over, it now works where you need to either hit enter or space in order to "expand" the shortcut, e.g. for the above example, again with no trailing whitespace just hitting enter at the end of the line, it would become three commands:

rm -rf /
sudo !!
sudo rm -rf /

You then have to hit enter again on the third line for the command to actually execute.

Or in just two lines, you would type:

rm -rf /
sudo !!

(no trailing whitespace)

And then when you type:

rm -rf /
sudo !!<SPACE>

(<SPACE> not being literal, being a representation of a space character at the end of the line)

It automatically expands to:

rm -rf /
sudo rm -rf /<SPACE><your cursor is here>

I assume this is a safety feature so you can review what your shortcut expands to before hitting enter, but honestly when this happens I just double-tap enter anyway as a reflexive thing, so it's not really adding extra security for me.

My question is: does anyone know what setting in the zshrc (or elsewhere) causes this behaviour, and how can I disable it so I can just use these shortcuts the way they work in default out-of-the-box Zsh?

(I tried to look this up, however I don't know what these shortcuts are called, and looking things up like zsh enable !! shortcut zsh enable "!!" shortcut etc just does not give you helpful results)

3
  • 1
    Is the histverify option set the same in both cases? Commented Mar 26 at 2:29
  • @steeldriver Not set in both zshrcs. Tried setting it to false but it doesn't seem to change the behaviour
    – revsuine
    Commented Mar 26 at 20:13
  • Please use less destructive examples! I can well imagine someone trying out your example, which could end up in (let's say) unintended consequences...
    – Popup
    Commented Apr 4 at 11:21

1 Answer 1

1

For space, this is caused by having space bound to the magic-space widget:

% bindkey -L ' '
bindkey " " magic-space

To disable it, restore the binding to self-insert with the following:

bindkey " " self-insert

In the case of enter, the behaviour you see is enabled with the HIST_VERIFY option. Disabling that would be with:

unsetopt hist_verify

In both cases, these are restoring what are zsh defaults. So you either need to put these at the end of ~/.zshrc, after oh-my-zsh and your plugins have initialised, or find where they are first set and see if it is possible to prevent the plugins from changing those settings.

You must log in to answer this question.

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