diff --git a/src/files.c b/src/files.c
index df3bb3e36c823c6e69570b02ca2460cea1460acb..aa2ceab203ccd5e7dac0b56320ac89e706283d68 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1081,7 +1081,7 @@ void do_insertfile(void)
 #endif
 		MINSERTFILE, given,
 #ifndef DISABLE_HISTORIES
-		NULL,
+		execute ? &execute_history : NULL,
 #endif
 		edit_refresh, msg,
 #ifndef DISABLE_OPERATINGDIR
@@ -1144,6 +1144,7 @@ void do_insertfile(void)
 #endif
 		/* Save the command's output in the current buffer. */
 		execute_command(answer);
+		update_history(&execute_history, answer);
 
 #ifdef ENABLE_MULTIBUFFER
 		/* If this is a new buffer, put the cursor at the top. */
diff --git a/src/global.c b/src/global.c
index 7a56664b11e393f1d54ce202f2251908904c5291..f58be8469a7a5a0841e526ed8e34d6f136704d49 100644
--- a/src/global.c
+++ b/src/global.c
@@ -216,6 +216,12 @@ filestruct *replaceage = NULL;
 	/* The top of the replace string history list. */
 filestruct *replacebot = NULL;
 	/* The bottom of the replace string history list. */
+filestruct *execute_history = NULL;
+	/* The list of commands that have been run with ^R ^X. */
+filestruct *executetop = NULL;
+	/* The top of the execute history list. */
+filestruct *executebot = NULL;
+	/* The bottom of the execute history list. */
 poshiststruct *position_history = NULL;
 	/* The cursor position history list. */
 #endif
@@ -1266,17 +1272,17 @@ void shortcut_init(void)
     add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0);
     add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0);
 #ifndef DISABLE_HISTORIES
-    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^P", 0, get_history_older_void, 0);
-    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^N", 0, get_history_newer_void, 0);
+    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "^P", 0, get_history_older_void, 0);
+    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "^N", 0, get_history_newer_void, 0);
 #ifdef ENABLE_UTF8
     if (using_utf8()) {
-	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "\xE2\x86\x91", KEY_UP, get_history_older_void, 0);
-	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "\xE2\x86\x93", KEY_DOWN, get_history_newer_void, 0);
+	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "\xE2\x86\x91", KEY_UP, get_history_older_void, 0);
+	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "\xE2\x86\x93", KEY_DOWN, get_history_newer_void, 0);
     } else
 #endif
     {
-	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Up", KEY_UP, get_history_older_void, 0);
-	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Down", KEY_DOWN, get_history_newer_void, 0);
+	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "Up", KEY_UP, get_history_older_void, 0);
+	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "Down", KEY_DOWN, get_history_newer_void, 0);
     }
 #endif
 #ifdef ENABLE_BROWSER
diff --git a/src/proto.h b/src/proto.h
index a9f826b3dddd395592c8e0efb7dd42e76c7bb8ce..b7a279c4ece9911689017c29690420b57b21d64f 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -165,6 +165,9 @@ extern filestruct *searchbot;
 extern filestruct *replace_history;
 extern filestruct *replaceage;
 extern filestruct *replacebot;
+extern filestruct *execute_history;
+extern filestruct *executetop;
+extern filestruct *executebot;
 extern poshiststruct *position_history;
 #endif
 
diff --git a/src/search.c b/src/search.c
index 92d90223b6df44d32deacd7f6979c40cf541e25c..b04e9a37a7cd6dda9c9d757703b7f408a42fbe01 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1107,6 +1107,11 @@ void history_init(void)
     replace_history->data = mallocstrcpy(NULL, "");
     replaceage = replace_history;
     replacebot = replace_history;
+
+    execute_history = make_new_node(NULL);
+    execute_history->data = mallocstrcpy(NULL, "");
+    executetop = execute_history;
+    executebot = execute_history;
 }
 
 /* Set the current position in the history list h to the bottom. */
@@ -1116,6 +1121,8 @@ void history_reset(const filestruct *h)
 	search_history = searchbot;
     else if (h == replace_history)
 	replace_history = replacebot;
+    else if (h == execute_history)
+	execute_history = executebot;
 }
 
 /* Return the first node containing the first len characters of the
@@ -1148,6 +1155,9 @@ void update_history(filestruct **h, const char *s)
     } else if (*h == replace_history) {
 	hage = &replaceage;
 	hbot = &replacebot;
+    } else if (*h == execute_history) {
+	hage = &executetop;
+	hbot = &executebot;
     }
 
     assert(hage != NULL && hbot != NULL);
@@ -1248,6 +1258,9 @@ char *get_history_completion(filestruct **h, char *s, size_t len)
 	} else if (*h == replace_history) {
 	    hage = replaceage;
 	    hbot = replacebot;
+	} else if (*h == execute_history) {
+	    hage = executetop;
+	    hbot = executebot;
 	}
 
 	assert(hage != NULL && hbot != NULL);