updated for version 7.0218
diff --git a/src/buffer.c b/src/buffer.c
index 4e5e037..089def0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -251,7 +251,7 @@
 	    /* Go to the buffer that was opened. */
 	    aucmd_prepbuf(&aco, old_curbuf);
 #endif
-	    do_modelines(FALSE);
+	    do_modelines(0);
 	    curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
 
 #ifdef FEAT_AUTOCMD
@@ -747,7 +747,7 @@
 	ml_recover();
 	MSG_PUTS("\n");	/* don't overwrite the last message */
 	cmdline_row = msg_row;
-	do_modelines(FALSE);
+	do_modelines(0);
 
 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
 	/* Restore the error/interrupt/exception state if not discarded by a
@@ -4632,16 +4632,20 @@
 
 #endif /* FEAT_WINDOWS */
 
+static int  chk_modeline __ARGS((linenr_T, int));
+
 /*
  * do_modelines() - process mode lines for the current file
  *
+ * "flags" can be:
+ * OPT_WINONLY	    only set options local to window
+ * OPT_NOWIN	    don't set options local to window
+ *
  * Returns immediately if the "ml" option isn't set.
  */
-static int  chk_modeline __ARGS((linenr_T, int));
-
     void
-do_modelines(win_only)
-    int		win_only;	    /* Only do window-local options. */
+do_modelines(flags)
+    int		flags;
 {
     linenr_T	lnum;
     int		nmlines;
@@ -4658,12 +4662,12 @@
     ++entered;
     for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines;
 								       ++lnum)
-	if (chk_modeline(lnum, win_only) == FAIL)
+	if (chk_modeline(lnum, flags) == FAIL)
 	    nmlines = 0;
 
     for (lnum = curbuf->b_ml.ml_line_count; lnum > 0 && lnum > nmlines
 		       && lnum > curbuf->b_ml.ml_line_count - nmlines; --lnum)
-	if (chk_modeline(lnum, win_only) == FAIL)
+	if (chk_modeline(lnum, flags) == FAIL)
 	    nmlines = 0;
     --entered;
 }
@@ -4675,9 +4679,9 @@
  * Return FAIL if an error encountered.
  */
     static int
-chk_modeline(lnum, win_only)
+chk_modeline(lnum, flags)
     linenr_T	lnum;
-    int		win_only;	    /* Only do window-local options. */
+    int		flags;		/* Same as for do_modelines(). */
 {
     char_u	*s;
     char_u	*e;
@@ -4774,8 +4778,7 @@
 		save_SID = current_SID;
 		current_SID = SID_MODELINE;
 #endif
-		retval = do_set(s, OPT_MODELINE | OPT_LOCAL
-					      | (win_only ? OPT_WINONLY : 0));
+		retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags);
 #ifdef FEAT_EVAL
 		current_SID = save_SID;
 #endif
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index d86084b..9deeae4 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2586,7 +2586,7 @@
 	    if (*curbuf->b_p_ft == NUL)
 	    {
 		(void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE);
-		do_modelines(FALSE);
+		do_modelines(0);
 	    }
 #endif
 	}
@@ -3495,7 +3495,7 @@
 	    /* Read the modelines, but only to set window-local options.  Any
 	     * buffer-local options have already been set and may have been
 	     * changed by the user. */
-	    do_modelines(TRUE);
+	    do_modelines(OPT_WINONLY);
 
 	    apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf,
 								    &retval);
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 31aa4ac..e2f2972 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -4743,7 +4743,7 @@
     exarg_T	*eap;
 {
     (void)do_doautocmd(eap->arg, TRUE);
-    do_modelines(FALSE);
+    do_modelines(0);
 }
 #endif
 
@@ -10505,7 +10505,7 @@
 	if (*arg == 'd')
 	{
 	    (void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE);
-	    do_modelines(FALSE);
+	    do_modelines(0);
 	}
     }
     else if (STRCMP(arg, "off") == 0)
