diff -upr gedit-2.24.2/gedit/dialogs/gedit-search-dialog.c gedit-2.24.2-search_open/gedit/dialogs/gedit-search-dialog.c
--- gedit-2.24.2/gedit/dialogs/gedit-search-dialog.c	2008-11-09 12:59:56.000000000 -0200
+++ gedit-2.24.2-search_open/gedit/dialogs/gedit-search-dialog.c	2009-02-18 22:40:57.000000000 -0300
@@ -68,6 +68,7 @@ struct _GeditSearchDialogPrivate 
 	GtkWidget *match_case_checkbutton;
 	GtkWidget *entire_word_checkbutton;
 	GtkWidget *backwards_checkbutton;
+	GtkWidget *open_documents_checkbutton;
 	GtkWidget *wrap_around_checkbutton;
 	GtkWidget *find_button;
 	GtkWidget *replace_button;
@@ -352,6 +353,7 @@ gedit_search_dialog_init (GeditSearchDia
 					  "match_case_checkbutton", &dlg->priv->match_case_checkbutton,
 					  "entire_word_checkbutton", &dlg->priv->entire_word_checkbutton,
 					  "search_backwards_checkbutton", &dlg->priv->backwards_checkbutton,
+					  "search_open_documents_checkbutton", &dlg->priv->open_documents_checkbutton,
 					  "wrap_around_checkbutton", &dlg->priv->wrap_around_checkbutton,
 					  NULL);
 
@@ -604,6 +606,24 @@ gedit_search_dialog_get_backwards (Gedit
 }
 
 void
+gedit_search_dialog_set_open_documents (GeditSearchDialog *dialog,
+					gboolean           open_documents)
+{
+	g_return_if_fail (GEDIT_IS_SEARCH_DIALOG (dialog));
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->open_documents_checkbutton),
+				      open_documents);
+}
+
+gboolean
+gedit_search_dialog_get_open_documents (GeditSearchDialog *dialog)
+{
+	g_return_val_if_fail (GEDIT_IS_SEARCH_DIALOG (dialog), FALSE);
+
+	return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->open_documents_checkbutton));
+}
+
+void
 gedit_search_dialog_set_wrap_around (GeditSearchDialog *dialog,
 				     gboolean           wrap_around)
 {
diff -upr gedit-2.24.2/gedit/dialogs/gedit-search-dialog.h gedit-2.24.2-search_open/gedit/dialogs/gedit-search-dialog.h
--- gedit-2.24.2/gedit/dialogs/gedit-search-dialog.h	2008-11-09 12:59:56.000000000 -0200
+++ gedit-2.24.2-search_open/gedit/dialogs/gedit-search-dialog.h	2009-02-18 22:40:57.000000000 -0300
@@ -119,6 +119,10 @@ void		 gedit_search_dialog_set_backwards
 							 gboolean           backwards);
 gboolean	 gedit_search_dialog_get_backwards	(GeditSearchDialog *dialog);
 
+void		 gedit_search_dialog_set_open_documents	(GeditSearchDialog *dialog,
+							 gboolean           open_documents);
+gboolean	 gedit_search_dialog_get_open_documents	(GeditSearchDialog *dialog);
+
 void		 gedit_search_dialog_set_wrap_around	(GeditSearchDialog *dialog,
 							 gboolean           wrap_around);
 gboolean	 gedit_search_dialog_get_wrap_around	(GeditSearchDialog *dialog);
diff -upr gedit-2.24.2/gedit/dialogs/gedit-search-dialog.ui gedit-2.24.2-search_open/gedit/dialogs/gedit-search-dialog.ui
--- gedit-2.24.2/gedit/dialogs/gedit-search-dialog.ui	2008-11-09 12:59:56.000000000 -0200
+++ gedit-2.24.2-search_open/gedit/dialogs/gedit-search-dialog.ui	2009-02-18 22:40:57.000000000 -0300
@@ -212,6 +212,24 @@
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkCheckButton" id="search_open_documents_checkbutton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">Search in _open documents</property>
+                    <property name="use_underline">True</property>
+                    <property name="relief">GTK_RELIEF_NORMAL</property>
+                    <property name="focus_on_click">True</property>
+                    <property name="active">False</property>
+                    <property name="inconsistent">False</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="padding">0</property>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkCheckButton" id="wrap_around_checkbutton">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
diff -upr gedit-2.24.2/gedit/gedit-commands-search.c gedit-2.24.2-search_open/gedit/gedit-commands-search.c
--- gedit-2.24.2/gedit/gedit-commands-search.c	2008-11-09 12:59:57.000000000 -0200
+++ gedit-2.24.2-search_open/gedit/gedit-commands-search.c	2009-02-18 23:02:40.000000000 -0300
@@ -50,6 +50,12 @@
 #define GEDIT_SEARCH_DIALOG_KEY		"gedit-search-dialog-key"
 #define GEDIT_LAST_SEARCH_DATA_KEY	"gedit-last-search-data-key"
 
