On 2024-06-04 17:33, Lawrence Velázquez wrote:
I was reading 'info zsh history'Ok, at least that's clear. I should be using 'info zshbuiltins'. 'History Expansion' ... I'm taking that to be what the history command does so ... actually now that I look closely, it's obviously the wrong place. And 'run-help history' goes somewhere else entirely.That shows the "History Expansion" section of the manual, which does not mention the "history" builtin at all.
In general, the ! is followed by a selector that determines which item from the history you want to copy from. This can be an item number (which matches the one shown by history/fc -l), another ! (which means the most recent command), or a prefix string (which refers to the most recent command starting with that prefix, e.g. !ls to refer to the most recent ls command). The selector can be followed by modifiers to restrict the expansion to just part of the command: :0 for the command name, :* for the arguments without the command name, :$ for just the last argument, etc. The !!:$ _expression_ (last word of the last command) is so common that it got its own shortcut, the !$ I used above.zsh% vi path/to/some/filezsh% gcc !$ # compile the file I just edited