Skip to content

Commit 94f4ffa

Browse files
committed
patch 8.2.1413: previous tab page not usable from an Ex command
Problem: Previous tab page not usable from an Ex command. Solution: Add the "#" argument for :tabnext et al. (Yegappan Lakshmanan, closes #6677)
1 parent 6e4cfff commit 94f4ffa

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

runtime/doc/tabpage.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ something else.
142142
:tabclose + " close the next tab page
143143
:tabclose 3 " close the third tab page
144144
:tabclose $ " close the last tab page
145+
:tabclose # " close the last accessed tab page
145146
<
146147
*:tabo* *:tabonly*
147148
:tabo[nly][!] Close all other tab pages.
@@ -170,6 +171,8 @@ something else.
170171
" one
171172
:tabonly 1 " close all tab pages except the first one
172173
:tabonly $ " close all tab pages except the last one
174+
:tabonly # " close all tab pages except the last
175+
" accessed one
173176
174177
175178
SWITCHING TO ANOTHER TAB PAGE:
@@ -192,6 +195,7 @@ gt *i_CTRL-<PageDown>* *i_<C-PageDown>*
192195
:+2tabnext " go to the two next tab page
193196
:1tabnext " go to the first tab page
194197
:$tabnext " go to the last tab page
198+
:tabnext # " go to the last accessed tab page
195199
:tabnext $ " as above
196200
:tabnext - " go to the previous tab page
197201
:tabnext -1 " as above
@@ -255,6 +259,8 @@ REORDERING TAB PAGES:
255259
:tabmove " move the tab page to the last
256260
:$tabmove " as above
257261
:tabmove $ " as above
262+
:tabmove # " move the tab page after the last accessed
263+
" tab page
258264
259265
:tabm[ove] +[N]
260266
:tabm[ove] -[N]

src/ex_docmd.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,6 +5412,15 @@ get_tabpage_arg(exarg_T *eap)
54125412
{
54135413
if (STRCMP(p, "$") == 0)
54145414
tab_number = LAST_TAB_NR;
5415+
else if (STRCMP(p, "#") == 0)
5416+
if (valid_tabpage(lastused_tabpage))
5417+
tab_number = tabpage_index(lastused_tabpage);
5418+
else
5419+
{
5420+
eap->errmsg = ex_errmsg(e_invargval, eap->arg);
5421+
tab_number = 0;
5422+
goto theend;
5423+
}
54155424
else if (p == p_save || *p_save == '-' || *p != NUL
54165425
|| tab_number > LAST_TAB_NR)
54175426
{

src/testdir/test_tabpage.vim

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ func Test_lastused_tabpage()
784784
call assert_beeps('call feedkeys("g\<Tab>", "xt")')
785785
call assert_beeps('call feedkeys("\<C-Tab>", "xt")')
786786
call assert_beeps('call feedkeys("\<C-W>g\<Tab>", "xt")')
787+
call assert_fails('tabnext #', 'E475:')
787788

788789
" open four tab pages
789790
tabnew
@@ -808,17 +809,41 @@ func Test_lastused_tabpage()
808809
call assert_equal(4, tabpagenr())
809810
call assert_equal(2, tabpagenr('#'))
810811

812+
" Test for :tabnext #
813+
tabnext #
814+
call assert_equal(2, tabpagenr())
815+
call assert_equal(4, tabpagenr('#'))
816+
811817
" Try to jump to a closed tab page
812-
tabclose 2
818+
tabclose #
813819
call assert_equal(0, tabpagenr('#'))
814820
call feedkeys("g\<Tab>", "xt")
815-
call assert_equal(3, tabpagenr())
821+
call assert_equal(2, tabpagenr())
816822
call feedkeys("\<C-Tab>", "xt")
817-
call assert_equal(3, tabpagenr())
823+
call assert_equal(2, tabpagenr())
818824
call feedkeys("\<C-W>g\<Tab>", "xt")
819-
call assert_equal(3, tabpagenr())
825+
call assert_equal(2, tabpagenr())
826+
call assert_fails('tabnext #', 'E475:')
827+
call assert_equal(2, tabpagenr())
820828

821-
tabclose!
829+
" Test for :tabonly #
830+
let wnum = win_getid()
831+
$tabnew
832+
tabonly #
833+
call assert_equal(wnum, win_getid())
834+
call assert_equal(1, tabpagenr('$'))
835+
836+
" Test for :tabmove #
837+
tabnew
838+
let wnum = win_getid()
839+
tabnew
840+
tabnew
841+
tabnext 2
842+
tabmove #
843+
call assert_equal(4, tabpagenr())
844+
call assert_equal(wnum, win_getid())
845+
846+
tabonly!
822847
endfunc
823848

824849
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1413,
757759
/**/
758760
1412,
759761
/**/

src/window.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3844,6 +3844,7 @@ free_tabpage(tabpage_T *tp)
38443844
win_new_tabpage(int after)
38453845
{
38463846
tabpage_T *tp = curtab;
3847+
tabpage_T *prev_tp = curtab;
38473848
tabpage_T *newtp;
38483849
int n;
38493850

@@ -3893,7 +3894,7 @@ win_new_tabpage(int after)
38933894
newtp->tp_topframe = topframe;
38943895
last_status(FALSE);
38953896

3896-
lastused_tabpage = tp;
3897+
lastused_tabpage = prev_tp;
38973898

38983899
#if defined(FEAT_GUI)
38993900
// When 'guioptions' includes 'L' or 'R' may have to remove or add

0 commit comments

Comments
 (0)