diff --git a/src/quickfix.c b/src/quickfix.c
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -3109,6 +3109,7 @@
     char_u	*p;
     int		fi;
     qf_info_T	*qi = &ql_info;
+    qfline_T	*qi_prev; /* check for quickfix changes from autocommands */
     qfline_T	*prevp = NULL;
     long	lnum;
     buf_T	*buf;
@@ -3218,9 +3219,24 @@
      * ":lcd %:p:h" changes the meaning of short path names. */
     mch_dirname(dirname_start, MAXPATHL);
 
+    qi_prev = qi->qf_lists[qi->qf_curlist].qf_start;
     seconds = (time_t)0;
     for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
     {
+	if (qi_prev != qi->qf_lists[qi->qf_curlist].qf_start) /* autocommands changed quickfix list */
+	{
+	    int idx = 0;
+
+	    while (qi->qf_lists[idx].qf_start != qi_prev && idx < LISTCOUNT)
+		idx++;
+
+	    if (qi_prev != qi->qf_lists[idx].qf_start) /* vimgrep list has been freed */
+		qf_new_list(qi, *eap->cmdlinep);
+	    else
+		qi->qf_curlist = idx;
+
+	    qi_prev = qi->qf_lists[idx].qf_start;
+	}
 	fname = shorten_fname1(fnames[fi]);
 	if (time(NULL) > seconds)
 	{
@@ -3324,6 +3340,7 @@
 		if (got_int)
 		    break;
 	    }
+	    qi_prev = qi->qf_lists[qi->qf_curlist].qf_start;
 
 	    if (using_dummy)
 	    {
