diff options
-rw-r--r-- | runtime/doc/options.txt | 2 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 3 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 7 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 8 |
4 files changed, 17 insertions, 3 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 209b8a7aee..e52fc2a2f5 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -6014,6 +6014,8 @@ A jump table for the options with a short description can be found at |Q_op|. vsplit Just like "split" but split vertically. newtab Like "split", but open a new tab page. Overrules "split" when both are present. + uselast If included, jump to the previously used window when + jumping to errors with |quickfix| commands. *'synmaxcol'* *'smc'* 'synmaxcol' 'smc' number (default 3000) diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index ce0ea19a2f..c6e3f71016 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -612,13 +612,14 @@ EXTERN char_u *p_swb; // 'switchbuf' EXTERN unsigned swb_flags; #ifdef IN_OPTION_C static char *(p_swb_values[]) = - { "useopen", "usetab", "split", "newtab", "vsplit", NULL }; + { "useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL }; #endif #define SWB_USEOPEN 0x001 #define SWB_USETAB 0x002 #define SWB_SPLIT 0x004 #define SWB_NEWTAB 0x008 #define SWB_VSPLIT 0x010 +#define SWB_USELAST 0x020 EXTERN int p_tbs; ///< 'tagbsearch' EXTERN char_u *p_tc; ///< 'tagcase' EXTERN unsigned tc_flags; ///< flags from 'tagcase' diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 194cc5781b..5d30ca624f 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2595,8 +2595,11 @@ static void qf_goto_win_with_qfl_file(int qf_fnum) if (IS_QF_WINDOW(win)) { // Didn't find it, go to the window before the quickfix - // window. - if (altwin != NULL) { + // window, unless 'switchbuf' contains 'uselast': in this case we + // try to jump to the previously used window first. + if ((swb_flags & SWB_USELAST) && win_valid(prevwin)) { + win = prevwin; + } else if (altwin != NULL) { win = altwin; } else if (curwin->w_prev != NULL) { win = curwin->w_prev; diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 15cbf52cb5..60ffb11793 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -1642,6 +1642,14 @@ func Test_switchbuf() call assert_equal(3, tabpagenr('$')) tabfirst | enew | tabonly | only + set switchbuf=uselast + split + let last_winid = win_getid() + copen + exe "normal 1G\<CR>" + call assert_equal(last_winid, win_getid()) + enew | only + set switchbuf= edit Xqftestfile1 let file1_winid = win_getid() |