aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-09-06 20:13:40 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-10 15:35:19 +0100
commitf46341fa43075443241fe641905656c74a9523ee (patch)
tree7bd2db9da487ced83ba39f3690bf04139dd40631
parenta73b7c2b16f80436b324404a0eda90fe158604c6 (diff)
downloadrneovim-f46341fa43075443241fe641905656c74a9523ee.tar.gz
rneovim-f46341fa43075443241fe641905656c74a9523ee.tar.bz2
rneovim-f46341fa43075443241fe641905656c74a9523ee.zip
vim-patch:8.2.3400: ":z!" is not supported
Problem: ":z!" is not supported. Solution: Make ":z!" work and add tests. (Dominique Pellé, closes vim/vim#8836) Use display height instead of current window height. https://github.com/vim/vim/commit/7f2dd1e90c1d4a30c791fae20014594641769a1e
-rw-r--r--runtime/doc/various.txt10
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/ex_cmds.lua2
-rw-r--r--src/nvim/testdir/test_ex_z.vim36
4 files changed, 42 insertions, 8 deletions
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index 29bd6e5e64..b06fa7518c 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -166,9 +166,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.
- {not in all versions of Vi, not with these arguments}
+ *: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.
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 8a93eafc81..87d9c312d9 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3090,7 +3090,7 @@ void ex_z(exarg_T *eap)
// Vi compatible: ":z!" uses display height, without a count uses
// 'scroll'
if (eap->forceit) {
- bigness = curwin->w_height_inner;
+ bigness = Rows - 1;
} else if (ONE_WINDOW) {
bigness = curwin->w_p_scr * 2;
} else {
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 7b971f464f..c388373ac1 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -3271,7 +3271,7 @@ module.cmds = {
},
{
command='z',
- flags=bit.bor(RANGE, WHOLEFOLD, EXTRA, FLAGS, TRLBAR, CMDWIN),
+ flags=bit.bor(RANGE, WHOLEFOLD, BANG, EXTRA, FLAGS, TRLBAR, CMDWIN),
addr_type='ADDR_LINES',
func='ex_z',
},
diff --git a/src/nvim/testdir/test_ex_z.vim b/src/nvim/testdir/test_ex_z.vim
index 608a36c490..481747ce84 100644
--- a/src/nvim/testdir/test_ex_z.vim
+++ b/src/nvim/testdir/test_ex_z.vim
@@ -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_bug()
" This used to access invalid memory as a result of an integer overflow
" and freeze vim.