<p>In Vim I can <code>:set wrapscan</code> so that when I do an incremental search, the cursor jumps to the first match whether the first match is above or below the cursor.</p>

<p>In Emacs, if I start a search via <code>C-s</code>, the search fails saying <em>Failing I-search</em> if the first match is above the cursor.  If I hit <code>C-s</code> again it then wraps the search, saying <em>Wrapped I-search</em>.  How do I wrap and jump the cursor by default as in Vim, without having to <code>C-s</code> a second time?</p>

The easiest way to do this is to use the following defadvice:
```
```
(defadvice isearch-repeat (after isearch-no-fail activate)
  (unless isearch-success
    (ad-disable-advice 'isearch-repeat 'after 'isearch-no-fail)
    (ad-activate 'isearch-repeat)
    (isearch-repeat (if isearch-forward 'forward))
    (ad-enable-advice 'isearch-repeat 'after 'isearch-no-fail)
    (ad-activate 'isearch-repeat)))
```
```
When Isearch fails, it immediately tries again with wrapping. Note that it is important to temporarily disable this defadvice to prevent an infinite loop when there are no matches.