updated for version 7.0020
diff --git a/src/eval.c b/src/eval.c
index 8416b57..88b9549 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -5571,6 +5571,10 @@
 	else if (STRICMP(name, "win95") == 0)
 	    n = mch_windows95();
 #endif
+#ifdef FEAT_NETBEANS_INTG
+	else if (STRICMP(name, "netbeans_enabled") == 0)
+	    n = usingNetbeans;
+#endif
     }
 
     retvar->var_val.var_number = n;
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index b462e1f..7ed48b9 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3208,8 +3208,8 @@
 	    workshop_file_opened((char *)curbuf->b_ffname, curbuf->b_p_ro);
 # endif
 # ifdef FEAT_NETBEANS_INTG
-	if (usingNetbeans)
-	    netbeans_file_opened((char *)curbuf->b_ffname);
+	if (usingNetbeans & ((flags & ECMD_SET_HELP) != ECMD_SET_HELP))
+	    netbeans_file_opened(curbuf);
 # endif
     }
 #endif
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index af76d734..5d0f081 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -524,6 +524,8 @@
 			RANGE|FILE1|NEEDARG|CMDWIN),
 EX(CMD_next,		"next",		ex_next,
 			RANGE|NOTADR|BANG|FILES|EDITCMD|ARGOPT|TRLBAR),
+EX(CMD_nbkey,		"nbkey",	ex_nbkey,
+			EXTRA|NOTADR|NEEDARG),
 EX(CMD_new,		"new",		ex_splitview,
 			BANG|FILE1|RANGE|NOTADR|EDITCMD|ARGOPT|TRLBAR),
 EX(CMD_nmap,		"nmap",		ex_map,
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index bc72773..6d6d55d 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -3309,11 +3309,6 @@
     /* Pretend we don't have input focus, we will get an event if we do. */
     gui.in_focus = FALSE;
 
-#ifdef FEAT_NETBEANS_INTG
-    if (usingNetbeans)
-	netbeans_gtk_connect();
-# endif
-
     return OK;
 }
 
diff --git a/src/gui_x11.c b/src/gui_x11.c
index 7087e02..e57bb92 100644
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -1540,10 +1540,6 @@
     if (usingSunWorkShop)
 	workshop_connect(app_context);
 #endif
-#ifdef FEAT_NETBEANS_INTG
-    if (usingNetbeans)
-	netbeans_Xt_connect(app_context);
-#endif
 
 #ifdef FEAT_BEVAL
     gui_init_tooltip_font();
diff --git a/src/main.c b/src/main.c
index 0f63d78..3976a44 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1255,6 +1255,20 @@
 #endif
 	    )
     {
+#ifdef NBDEBUG
+	/*
+	 * This shouldn't be necessary. But if I run netbeans with the log
+	 * output coming to the console and XOpenDisplay fails, I get vim
+	 * trying to start with input/output to my console tty.  This fills my
+	 * input buffer so fast I can't even kill the process in under 2
+	 * minutes (and it beeps continuosly the whole time :-)
+	 */
+	if (usingNetbeans && (!stdout_isatty || !input_isatty))
+	{
+	    mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n"));
+	    exit(1);
+	}
+#endif
 	if (!stdout_isatty)
 	    mch_errmsg(_("Vim: Warning: Output is not to a terminal\n"));
 	if (!input_isatty)
diff --git a/src/memline.c b/src/memline.c
index 67d233b..a3bd9d7 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -2462,8 +2462,8 @@
     if (usingNetbeans)
     {
 	if (STRLEN(line) > 0)
-	    netbeans_inserted(buf, lnum+1, (colnr_T)0, 0, line, STRLEN(line));
-	netbeans_inserted(buf, lnum+1, (colnr_T)STRLEN(line), 0,
+	    netbeans_inserted(buf, lnum+1, (colnr_T)0, line, STRLEN(line));
+	netbeans_inserted(buf, lnum+1, (colnr_T)STRLEN(line),
 							   (char_u *)"\n", 1);
     }
 #endif
@@ -2500,7 +2500,7 @@
     if (usingNetbeans)
     {
 	netbeans_removed(curbuf, lnum, 0, (long)STRLEN(ml_get(lnum)));
-	netbeans_inserted(curbuf, lnum, 0, 0, line, STRLEN(line));
+	netbeans_inserted(curbuf, lnum, 0, line, STRLEN(line));
     }
 #endif
     if (curbuf->b_ml.ml_line_lnum != lnum)	    /* other line buffered */
@@ -2605,7 +2605,7 @@
 
 #ifdef FEAT_NETBEANS_INTG
     if (usingNetbeans)
-	netbeans_removed(buf, lnum, 0, line_size);
+	netbeans_removed(buf, lnum, 0, (long)line_size);
 #endif
 
 /*