--- vim-8.2.1897/src/help.c 2020-10-24 17:19:16.000000000 +0000 +++ vim-8.2.1897/src/help.c 2020-10-24 18:42:52.206685850 +0000 @@ -38,6 +38,8 @@ ex_help(exarg_T *eap) #ifdef FEAT_FOLDING int old_KeyTyped = KeyTyped; #endif + int nohelp = FALSE, nominhelp = FALSE; + char_u *mhf = NULL; if (ERROR_IF_ANY_POPUP_WINDOW) return; @@ -88,6 +90,23 @@ ex_help(exarg_T *eap) n = find_help_tags(arg, &num_matches, &matches, eap != NULL && eap->forceit); + /* + * If we didn't find the help topic, check to see whether 'helpfile' + * (typically $VIMRUNTIME/doc/help.txt) exists. If not, then we'll send the + * user to the minimized help file delivered with the core vim package which + * explains why there's no help and how to get it. + */ + if (num_matches == 0 && mch_access((char *)p_hf, F_OK) < 0) { + nohelp = TRUE; + mhf = alloc(MAXPATHL); + STRNCPY(mhf, p_hf, MAXPATHL - 1); + mhf[STRLEN(mhf) - 8] = '\0'; + STRNCAT(mhf, "help_minimized.txt", MAXPATHL - STRLEN(mhf) - 1); + + if (mch_access((char *)mhf, F_OK) < 0) + nominhelp = TRUE; + } + i = 0; #ifdef FEAT_MULTI_LANG if (n != FAIL && lang != NULL) @@ -100,7 +119,7 @@ ex_help(exarg_T *eap) break; } #endif - if (i >= num_matches || n == FAIL) + if (!nohelp && i >= num_matches || n == FAIL) { #ifdef FEAT_MULTI_LANG if (lang != NULL) @@ -113,9 +132,11 @@ ex_help(exarg_T *eap) return; } - // The first match (in the requested language) is the best match. - tag = vim_strsave(matches[i]); - FreeWild(num_matches, matches); + if (!nohelp) { + /* The first match (in the requested language) is the best match. */ + tag = vim_strsave(matches[i]); + FreeWild(num_matches, matches); + } #ifdef FEAT_GUI need_mouse_correct = TRUE; @@ -137,12 +158,14 @@ ex_help(exarg_T *eap) { // There is no help window yet. // Try to open the file specified by the "helpfile" option. - if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL) - { - smsg(_("Sorry, help file \"%s\" not found"), p_hf); - goto erret; + if (!nohelp || nominhelp) { + if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL) + { + smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf); + goto erret; + } + fclose(helpfd); } - fclose(helpfd); // Split off help window; put it at far top if no position // specified, the current window is vertically split and @@ -161,7 +184,7 @@ ex_help(exarg_T *eap) // set b_p_ro flag). // Set the alternate file to the previously edited file. alt_fnum = curbuf->b_fnum; - (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, + (void)do_ecmd(0, mhf, NULL, NULL, ECMD_LASTL, ECMD_HIDE + ECMD_SET_HELP, NULL); // buffer is still open, don't store info if (!cmdmod.keepalt) @@ -179,7 +202,7 @@ ex_help(exarg_T *eap) KeyTyped = old_KeyTyped; #endif - if (tag != NULL) + if (!nohelp && tag != NULL) do_tag(tag, DT_HELP, 1, FALSE, TRUE); // Delete the empty buffer if we're not using it. Careful: autocommands @@ -197,7 +220,8 @@ ex_help(exarg_T *eap) curwin->w_alt_fnum = alt_fnum; erret: - vim_free(tag); + if (!nohelp) + vim_free(tag); } /*