In zsh
, I have alt+. bound to insert-last-word
.
When I press alt+., I can list through the last word of previous commands.
How can I exclude some words from being shown when I cycle through ?
ie, if this is my history:
echo
foo
ls
and I want to ignore foo
, then alt+. should skip foo
.
Best Answer
I’ve tested this and it works:
What this does:
insert-last-word
implementation with the functionsmart-insert-last-word
, which is distributed with Zsh, but not loaded by default.insert-last-word
widget to match any word (*
), but not any word that contains the wordlast
or the literal wordmatch
.EXTENDED_GLOB
is required to be able to use the~
("but not") operator.Of course, it's up to you to replace that pattern in the last line with something that excludes all the words or patterns that you never want to be inserted. ?