]> granicus.if.org Git - vim/commitdiff
patch 8.2.3400: ":z!" is not supported v8.2.3400
authorDominique Pelle <dominique.pelle@gmail.com>
Sat, 4 Sep 2021 11:44:01 +0000 (13:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 4 Sep 2021 11:44:01 +0000 (13:44 +0200)
Problem:    ":z!" is not supported.
Solution:   Make ":z!" work and add tests. (Dominique PellĂ©, closes #8836)
            Use display height instead of current window height.

runtime/doc/various.txt
src/ex_cmds.c
src/ex_cmds.h
src/testdir/test_ex_z.vim
src/version.c

index 0ad12e80424e453436f94b446ef7fac3734c2487..10974ac188b2ffaf698867965a6e15183b4d2013 100644 (file)
@@ -170,8 +170,13 @@ g8                 Print the hex values of the bytes used in the
                        If the mark is "=", a line of dashes is printed
                        around the current line.
 
-:[range]z#[+-^.=][count]                               *:z#*
-                       Like ":z", but number the lines.
+                                                       *:z!
+:[range]z![+-^.=][count]
+                       Like ":z:", but when [count] is not specified, it
+                       defaults to the Vim window height minus one.
+
+:[range]z[!]#[+-^.=][count]                            *:z#*
+                       Like ":z" or ":z!", but number the lines.
 
                                                        *:=*
 := [flags]             Print the last line number.
@@ -418,7 +423,7 @@ N  *+multi_lang*    non-English language support |multi-lang|
 m  *+mzscheme*         Mzscheme interface |mzscheme|
 m  *+mzscheme/dyn*     Mzscheme interface |mzscheme-dynamic| |/dyn|
 m  *+netbeans_intg*    |netbeans|
-   *+num64*            64-bit Number support |Number| 
+   *+num64*            64-bit Number support |Number|
                        Always enabled since 8.2.0271, use v:numbersize to
                        check the actual size of a Number.
 m  *+ole*              Win32 GUI only: |ole-interface|
index 021296d38c248a39cc0e2ac6b9bff710f5ff6e39..5c92e094e1f9fc58f2e111c8fe4112343c8b3717 100644 (file)
@@ -3445,7 +3445,7 @@ ex_z(exarg_T *eap)
     // Vi compatible: ":z!" uses display height, without a count uses
     // 'scroll'
     if (eap->forceit)
-       bigness = curwin->w_height;
+       bigness = Rows - 1;
     else if (!ONE_WINDOW)
        bigness = curwin->w_height - 3;
     else
index 480bf3c04422d8683a7df5f7d3549593ec23e641..1ea74422c3b0a0d9c8071779ed24440c3098f4c8 100644 (file)
@@ -1824,7 +1824,7 @@ EXCMD(CMD_yank,           "yank",         ex_operators,
        EX_RANGE|EX_WHOLEFOLD|EX_REGSTR|EX_COUNT|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
        ADDR_LINES),
 EXCMD(CMD_z,           "z",            ex_z,
-       EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_FLAGS|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
+       EX_RANGE|EX_WHOLEFOLD|EX_BANG|EX_EXTRA|EX_FLAGS|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
        ADDR_LINES),
 
 // commands that don't start with a letter
index fcb82b3acf917ababdaff2cf11ff716a6b0cc405..4607d96856d2ffb02b08caf4db86fab22fc0e0e2 100644 (file)
@@ -16,8 +16,9 @@ func Test_z()
   call assert_equal(23, line('.'))
 
   let a = execute('20z+3')
-  " FIXME: I would expect the same result as '20z3' but it
-  " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
+  " FIXME: I would expect the same result as '20z3' since 'help z'
+  " says: Specifying no mark at all is the same as "+".
+  " However it " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"?
   "call assert_equal("\n20\n21\n22", a)
   "call assert_equal(22, line('.'))
 
@@ -55,19 +56,48 @@ func Test_z()
   call assert_equal(100, line('.'))
 
   let a = execute('20z-1000')
-  call assert_match("^\n1\n2\n.*\n19\n20$", a)
   call assert_equal(20, line('.'))
 
   let a = execute('20z=1000')
   call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a)
   call assert_equal(20, line('.'))
 
+  " Tests with multiple windows.
+  5split
+  call setline(1, range(1, 100))
+  " Without a count, the number line is window height - 3.
+  let a = execute('20z')
+  call assert_equal("\n20\n21", a)
+  call assert_equal(21, line('.'))
+  " If window height - 3 is less than 1, it should be clamped to 1.
+  resize 2
+  let a = execute('20z')
+  call assert_equal("\n20", a)
+  call assert_equal(20, line('.'))
+
   call assert_fails('20z=a', 'E144:')
 
   set window& scroll&
   bw!
 endfunc
 
+" :z! is the same as :z but count uses the Vim window height when not specified.
+func Test_z_bang()
+  4split
+  call setline(1, range(1, 20))
+
+  let a = execute('10z!')
+  call assert_equal("\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20", a)
+
+  let a = execute('10z!#')
+  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)
+
+  let a = execute('10z!3')
+  call assert_equal("\n10\n11\n12", a)
+
+  %bwipe!
+endfunc
+
 func Test_z_overflow()
   " This used to access invalid memory as a result of an integer overflow
   " and freeze vim.
index a9219db153e75fe01c7d0fdb06ff88f88d47a68b..7482d3f7fdb79d315c130b4ed0e9680a49c41bd6 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3400,
 /**/
     3399,
 /**/