diff --git a/src/fileio.c b/src/fileio.c
index 205e5f0..635bbcf 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4655,7 +4655,7 @@
     {
 	if (au_find_group((char_u *)"filetypedetect") != AUGROUP_ERROR)
 	    (void)do_doautocmd((char_u *)"filetypedetect BufRead", FALSE);
-	do_modelines(FALSE);
+	do_modelines(0);
     }
 #endif
 
@@ -8045,7 +8045,7 @@
 
 	    /* execute the autocommands for this buffer */
 	    retval = do_doautocmd(eap->arg, FALSE);
-	    do_modelines(FALSE);
+	    do_modelines(0);
 
 	    /* restore the current window */
 	    aucmd_restbuf(&aco);
diff --git a/src/gui_x11.c b/src/gui_x11.c
index be93cc5..3176b9d 100644
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -111,7 +111,16 @@
 	    if (current_fontset != NULL) \
 		XwcDrawString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \
 	    else \
-		XDrawString16(dpy, win, gc, x, y, str, n); \
+		XDrawString16(dpy, win, gc, x, y, (XChar2b *)str, n); \
+	} while (0)
+
+#define XDrawImageString16(dpy, win, gc, x, y, str, n) \
+	do \
+	{ \
+	    if (current_fontset != NULL) \
+		XwcDrawImageString(dpy, win, current_fontset, gc, x, y, (wchar_t *)str, n); \
+	    else \
+		XDrawImageString16(dpy, win, gc, x, y, (XChar2b *)str, n); \
 	} while (0)
 
 static int check_fontset_sanity __ARGS((XFontSet fs));
