@@ -3088,7 +3088,7 @@ jumpto_tag(
30883088 char_u * fname ;
30893089 tagptrs_T tagp ;
30903090 int retval = FAIL ;
3091- int getfile_result ;
3091+ int getfile_result = GETFILE_UNUSED ;
30923092 int search_options ;
30933093#ifdef FEAT_SEARCH_EXTRA
30943094 int save_no_hlsearch ;
@@ -3202,7 +3202,29 @@ jumpto_tag(
32023202
32033203 /* If it was a CTRL-W CTRL-] command split window now. For ":tab tag"
32043204 * open a new tab page. */
3205- if (postponed_split || cmdmod .tab != 0 )
3205+ if (postponed_split && (swb_flags & (SWB_USEOPEN | SWB_USETAB )))
3206+ {
3207+ buf_T * existing_buf = buflist_findname_exp (fname );
3208+
3209+ if (existing_buf != NULL )
3210+ {
3211+ win_T * wp = NULL ;
3212+
3213+ if (swb_flags & SWB_USEOPEN )
3214+ wp = buf_jump_open_win (existing_buf );
3215+
3216+ /* If 'switchbuf' contains "usetab": jump to first window in any tab
3217+ * page containing "existing_buf" if one exists */
3218+ if (wp == NULL && (swb_flags & SWB_USETAB ))
3219+ wp = buf_jump_open_tab (existing_buf );
3220+ /* We've switched to the buffer, the usual loading of the file must
3221+ * be skipped. */
3222+ if (wp != NULL )
3223+ getfile_result = GETFILE_SAME_FILE ;
3224+ }
3225+ }
3226+ if (getfile_result == GETFILE_UNUSED
3227+ && (postponed_split || cmdmod .tab != 0 ))
32063228 {
32073229 if (win_split (postponed_split > 0 ? postponed_split : 0 ,
32083230 postponed_split_flags ) == FAIL )
@@ -3225,10 +3247,11 @@ jumpto_tag(
32253247#endif
32263248 keep_help_flag = curbuf -> b_help ;
32273249 }
3228- getfile_result = getfile (0 , fname , NULL , TRUE, (linenr_T )0 , forceit );
3250+ if (getfile_result == GETFILE_UNUSED )
3251+ getfile_result = getfile (0 , fname , NULL , TRUE, (linenr_T )0 , forceit );
32293252 keep_help_flag = FALSE;
32303253
3231- if (getfile_result <= 0 ) /* got to the right file */
3254+ if (GETFILE_SUCCESS ( getfile_result )) /* got to the right file */
32323255 {
32333256 curwin -> w_set_curswant = TRUE;
32343257#ifdef FEAT_WINDOWS
@@ -3377,7 +3400,7 @@ jumpto_tag(
33773400#endif
33783401
33793402 /* Return OK if jumped to another file (at least we found the file!). */
3380- if (getfile_result == -1 )
3403+ if (getfile_result == GETFILE_OPEN_OTHER )
33813404 retval = OK ;
33823405
33833406 if (retval == OK )
0 commit comments