+typedef enum
+{
+	FIND,
+	REPLACE_ALL
+} SearchAction;
+
 /* data stored in the document
  * to persist the last searched
  * words and options
@@ -60,10 +66,11 @@ struct _LastSearchData
 	gchar *find_text;
 	gchar *replace_text;
 
-	gint match_case :1;
-	gint entire_word :1;
-	gint backwards :1;
-	gint wrap_around :1;
+	guint match_case :1;
+	guint entire_word :1;
+	guint backwards :1;
+	guint open_documents :1;
+	guint wrap_around :1;
 };
 
 static void
@@ -74,9 +81,10 @@ last_search_data_free (LastSearchData *d
 	g_free (data);
 }
 
-static void
+static gboolean
 last_search_data_set (LastSearchData    *data,
-		      GeditSearchDialog *dialog)
+		      GeditSearchDialog *dialog,
+		      SearchAction       action)
 {
 	const gchar *str;
 
@@ -86,18 +94,28 @@ last_search_data_set (LastSearchData    
 		g_free (data->find_text);
 		data->find_text = gedit_utils_unescape_search_text (str);
 	}
+	else
+		return FALSE;
 
 	str = gedit_search_dialog_get_replace_text (dialog);
-	if (str != NULL && *str != '\0')
+	if (str != NULL && (*str != '\0' || action == REPLACE_ALL))
 	{
 		g_free (data->replace_text);
 		data->replace_text = gedit_utils_unescape_search_text (str);
 	}
+	else
+	{
+		if (action == REPLACE_ALL)
+			return FALSE;
+	}
 
 	data->match_case = gedit_search_dialog_get_match_case (dialog);
 	data->entire_word = gedit_search_dialog_get_entire_word (dialog);
 	data->backwards = gedit_search_dialog_get_backwards (dialog);
+	data->open_documents = gedit_search_dialog_get_open_documents (dialog);
 	data->wrap_around = gedit_search_dialog_get_wrap_around (dialog);
+
+	return TRUE;
 }
 
 static void
@@ -123,12 +141,12 @@ search_dialog_set_last_options (GeditSea
 	gedit_search_dialog_set_match_case (dialog, data->match_case);
 	gedit_search_dialog_set_entire_word (dialog, data->entire_word);
 	gedit_search_dialog_set_backwards (dialog, data->backwards);
+	gedit_search_dialog_set_open_documents (dialog, data->open_documents);
 	gedit_search_dialog_set_wrap_around (dialog, data->wrap_around);
 }
 
-static void
-restore_last_searched_data (GeditSearchDialog *dialog,
-			    GeditDocument     *doc)
+static LastSearchData *
+get_doc_search_data (GeditDocument *doc)
 {
 	LastSearchData *data;
 
@@ -137,7 +155,6 @@ restore_last_searched_data (GeditSearchD
 	if (data == NULL)
 	{
 		data = g_new0 (LastSearchData, 1);
-		last_search_data_set (data, dialog);
 
 		g_object_set_data (G_OBJECT (doc),
 				   GEDIT_LAST_SEARCH_DATA_KEY,
@@ -147,10 +164,7 @@ restore_last_searched_data (GeditSearchD
 				   (GWeakNotify) last_search_data_free,
 				   data);
 	}
-	else
-	{
-		last_search_data_set (data, dialog);
-	}
+	return data;
 }
 
 /* Use occurences only for Replace All */