@@ -2503,7 +2512,7 @@
 {
     int			cells = len;
 #ifdef FEAT_MBYTE
-    static XChar2b	*buf = NULL;
+    static void		*buf = NULL;
     static int		buflen = 0;
     char_u		*p;
     int			wlen = 0;
@@ -2517,7 +2526,8 @@
 	if (buflen < len)
 	{
 	    XtFree((char *)buf);
-	    buf = (XChar2b *)XtMalloc(len * sizeof(XChar2b));
+	    buf = (void *)XtMalloc(len * (sizeof(XChar2b) < sizeof(wchar_t)
+					? sizeof(wchar_t) : sizeof(XChar2b)));
 	    buflen = len;
 	}
 	p = s;
@@ -2525,10 +2535,21 @@
 	while (p < s + len)
 	{
 	    c = utf_ptr2char(p);
-	    if (c >= 0x10000)	/* show chars > 0xffff as ? */
-		c = 0xbf;
-	    buf[wlen].byte1 = (unsigned)c >> 8;
-	    buf[wlen].byte2 = c;
+# ifdef FEAT_XFONTSET
+	    if (current_fontset != NULL)
+	    {
+		if (c >= 0x10000 && sizeof(wchar_t) <= 2)
+		    c = 0xbf;		/* show chars > 0xffff as ? */
+		((wchar_t *)buf)[wlen] = c;
+	    }
+	    else
+# endif
+	    {
+		if (c >= 0x10000)
+		    c = 0xbf;		/* show chars > 0xffff as ? */
+		((XChar2b *)buf)[wlen].byte1 = (unsigned)c >> 8;
+		((XChar2b *)buf)[wlen].byte2 = c;
+	    }
 	    ++wlen;
 	    cells += utf_char2cells(c);
 	    p += utf_ptr2len(p);
diff --git a/src/main.c b/src/main.c
index bd31e50..60aebf9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2302,7 +2302,7 @@
 	ml_recover();
 	if (curbuf->b_ml.ml_mfp == NULL) /* failed */
 	    getout(1);
-	do_modelines(FALSE);		/* do modelines */
+	do_modelines(0);		/* do modelines */
     }
     else
     {
diff --git a/src/netbeans.c b/src/netbeans.c
index c284624..889ad3c 100644
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -1489,10 +1489,10 @@
 		lbuf[0] = '\0';
 
 		nb_set_curbuf(buf->bufp);
-		old_b_changed = buf->bufp->b_changed;
+		old_b_changed = curbuf->b_changed;
 
-		pos = off2pos(buf->bufp, off);
-		if (pos)
+		pos = off2pos(curbuf, off);
+		if (pos != NULL)
 		{
 		    if (pos->lnum == 0)
 			pos->lnum = 1;
@@ -1506,28 +1506,30 @@
 #ifdef FEAT_VIRTUALEDIT
 		    pos->coladd = 0;
 #endif
-		    pos->lnum = buf->bufp->b_ml.ml_line_count;
+		    pos->lnum = curbuf->b_ml.ml_line_count;
 		}
 		lnum = pos->lnum;
 		old_w_cursor = curwin->w_cursor;
 		curwin->w_cursor = *pos;
 
-		if (buf->bufp->b_start_eol == FALSE && lnum > 0)
+		if (curbuf->b_start_eol == FALSE
+			&& lnum > 0
+			&& lnum <= curbuf->b_ml.ml_line_count)
 		{
 		    /* Append to a partial line */
 		    char_u *partial = ml_get(lnum);
 
-		    if (partial != IObuff)
-			STRCPY(lbuf, partial);
-			lbuf_len = STRLEN(partial);
-			ml_delete(lnum, FALSE);
+		    STRCPY(lbuf, partial);
+		    lbuf_len = STRLEN(partial);
+		    ml_delete(lnum, FALSE);
+		    buf_was_empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
 		}
 
 		doupdate = 1;
 		while (*args)
 		{
 		    nl = (char_u *)strchr((char *)args, '\n');
-		    if (nl)
+		    if (nl != NULL)
 		    {
 			STRNCAT(lbuf, args, nl - args);
 			lbuf[lbuf_len + nl - args] = '\0';
@@ -1554,13 +1556,13 @@
 
 		if (*(args - 1) == '\n')
 		{
-		    buf->bufp->b_p_eol = TRUE;
-		    buf->bufp->b_start_eol = TRUE;
+		    curbuf->b_p_eol = TRUE;
+		    curbuf->b_start_eol = TRUE;
 		}
 		else
 		{
-		    buf->bufp->b_p_eol = FALSE;
-		    buf->bufp->b_start_eol = FALSE;
+		    curbuf->b_p_eol = FALSE;
+		    curbuf->b_start_eol = FALSE;
 		}
 
 		appended_lines_mark(pos->lnum - 1, lnum - pos->lnum);
@@ -1573,8 +1575,11 @@
 		    if (ff_detected == EOL_UNKNOWN)
 			ff_detected = EOL_DOS;
 		    set_fileformat(ff_detected, OPT_LOCAL);
-		    buf->bufp->b_start_ffc = *buf->bufp->b_p_ff;
-		    ml_delete(curbuf->b_ml.ml_line_count, FALSE);
+		    curbuf->b_start_ffc = *curbuf->b_p_ff;
+
+		    /* Safety check: only delete empty line */
+		    if (*ml_get(curbuf->b_ml.ml_line_count) == NUL)
+			ml_delete(curbuf->b_ml.ml_line_count, FALSE);
 		}
 
 		curwin->w_cursor = old_w_cursor;
@@ -1584,11 +1589,11 @@
 		 * text the buffer has been updated but not written. Will
 		 * netbeans guarantee to write it? Even if I do a :q! ?
 		 */
-		buf->bufp->b_changed = old_b_changed; /* logically unchanged */
+		curbuf->b_changed = old_b_changed; /* logically unchanged */
 		netbeansFireChanges = oldFire;
 
-		u_blockfree(buf->bufp);
-		u_clearall(buf->bufp);
+		u_blockfree(curbuf);
+		u_clearall(curbuf);
 	    }
 	    vim_free(to_free);
 	    nb_reply_nil(cmdno); /* or !error */
diff --git a/src/option.c b/src/option.c
index 5c957e5..b14b4f9 100644
--- a/src/option.c
+++ b/src/option.c
@@ -3774,9 +3774,11 @@
  * does not need to be expanded with option_expand().
  * "opt_flags":
  * 0 for ":set"
- * OPT_GLOBAL for ":setglobal"
- * OPT_LOCAL for ":setlocal" and a modeline
+ * OPT_GLOBAL   for ":setglobal"
+ * OPT_LOCAL    for ":setlocal" and a modeline
  * OPT_MODELINE for a modeline
+ * OPT_WINONLY  to only set window-local options
+ * OPT_NOWIN	to skip setting window-local options
  *
  * returns FAIL if an error is detected, OK otherwise
  */
@@ -3977,6 +3979,11 @@
 			  && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
 		goto skip;
 
+	    /* Skip all options that are window-local (used for :vimgrep). */
+	    if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
+					   && options[opt_idx].var == VAR_WIN)
+		goto skip;
+
 	    /* Disallow changing some options from modelines */
 	    if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
 	    {
diff --git a/src/quickfix.c b/src/quickfix.c
index 1431c76..a8e5099 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -3039,12 +3039,12 @@
 	}
 	else
 	{
+	    /* Try for a match in all lines of the buffer.
+	     * For ":1vimgrep" look for first match only. */
 	    found_match = FALSE;
-	    /* Try for a match in all lines of the buffer. */
 	    for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0;
 								       ++lnum)
 	    {
-		/* For ":1vimgrep" look for multiple matches. */
 		col = 0;
 		while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
 								     col) > 0)
