Skip to content

Commit 9b7f8ce

Browse files
committed
patch 7.4.2237
Problem: Can't use "." and "$" with ":tab". Solution: Support a range for ":tab". (Hirohito Higashi)
1 parent 920694c commit 9b7f8ce

4 files changed

Lines changed: 63 additions & 14 deletions

File tree

runtime/doc/tabpage.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,21 @@ In the GUI tab pages line you can use the right mouse button to open menu.
8787
Execute {cmd} and when it opens a new window open a new tab
8888
page instead. Doesn't work for |:diffsplit|, |:diffpatch|,
8989
|:execute| and |:normal|.
90-
When [count] is omitted the tab page appears after the current
91-
one.
92-
When [count] is specified the new tab page comes after tab
93-
page [count]. Use ":0tab cmd" to get the new tab page as the
94-
first one.
90+
If [count] is given the new tab page appears after the tab
91+
page [count] otherwise the new tab page will appear after the
92+
current one.
9593
Examples: >
96-
:tab split " opens current buffer in new tab page
97-
:tab help gt " opens tab page with help for "gt"
94+
:tab split " opens current buffer in new tab page
95+
:tab help gt " opens tab page with help for "gt"
96+
:.tab help gt " as above
97+
:+tab help " opens tab page with help after the next
98+
" tab page
99+
:-tab help " opens tab page with help before the
100+
" current one
101+
:0tab help " opens tab page with help before the
102+
" first one
103+
:$tab help " opens tab page with help after the last
104+
" one
98105
99106
CTRL-W gf Open a new tab page and edit the file name under the cursor.
100107
See |CTRL-W_gf|.
@@ -141,10 +148,11 @@ something else.
141148
given, then they become hidden. But modified buffers are
142149
never abandoned, so changes cannot get lost. >
143150
:tabonly " close all tab pages except the current
151+
" one
144152
145153
:{count}tabo[nly][!]
146154
Close all tab pages except the {count}th one. >
147-
:.tabonly " one
155+
:.tabonly " as above
148156
:-tabonly " close all tab pages except the previous
149157
" one
150158
:+tabonly " close all tab pages except the next one

src/ex_docmd.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,9 +1858,7 @@ do_one_cmd(
18581858
/*
18591859
* 2. Handle command modifiers.
18601860
*/
1861-
p = ea.cmd;
1862-
if (VIM_ISDIGIT(*ea.cmd))
1863-
p = skipwhite(skipdigits(ea.cmd));
1861+
p = skip_range(ea.cmd, NULL);
18641862
switch (*p)
18651863
{
18661864
/* When adding an entry, also modify cmd_exists(). */
@@ -1992,10 +1990,19 @@ do_one_cmd(
19921990
case 't': if (checkforcmd(&p, "tab", 3))
19931991
{
19941992
#ifdef FEAT_WINDOWS
1995-
if (vim_isdigit(*ea.cmd))
1996-
cmdmod.tab = atoi((char *)ea.cmd) + 1;
1997-
else
1993+
long tabnr = get_address(&ea, &ea.cmd, ADDR_TABS,
1994+
ea.skip, FALSE);
1995+
if (tabnr == MAXLNUM)
19981996
cmdmod.tab = tabpage_index(curtab) + 1;
1997+
else
1998+
{
1999+
if (tabnr < 0 || tabnr > LAST_TAB_NR)
2000+
{
2001+
errormsg = (char_u *)_(e_invrange);
2002+
goto doend;
2003+
}
2004+
cmdmod.tab = tabnr + 1;
2005+
}
19992006
ea.cmd = p;
20002007
#endif
20012008
continue;

src/testdir/test_tabpage.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,36 @@ function Test_tabpage_with_autocmd()
186186
bw!
187187
endfunction
188188

189+
function Test_tabpage_with_tab_modifier()
190+
for n in range(4)
191+
tabedit
192+
endfor
193+
194+
function s:check_tab(pre_nr, cmd, post_nr)
195+
exec 'tabnext ' . a:pre_nr
196+
exec a:cmd
197+
call assert_equal(a:post_nr, tabpagenr())
198+
call assert_equal('help', &filetype)
199+
helpclose
200+
endfunc
201+
202+
call s:check_tab(1, 'tab help', 2)
203+
call s:check_tab(1, '3tab help', 4)
204+
call s:check_tab(1, '.tab help', 2)
205+
call s:check_tab(1, '.+1tab help', 3)
206+
call s:check_tab(1, '0tab help', 1)
207+
call s:check_tab(2, '+tab help', 4)
208+
call s:check_tab(2, '+2tab help', 5)
209+
call s:check_tab(4, '-tab help', 4)
210+
call s:check_tab(4, '-2tab help', 3)
211+
call s:check_tab(3, '$tab help', 6)
212+
call assert_fails('99tab help', 'E16:')
213+
call assert_fails('+99tab help', 'E16:')
214+
call assert_fails('-99tab help', 'E16:')
215+
216+
delfunction s:check_tab
217+
tabonly!
218+
bw!
219+
endfunction
220+
189221
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2237,
766768
/**/
767769
2236,
768770
/**/

0 commit comments

Comments
 (0)