diff --git a/cmd-find-window.c b/cmd-find-window.c
index 06cdd946..6338e2e1 100644
--- a/cmd-find-window.c
+++ b/cmd-find-window.c
@@ -122,7 +122,7 @@ cmd_find_window_match(struct cmd_find_window_list *find_list,
 		}
 
 		if (match_flags & CMD_FIND_WINDOW_BY_CONTENT &&
-		    (sres = window_pane_search(wp, str, &line)) != NULL) {
+		    (sres = window_pane_search_old(wp, str, &line)) != NULL) {
 			xasprintf(&find_data->list_ctx,
 			    "pane %u line %u: \"%s\"", i - 1, line + 1, sres);
 			free(sres);
diff --git a/format.c b/format.c
index 24836b0b..7af7840d 100644
--- a/format.c
+++ b/format.c
@@ -848,19 +848,17 @@ format_true(const char *s)
 	return (0);
 }
 
-/*
- * Replace a key/value pair in buffer. #{blah} is expanded directly,
- * #{?blah,a,b} is replace with a if blah exists and is nonzero else b.
- */
+/* Replace a key. */
 static int
 format_replace(struct format_tree *ft, const char *key, size_t keylen,
     char **buf, size_t *len, size_t *off)
 {
-	char		*copy, *copy0, *endptr, *ptr, *found, *new, *value;
-	char		*from = NULL, *to = NULL, *left, *right;
-	size_t		 valuelen, newlen, fromlen, tolen, used;
-	long		 limit = 0;
-	int		 modifiers = 0, compare = 0;
+	struct window_pane	*wp = ft->wp;
+	char			*copy, *copy0, *endptr, *ptr, *found, *new;
+	char			*value, *from = NULL, *to = NULL, *left, *right;
+	size_t			 valuelen, newlen, fromlen, tolen, used;
+	long			 limit = 0;
+	int			 modifiers = 0, compare = 0, search = 0;
 
 	/* Make a copy of the key. */
 	copy0 = copy = xmalloc(keylen + 1);
@@ -875,6 +873,24 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
 		compare = -2;
 		copy += 2;
 		break;
+	case 'C':
+		if (copy[1] != ':')
+			break;
+		search = 1;
+		copy += 2;
+		break;
+	case '|':
+		if (copy[1] != '|' || copy[2] != ':')
+			break;
+		compare = -3;
+		copy += 3;
+		break;
+	case '&':
+		if (copy[1] != '&' || copy[2] != ':')
+			break;
+		compare = -4;
+		copy += 3;
+		break;
 	case '!':
 		if (copy[1] == '=' && copy[2] == ':') {
 			compare = -1;
@@ -940,13 +956,25 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
 	}
 
 	/* Is this a comparison or a conditional? */
-	if (compare != 0) {
+	if (search) {
+		/* Search in pane. */
+		if (wp == NULL)
+			value = xstrdup("0");
+		else
+			xasprintf(&value, "%u", window_pane_search(wp, copy));
+	} else if (compare != 0) {
 		/* Comparison: compare comma-separated left and right. */
 		if (format_choose(copy, &left, &right) != 0)
 			goto fail;
 		left = format_expand(ft, left);
 		right = format_expand(ft, right);
-		if (compare == 1 && strcmp(left, right) == 0)
+		if (compare == -3 &&
+		    (format_true(left) || format_true(right)))
+			value = xstrdup("1");
+		else if (compare == -4 &&
+		    (format_true(left) && format_true(right)))
+			value = xstrdup("1");
+		else if (compare == 1 && strcmp(left, right) == 0)
 			value = xstrdup("1");
 		else if (compare == -1 && strcmp(left, right) != 0)
 			value = xstrdup("1");
diff --git a/tmux.1 b/tmux.1
index 1ba66da4..8110ae50 100644
--- a/tmux.1
+++ b/tmux.1
@@ -3430,7 +3430,7 @@ is enabled, or
 .Ql no
 if not.
 .Pp
-Simple comparisons may be expressed by prefixing two comma-separated
+Comparisons may be expressed by prefixing two comma-separated
 alternatives by
 .Ql ==
 or
@@ -3443,14 +3443,26 @@ will be replaced by
 if running on
 .Ql myhost ,
 otherwise by
-.Ql 0.
+.Ql 0 .
 An
 .Ql m
-specifies a
+specifies an
 .Xr fnmatch 3
-comparison - the first argument is the pattern and the second the string to
-compare. For example,
+comparison where the first argument is the pattern and the second the string to
+compare, for example
 .Ql #{m:*foo*,#{host}} .
+.Ql ||
+and
+.Ql &&
+evaluate to true if either or both of two comma-separated alternatives are
+true, for example
+.Ql #{||,#{pane_in_mode},#{alternate_on}} .
+A
+.Ql C
+performs a search for an
+.Xr fnmatch 3
+pattern in the pane content and evaluates to zero if not found, or a line
+number if found.
 .Pp
 A limit may be placed on the length of the resultant string by prefixing it
 by an
diff --git a/tmux.h b/tmux.h
index bf15dbd9..6fcfd9d3 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2121,7 +2121,8 @@ void		 window_pane_key(struct window_pane *, struct client *,
 		     struct session *, key_code, struct mouse_event *);
 int		 window_pane_outside(struct window_pane *);
 int		 window_pane_visible(struct window_pane *);
-char		*window_pane_search(struct window_pane *, const char *,
+u_int		 window_pane_search(struct window_pane *, const char *);
+char		*window_pane_search_old(struct window_pane *, const char *,
 		     u_int *);
 const char	*window_printable_flags(struct winlink *);
 struct window_pane *window_pane_find_up(struct window_pane *);
diff --git a/window.c b/window.c
index 392a889e..5e49adc4 100644
--- a/window.c
+++ b/window.c
@@ -1267,8 +1267,32 @@ window_pane_visible(struct window_pane *wp)
 	return (!window_pane_outside(wp));
 }
 
+u_int
+window_pane_search(struct window_pane *wp, const char *searchstr)
+{
+	struct screen	*s = &wp->base;
+	char		*newsearchstr, *line;
+	u_int		 i;
+
+	xasprintf(&newsearchstr, "*%s*", searchstr);
+
+	for (i = 0; i < screen_size_y(s); i++) {
+		line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
+		if (fnmatch(newsearchstr, line, 0) == 0) {
+			free(line);
+			break;
+		}
+		free(line);
+	}
+
+	free(newsearchstr);
+	if (i == screen_size_y(s))
+		return (0);
+	return (i + 1);
+}
+
 char *
-window_pane_search(struct window_pane *wp, const char *searchstr,
+window_pane_search_old(struct window_pane *wp, const char *searchstr,
     u_int *lineno)
 {
 	struct screen	*s = &wp->base;