@@ -3093,12 +3093,17 @@
 		    wipe_dummy_buffer(buf);
 		    buf = NULL;
 		}
-		else if (!buf_hide(buf))
+		else if (!cmdmod.hide
+			    || buf->b_p_bh[0] == 'u'	/* "unload" */
+			    || buf->b_p_bh[0] == 'w'	/* "wipe" */
+			    || buf->b_p_bh[0] == 'd')	/* "delete" */
 		{
-		    /* When not hiding the buffer and no match was found we
-		     * don't need to remember the buffer, wipe it out.  If
-		     * there was a match and it wasn't the first one or we
-		     * won't jump there: only unload the buffer. */
+		    /* When no match was found we don't need to remember the
+		     * buffer, wipe it out.  If there was a match and it
+		     * wasn't the first one or we won't jump there: only
+		     * unload the buffer.
+		     * Ignore 'hidden' here, because it may lead to having too
+		     * many swap files. */
 		    if (!found_match)
 		    {
 			wipe_dummy_buffer(buf);
@@ -3115,7 +3120,8 @@
 		{
 		    /* The buffer is still loaded, the Filetype autocommands
 		     * need to be done now, in that buffer.  And the modelines
-		     * need to be done (again). */
+		     * need to be done (again).  But not the window-local
+		     * options! */
 #if defined(FEAT_AUTOCMD)
 		    aucmd_prepbuf(&aco, buf);
 #else
@@ -3127,7 +3133,7 @@
 		    apply_autocmds(EVENT_FILETYPE, buf->b_p_ft,
 						     buf->b_fname, TRUE, buf);
 #endif
-		    do_modelines(FALSE);
+		    do_modelines(OPT_NOWIN);
 #if defined(FEAT_AUTOCMD)
 		    aucmd_restbuf(&aco);
 #else
diff --git a/src/version.h b/src/version.h
index 9f2cbcc..79f06be 100644
--- a/src/version.h
+++ b/src/version.h
@@ -36,5 +36,5 @@
 #define VIM_VERSION_NODOT	"vim70aa"
 #define VIM_VERSION_SHORT	"7.0aa"
 #define VIM_VERSION_MEDIUM	"7.0aa ALPHA"
-#define VIM_VERSION_LONG	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 7)"
-#define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 7, compiled "
+#define VIM_VERSION_LONG	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 8)"
+#define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 7.0aa ALPHA (2006 Mar 8, compiled "
diff --git a/src/vim.h b/src/vim.h
index a58ce7c..93c9446 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1021,6 +1021,7 @@
 #define OPT_LOCAL	4	/* use local value */
 #define OPT_MODELINE	8	/* option in modeline */
 #define OPT_WINONLY	16	/* only set window-local options */
+#define OPT_NOWIN	32	/* don't set window-local options */
 
 /* Magic chars used in confirm dialog strings */
 #define DLG_BUTTON_SEP	'\n'