Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a setting that will make it so that when i hit the up arrow, zsh shows commands i have recently edited. The catch is, i only want unique commands. Currently, if i type echo "hello world" 50 times, i have to press up arrow 50 times to get the command i used before typing the echo command. This is annoying to say the least.

Any thoughts on what setting i need to enable/disable?

share|improve this question
up vote 8 down vote accepted

HIST_IGNORE_ALL_DUPS will throw out all previous matches of the command, which can be confusing when using the history as a log of what you did later.

A closer fit to your needs is probably the HIST_IGNORE_DUPS or even the HIST_FIND_NO_DUPS option.

See man zshoptions | less -p History:

HIST_FIND_NO_DUPS: When searching for history entries in the line editor, do not display duplicates of a line previously found, even if the duplicates are not contiguous.

HIST_IGNORE_ALL_DUPS: If a new command line being added to the history list duplicates an older one, the older command is removed from the list (even if it is not the previous event).

HIST_IGNORE_DUPS: Do not enter command lines into the history list if they are duplicates of the previous event.

share|improve this answer
HIST_FIND_NO_DUPS is a better answer than mine I think. – Mikel Apr 20 '11 at 21:27
@Mikel: Agreed. Thanks to both of you :) – Lee Olayvar Apr 21 '11 at 4:06

I can't see any way to literally only do that, but if you set the HIST_IGNORE_ALL_DUPS option, only the most recent version of a command will be retained in history, giving you the same effect.

See man zshoptions for details.

share|improve this answer
Works great! Unless i am missing something, this is exactly what i wanted :) – Lee Olayvar Apr 20 '11 at 16:35

You must log in to answer this question.

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