diff --git a/internal/action/actions.go b/internal/action/actions.go index b0867da9f8..bcdc121278 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1144,8 +1144,7 @@ func (h *BufPane) find(useRegex bool) bool { match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex) if err != nil { InfoBar.Error(err) - } - if found { + } else if found { h.Cursor.SetSelectionStart(match[0]) h.Cursor.SetSelectionEnd(match[1]) h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0] diff --git a/internal/buffer/search.go b/internal/buffer/search.go index a48e1f87f4..76931ee283 100644 --- a/internal/buffer/search.go +++ b/internal/buffer/search.go @@ -41,12 +41,21 @@ func findLineParams(b *Buffer, start, end Loc, i int, r *regexp.Regexp) ([]byte, } } - if padMode == padStart { - r = regexp.MustCompile(".(?:" + r.String() + ")") - } else if padMode == padEnd { - r = regexp.MustCompile("(?:" + r.String() + ").") - } else if padMode == padStart|padEnd { - r = regexp.MustCompile(".(?:" + r.String() + ").") + if padMode != 0 { + re, err := regexp.Compile(r.String() + `\E`) + if err == nil { + // r contains \Q without closing \E + r = re + } + + if padMode == padStart { + r = regexp.MustCompile(".(?:" + r.String() + ")") + } else if padMode == padEnd { + r = regexp.MustCompile("(?:" + r.String() + ").") + } else { + // padMode == padStart|padEnd + r = regexp.MustCompile(".(?:" + r.String() + ").") + } } return l, charpos, padMode, r