Go forward to Managing the History File.
Go backward to Moving Around the History List.
Go up to History Functions.

Searching the History List
--------------------------

   These functions allow searching of the history list for entries
containing a specific string.  Searching may be performed both forward
and backward from the current history position.  The search may be
"anchored", meaning that the string must match at the beginning of the
history entry.

 - Function: int history_search (char *string, int direction)
     Search the history for STRING, starting at the current history
     offset.  If DIRECTION < 0, then the search is through previous
     entries, else through subsequent.  If STRING is found, then the
     current history index is set to that history entry, and the value
     returned is the offset in the line of the entry where STRING was
     found.  Otherwise, nothing is changed, and a -1 is returned.

 - Function: int history_search_prefix (char *string, int direction)
     Search the history for STRING, starting at the current history
     offset.  The search is anchored: matching lines must begin with
     STRING.  If DIRECTION < 0, then the search is through previous
     entries, else through subsequent.  If STRING is found, then the
     current history index is set to that entry, and the return value
     is 0.  Otherwise, nothing is changed, and a -1 is returned.

 - Function: int history_search_pos (char *string, int direction, int
          pos)
     Search for STRING in the history list, starting at POS, an
     absolute index into the list.  If DIRECTION is negative, the search
     proceeds backward from POS, otherwise forward.  Returns the
     absolute index of the history element where STRING was found, or
     -1 otherwise.