Skip to content

Commit 7f2dd1e

Browse files
dpellebrammool
authored andcommitted
patch 8.2.3400: ":z!" is not supported
Problem: ":z!" is not supported. Solution: Make ":z!" work and add tests. (Dominique Pellé, closes #8836) Use display height instead of current window height.
1 parent deba5eb commit 7f2dd1e

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

runtime/doc/various.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ g8 Print the hex values of the bytes used in the
170170
If the mark is "=", a line of dashes is printed
171171
around the current line.
172172

173-
:[range]z#[+-^.=][count] *:z#*
174-
Like ":z", but number the lines.
173+
*:z!
174+
:[range]z![+-^.=][count]
175+
Like ":z:", but when [count] is not specified, it
176+
defaults to the Vim window height minus one.
177+
178+
:[range]z[!]#[+-^.=][count] *:z#*
179+
Like ":z" or ":z!", but number the lines.
175180

176181
*:=*
177182
:= [flags] Print the last line number.
@@ -418,7 +423,7 @@ N *+multi_lang* non-English language support |multi-lang|
418423
m *+mzscheme* Mzscheme interface |mzscheme|
419424
m *+mzscheme/dyn* Mzscheme interface |mzscheme-dynamic| |/dyn|
420425
m *+netbeans_intg* |netbeans|
421-
*+num64* 64-bit Number support |Number|
426+
*+num64* 64-bit Number support |Number|
422427
Always enabled since 8.2.0271, use v:numbersize to
423428
check the actual size of a Number.
424429
m *+ole* Win32 GUI only: |ole-interface|

src/ex_cmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3445,7 +3445,7 @@ ex_z(exarg_T *eap)
34453445
// Vi compatible: ":z!" uses display height, without a count uses
34463446
// 'scroll'
34473447
if (eap->forceit)
3448-
bigness = curwin->w_height;
3448+
bigness = Rows - 1;
34493449
else if (!ONE_WINDOW)
34503450
bigness = curwin->w_height - 3;
34513451
else

src/ex_cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ EXCMD(CMD_yank, "yank", ex_operators,
18241824
EX_RANGE|EX_WHOLEFOLD|EX_REGSTR|EX_COUNT|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
18251825
ADDR_LINES),
18261826
EXCMD(CMD_z, "z", ex_z,
1827-
EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_FLAGS|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
1827+
EX_RANGE|EX_WHOLEFOLD|EX_BANG|EX_EXTRA|EX_FLAGS|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
18281828
ADDR_LINES),
18291829

18301830
// commands that don't start with a letter

src/testdir/test_ex_z.vim

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ func Test_z()
1616
call assert_equal(23, line('.'))
1717

1818
let a = execute('20z+3')
19-
" FIXME: I would expect the same result as '20z3' but it
20-
" gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
19+
" FIXME: I would expect the same result as '20z3' since 'help z'
20+
" says: Specifying no mark at all is the same as "+".
21+
" However it " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
2122
"call assert_equal("\n20\n21\n22", a)
2223
"call assert_equal(22, line('.'))
2324

@@ -55,19 +56,48 @@ func Test_z()
5556
call assert_equal(100, line('.'))
5657

5758
let a = execute('20z-1000')
58-
call assert_match("^\n1\n2\n.*\n19\n20$", a)
5959
call assert_equal(20, line('.'))
6060

6161
let a = execute('20z=1000')
6262
call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a)
6363
call assert_equal(20, line('.'))
6464

65+
" Tests with multiple windows.
66+
5split
67+
call setline(1, range(1, 100))
68+
" Without a count, the number line is window height - 3.
69+
let a = execute('20z')
70+
call assert_equal("\n20\n21", a)
71+
call assert_equal(21, line('.'))
72+
" If window height - 3 is less than 1, it should be clamped to 1.
73+
resize 2
74+
let a = execute('20z')
75+
call assert_equal("\n20", a)
76+
call assert_equal(20, line('.'))
77+
6578
call assert_fails('20z=a', 'E144:')
6679

6780
set window& scroll&
6881
bw!
6982
endfunc
7083

84+
" :z! is the same as :z but count uses the Vim window height when not specified.
85+
func Test_z_bang()
86+
4split
87+
call setline(1, range(1, 20))
88+
89+
let a = execute('10z!')
90+
call assert_equal("\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20", a)
91+
92+
let a = execute('10z!#')
93+
call assert_equal("\n 10 10\n 11 11\n 12 12\n 13 13\n 14 14\n 15 15\n 16 16\n 17 17\n 18 18\n 19 19\n 20 20", a)
94+
95+
let a = execute('10z!3')
96+
call assert_equal("\n10\n11\n12", a)
97+
98+
%bwipe!
99+
endfunc
100+
71101
func Test_z_overflow()
72102
" This used to access invalid memory as a result of an integer overflow
73103
" and freeze vim.

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3400,
758760
/**/
759761
3399,
760762
/**/

0 commit comments

Comments
 (0)