@@ -191,7 +205,8 @@ phrase_not_found (GeditWindow *window)
 static gboolean
 run_search (GeditView   *view,
 	    gboolean     wrap_around,
-	    gboolean     search_backwards)
+	    gboolean     search_backwards,
+	    gboolean     entire_document)
 {
 	GeditDocument *doc;
 	GtkTextIter start_iter;
@@ -201,42 +216,50 @@ run_search (GeditView   *view,
 
 	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
 
-	if (!search_backwards)
+	if (!entire_document)
 	{
-		gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
-						      NULL,
-						      &start_iter);
-
-		found = gedit_document_search_forward (doc,
-						       &start_iter,
-						       NULL,
-						       &match_start,
-						       &match_end);
+		if (!search_backwards)
+		{
+			gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
+							      NULL,
+							      &start_iter);
+			found = gedit_document_search_forward (doc,
+							       &start_iter,
+							       NULL,
+							       &match_start,
+							       &match_end);
+		}
+		else
+		{
+			gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
+							      &start_iter,
+							      NULL);
+			found = gedit_document_search_backward (doc,
+							        NULL,
+							        &start_iter,
+							        &match_start,
+							        &match_end);
+		}
 	}
 	else
 	{
-		gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
-						      &start_iter,
-						      NULL);
-
-		found = gedit_document_search_backward (doc,
-						        NULL,
-						        &start_iter,
-						        &match_start,
-						        &match_end);
+		if (!search_backwards)
+			gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &start_iter);
+		else
+			gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &start_iter);
 	}
 
-	if (!found && wrap_around)
+	if ((!found && wrap_around) || entire_document)
 	{
 		if (!search_backwards)
 			found = gedit_document_search_forward (doc,
 							       NULL,
-							       NULL, /* FIXME: set the end_inter */
+							       &start_iter,
 							       &match_start,
 							       &match_end);
 		else
 			found = gedit_document_search_backward (doc,
-							        NULL, /* FIXME: set the start_inter */
+							        &start_iter,
 							        NULL, 
 							        &match_start,
 							        &match_end);
@@ -262,11 +285,11 @@ run_search (GeditView   *view,
 	return found;
 }
 
-static void
-do_find (GeditSearchDialog *dialog,
-	 GeditWindow       *window)
+static guint
+manage_search (SearchAction action, GeditWindow *window, LastSearchData *data)
 {
-	GeditView *active_view;
+	GeditView *view;
+	GList *views;
 	GeditDocument *doc;
 	gchar *search_text;
 	const gchar *entry_text;
@@ -276,51 +299,202 @@ do_find (GeditSearchDialog *dialog,
 	gboolean search_backwards;	
 	guint flags = 0;
 	guint old_flags = 0;
-	gboolean found;
+	gboolean found = FALSE;	/* for action == FIND */
+	guint count = 0;	/* for action == REPLACE_ALL */
+	gboolean wrapped = FALSE;
+	gboolean search_open_docs;
+	gint active_index, index, nviews;
+
+	if (data == NULL)
+		return FALSE;
 
 	/* TODO: make the dialog insensitive when all the tabs are closed
 	 * and assert here that the view is not NULL */
-	active_view = gedit_window_get_active_view (window);
-	if (active_view == NULL)
-		return;
-
-	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
-
-	entry_text = gedit_search_dialog_get_search_text (dialog);
+	view = gedit_window_get_active_view (window);
+	if (view == NULL)
+		return FALSE;
 
-	match_case = gedit_search_dialog_get_match_case (dialog);
-	entire_word = gedit_search_dialog_get_entire_word (dialog);
-	search_backwards = gedit_search_dialog_get_backwards (dialog);
-	wrap_around = gedit_search_dialog_get_wrap_around (dialog);
+	match_case = data->match_case;
+	entire_word = data->entire_word;
+	search_backwards = data->backwards;
+	wrap_around = data->wrap_around;
+	entry_text = data->find_text;
+	search_open_docs = data->open_documents;
 
 	GEDIT_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
 	GEDIT_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
 
-	search_text = gedit_document_get_search_text (doc, &old_flags);
+	if (search_open_docs)
+	{
+		views = gedit_window_get_views (window);
+		index = active_index = g_list_index (views, view);
+		nviews = g_list_length (views);
+	}
+	else
+	{
+		views = NULL;
+		index = active_index = nviews = 0;
+	}
+
+	do {
+		doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+
+		search_text = gedit_document_get_search_text (doc, &old_flags);
+
+		if ((search_text == NULL) ||
+		    (strcmp (search_text, entry_text) != 0) ||
+		    (flags != old_flags))
+		{
+			gedit_document_set_search_text (doc, entry_text, flags);
+		}
+
+		g_free (search_text);
+
+		if (action == FIND)
+		{
+			if (!search_open_docs)
+			{
+				found = run_search (view,
+					            wrap_around,
+				   	            search_backwards,
+					            FALSE); /* entire_document */
+			}
+			else if (index != active_index)
+			{
+				/* When switch to other doc, it is necessary
+				   set the same data, so next time the "Find"
+				   dialog shows up or "Find Next" is run,
+				   options of the last search will be used. */
+				g_object_set_data (G_OBJECT (doc),
+				                   GEDIT_LAST_SEARCH_DATA_KEY,
+				                   data);
+				found = run_search (view,
+				                    FALSE,
+				                    search_backwards,
+				                    TRUE);
+			}
+			else if (wrapped)
+			{
+				found = run_search (view,
+				                    TRUE,
+				                    search_backwards,
+				                    FALSE);
+			}
+			else
+			{
+				found = run_search (view,
+				                    FALSE,
+				                    search_backwards,
+				                    FALSE);
+			}
+
+			if (found)
+				break;
+		}
+
+		if (wrapped && index == active_index)
+			break;
+
+		if (action == REPLACE_ALL)
+		{
+			count += gedit_document_replace_all (doc,
+							    entry_text,
+							    data->replace_text,
+							    flags);
+		}
+
+		if (!search_open_docs)
+			break;
+
+		if (search_backwards)
+		{
+			if (index == 0)
+			{
+				if (wrap_around)
+				{
+					index = nviews;
+					wrapped = TRUE;
+				}
+				else
+					break;
+			}
+			index--;
+		}
+		else
+		{
+			index++;
+			if (index == nviews)
+			{
+				if (wrap_around)
+				{
+					index = 0;
+					wrapped = TRUE;
+				}
+				else
+					break;
+			}
+		}
+		view = g_list_nth_data (views, index);
+	}
+	while (search_open_docs);
+
+	if (search_open_docs)
+		g_list_free (views);
+
+	if (action == REPLACE_ALL)
+		return count;
+
+	if (found)
+	{
+		if (gedit_window_get_active_tab (window) !=
+		    gedit_tab_get_from_document (doc))
+		{
+			gedit_window_set_active_tab (window,
+			    gedit_tab_get_from_document (doc));
+		}
+		return 1;
+	}
+	else
+		return 0;
+}
+
+static void
+do_find (GeditSearchDialog *dialog,
+	 GeditWindow       *window,
+	 gboolean           backward)
+	/* "backward" will be used only when "dialog" != NULL */
+{
+	GeditView *active_view;
+	GeditDocument *doc;
+	LastSearchData *data;
+	gboolean found;
+
+	active_view = gedit_window_get_active_view (window);
+	g_return_if_fail (active_view != NULL);
 
-	if ((search_text == NULL) ||
-	    (strcmp (search_text, entry_text) != 0) ||
-	    (flags != old_flags))
+	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
+
+	data = get_doc_search_data (doc);
+
+	if (dialog != NULL)
 	{
-		gedit_document_set_search_text (doc, entry_text, flags);
+		if (!last_search_data_set (data, dialog, FIND))
+			return;
 	}
+	else
+		data->backwards = backward;
 
-	g_free (search_text);
-	
-	found = run_search (active_view,
-			    wrap_around,
-			    search_backwards);
+	found = manage_search (FIND, window, data);
 
 	if (found)
 		phrase_found (window, 0);
 	else
 		phrase_not_found (window);
 
-	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
-					   GEDIT_SEARCH_DIALOG_REPLACE_RESPONSE,
-					   found);
-
-	restore_last_searched_data (dialog, doc);
+	if (dialog != NULL)
+		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
+						   GEDIT_SEARCH_DIALOG_REPLACE_RESPONSE,
+						   found);
 }
 
 /* FIXME: move in gedit-document.c and share it with gedit-view */
@@ -377,7 +551,6 @@ do_replace (GeditSearchDialog *dialog,
 	gchar *unescaped_replace_text;
 	gchar *selected_text = NULL;
 	gboolean match_case;
-	gboolean search_backwards;
 
 	doc = gedit_window_get_active_document (window);
 	if (doc == NULL)
@@ -398,7 +571,6 @@ do_replace (GeditSearchDialog *dialog,
 			   NULL);
 
 	match_case = gedit_search_dialog_get_match_case (dialog);
-	search_backwards = gedit_search_dialog_get_backwards (dialog);
 
 	if ((selected_text == NULL) ||
 	    (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) || 
@@ -407,7 +579,8 @@ do_replace (GeditSearchDialog *dialog,
 						    strlen (selected_text), 
 						    strlen (unescaped_search_text)) != 0))
 	{
-		do_find (dialog, window);
+		do_find (dialog, window, FALSE);
+
 		g_free (unescaped_search_text);
 		g_free (selected_text);	
 
@@ -421,46 +594,29 @@ do_replace (GeditSearchDialog *dialog,
 	g_free (selected_text);
 	g_free (unescaped_replace_text);
 	
-	do_find (dialog, window);
+	do_find (dialog, window, FALSE);
 }
 
 static void
 do_replace_all (GeditSearchDialog *dialog,
 		GeditWindow       *window)
 {
-	GeditView *active_view;
+	GeditView *view;
 	GeditDocument *doc;
-	const gchar *search_entry_text;
-	const gchar *replace_entry_text;	
-	gboolean match_case;
-	gboolean entire_word;
-	guint flags = 0;
-	gint count;
+	gint count = 0;
+	LastSearchData *data;
 
-	active_view = gedit_window_get_active_view (window);
-	if (active_view == NULL)
+	view = gedit_window_get_active_view (window);
+	if (view == NULL)
 		return;
 
-	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
-
-	search_entry_text = gedit_search_dialog_get_search_text (dialog);
-	g_return_if_fail ((search_entry_text) != NULL);
-	g_return_if_fail ((*search_entry_text) != '\0');
-
-	/* replace text may be "", we just delete all occurrencies */
-	replace_entry_text = gedit_search_dialog_get_replace_text (dialog);
-	g_return_if_fail ((replace_entry_text) != NULL);
-
-	match_case = gedit_search_dialog_get_match_case (dialog);
-	entire_word = gedit_search_dialog_get_entire_word (dialog);
+	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
 
-	GEDIT_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
-	GEDIT_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
+	data = get_doc_search_data (doc);
+	if (!last_search_data_set (data, dialog, REPLACE_ALL))
+		return;
 
-	count = gedit_document_replace_all (doc, 
-					    search_entry_text,
-					    replace_entry_text,
-					    flags);
+	count = manage_search (REPLACE_ALL, window, data);
 
 	if (count > 0)
 	{
@@ -474,8 +630,6 @@ do_replace_all (GeditSearchDialog *dialo
 	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
 					   GEDIT_SEARCH_DIALOG_REPLACE_RESPONSE,
 					   FALSE);
-
-	restore_last_searched_data (dialog, doc);
 }
 
 static void
@@ -488,7 +642,7 @@ search_dialog_response_cb (GeditSearchDi
 	switch (response_id)
 	{
 		case GEDIT_SEARCH_DIALOG_FIND_RESPONSE:
-			do_find (dialog, window);
+			do_find (dialog, window, FALSE);
 			break;
 		case GEDIT_SEARCH_DIALOG_REPLACE_RESPONSE:
 			do_replace (dialog, window);
@@ -556,8 +710,7 @@ _gedit_cmd_search_find (GtkAction   *act
 	doc = gedit_window_get_active_document (window);
 	g_return_if_fail (doc != NULL);
 
-	last_search_data = g_object_get_data (G_OBJECT (doc),
-					      GEDIT_LAST_SEARCH_DATA_KEY);
+	last_search_data = get_doc_search_data (doc);
 
 	selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
 					      &find_text,
@@ -639,9 +792,7 @@ _gedit_cmd_search_replace (GtkAction   *
 	doc = gedit_window_get_active_document (window);
 	g_return_if_fail (doc != NULL);
 
-	last_search_data = g_object_get_data (G_OBJECT (doc),
-					      GEDIT_LAST_SEARCH_DATA_KEY);
-
+	last_search_data = get_doc_search_data (doc);
 
 	selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
 					      &find_text,
@@ -678,38 +829,13 @@ _gedit_cmd_search_replace (GtkAction   *
 	gtk_widget_show (replace_dialog);
 }
 
-static void
-do_find_again (GeditWindow *window,
-	       gboolean     backward)
-{
-	GeditView *active_view;
-	GtkTextBuffer *buffer;
-	gboolean wrap_around = TRUE;
-	LastSearchData *data;
-	
-	active_view = gedit_window_get_active_view (window);
-	g_return_if_fail (active_view != NULL);
-
-	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view));
-
-	data = g_object_get_data (G_OBJECT (buffer), 
-				  GEDIT_LAST_SEARCH_DATA_KEY);
-
-	if (data != NULL)
-		wrap_around = data->wrap_around;					    
-
-	run_search (active_view,
-	   	    wrap_around,
-	   	    backward);
-}				 
-
 void
 _gedit_cmd_search_find_next (GtkAction   *action,
 			    GeditWindow *window)
 {
 	gedit_debug (DEBUG_COMMANDS);
 
-	do_find_again (window, FALSE);
+	do_find (NULL, window, FALSE);
 }
 
 void
@@ -718,7 +844,7 @@ _gedit_cmd_search_find_prev (GtkAction  
 {
 	gedit_debug (DEBUG_COMMANDS);
 
-	do_find_again (window, TRUE);
+	do_find (NULL, window, TRUE);
 }
 
 void
