robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
121.4 KiB4610 linesraw
1" Test for various Normal mode commands
2
3source shared.vim
4source check.vim
5source view_util.vim
6source vim9.vim
7source screendump.vim
8
9func Setup_NewWindow()
10  10new
11  call setline(1, range(1,100))
12endfunc
13
14func MyFormatExpr()
15  " Adds '->$' at lines having numbers followed by trailing whitespace
16  for ln in range(v:lnum, v:lnum+v:count-1)
17    let line = getline(ln)
18    if getline(ln) =~# '\d\s\+$'
19      call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
20    endif
21  endfor
22endfunc
23
24func CountSpaces(type, ...)
25  " for testing operatorfunc
26  " will count the number of spaces
27  " and return the result in g:a
28  let sel_save = &selection
29  let &selection = "inclusive"
30  let reg_save = @@
31
32  if a:0  " Invoked from Visual mode, use gv command.
33    silent exe "normal! gvy"
34  elseif a:type == 'line'
35    silent exe "normal! '[V']y"
36  else
37    silent exe "normal! `[v`]y"
38  endif
39  let g:a = strlen(substitute(@@, '[^ ]', '', 'g'))
40  let &selection = sel_save
41  let @@ = reg_save
42endfunc
43
44func OpfuncDummy(type, ...)
45  " for testing operatorfunc
46  let g:opt = &linebreak
47
48  if a:0  " Invoked from Visual mode, use gv command.
49    silent exe "normal! gvy"
50  elseif a:type == 'line'
51    silent exe "normal! '[V']y"
52  else
53    silent exe "normal! `[v`]y"
54  endif
55  " Create a new dummy window
56  new
57  let g:bufnr = bufnr('%')
58endfunc
59
60func Test_normal00_optrans()
61  new
62  call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
63  1
64  exe "norm! Sfoobar\<esc>"
65  call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
66  2
67  exe "norm! $vbsone"
68  call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
69  norm! VS Second line here
70  call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
71  %d
72  call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
73  call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
74
75  1
76  norm! 2D
77  call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
78  " Nvim: no "#" flag in 'cpoptions'.
79  " set cpo+=#
80  " norm! 4D
81  " call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
82
83  " clean up
84  set cpo-=#
85  bw!
86endfunc
87
88func Test_normal01_keymodel()
89  call Setup_NewWindow()
90  " Test 1: depending on 'keymodel' <s-down> does something different
91  50
92  call feedkeys("V\<S-Up>y", 'tx')
93  call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
94  set keymodel=startsel
95  50
96  call feedkeys("V\<S-Up>y", 'tx')
97  call assert_equal(['49', '50'], getline("'<", "'>"))
98  " Start visual mode when keymodel = startsel
99  50
100  call feedkeys("\<S-Up>y", 'tx')
101  call assert_equal(['49', '5'], getreg(0, 0, 1))
102  " Use the different Shift special keys
103  50
104  call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
105  call assert_equal(['50'], getline("'<", "'>"))
106  call assert_equal(['50', ''], getreg(0, 0, 1))
107
108  " Do not start visual mode when keymodel=
109  set keymodel=
110  50
111  call feedkeys("\<S-Up>y$", 'tx')
112  call assert_equal(['42'], getreg(0, 0, 1))
113  " Stop visual mode when keymodel=stopsel
114  set keymodel=stopsel
115  50
116  call feedkeys("Vkk\<Up>yy", 'tx')
117  call assert_equal(['47'], getreg(0, 0, 1))
118
119  set keymodel=
120  50
121  call feedkeys("Vkk\<Up>yy", 'tx')
122  call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
123
124  " Test for using special keys to start visual selection
125  %d
126  call setline(1, ['red fox tail', 'red fox tail', 'red fox tail'])
127  set keymodel=startsel
128  " Test for <S-PageUp> and <S-PageDown>
129  call cursor(1, 1)
130  call feedkeys("\<S-PageDown>y", 'xt')
131  call assert_equal([0, 1, 1, 0], getpos("'<"))
132  call assert_equal([0, 3, 1, 0], getpos("'>"))
133  call feedkeys("Gz\<CR>8|\<S-PageUp>y", 'xt')
134  call assert_equal([0, 3, 1, 0], getpos("'<"))
135  call assert_equal([0, 3, 8, 0], getpos("'>"))
136  " Test for <S-C-Home> and <S-C-End>
137  call cursor(2, 12)
138  call feedkeys("\<S-C-Home>y", 'xt')
139  call assert_equal([0, 1, 1, 0], getpos("'<"))
140  call assert_equal([0, 2, 12, 0], getpos("'>"))
141  call cursor(1, 4)
142  call feedkeys("\<S-C-End>y", 'xt')
143  call assert_equal([0, 1, 4, 0], getpos("'<"))
144  call assert_equal([0, 3, 13, 0], getpos("'>"))
145  " Test for <S-C-Left> and <S-C-Right>
146  call cursor(2, 5)
147  call feedkeys("\<S-C-Right>y", 'xt')
148  call assert_equal([0, 2, 5, 0], getpos("'<"))
149  call assert_equal([0, 2, 9, 0], getpos("'>"))
150  call cursor(2, 9)
151  call feedkeys("\<S-C-Left>y", 'xt')
152  call assert_equal([0, 2, 5, 0], getpos("'<"))
153  call assert_equal([0, 2, 9, 0], getpos("'>"))
154
155  set keymodel&
156
157  " clean up
158  bw!
159endfunc
160
161func Test_normal03_join()
162  " basic join test
163  call Setup_NewWindow()
164  50
165  norm! VJ
166  call assert_equal('50 51', getline('.'))
167  $
168  norm! J
169  call assert_equal('100', getline('.'))
170  $
171  norm! V9-gJ
172  call assert_equal('919293949596979899100', getline('.'))
173  call setline(1, range(1,100))
174  $
175  :j 10
176  call assert_equal('100', getline('.'))
177  call assert_beeps('normal GVJ')
178  " clean up
179  bw!
180endfunc
181
182" basic filter test
183func Test_normal04_filter()
184  " only test on non windows platform
185  CheckNotMSWindows
186  call Setup_NewWindow()
187  1
188  call feedkeys("!!sed -e 's/^/|    /'\n", 'tx')
189  call assert_equal('|    1', getline('.'))
190  90
191  :sil :!echo one
192  call feedkeys('.', 'tx')
193  call assert_equal('|    90', getline('.'))
194  95
195  set cpo+=!
196  " 2 <CR>, 1: for executing the command,
197  "         2: clear hit-enter-prompt
198  call feedkeys("!!\n", 'tx')
199  call feedkeys(":!echo one\n\n", 'tx')
200  call feedkeys(".", 'tx')
201  call assert_equal('one', getline('.'))
202  set cpo-=!
203  bw!
204endfunc
205
206func Test_normal05_formatexpr()
207  " basic formatexpr test
208  call Setup_NewWindow()
209  %d_
210  call setline(1, ['here: 1   ', '2', 'here: 3   ', '4', 'not here:   '])
211  1
212  set formatexpr=MyFormatExpr()
213  norm! gqG
214  call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here:   '], getline(1,'$'))
215  set formatexpr=
216  bw!
217endfunc
218
219func Test_normal05_formatexpr_newbuf()
220  " Edit another buffer in the 'formatexpr' function
221  new
222  func! Format()
223    edit another
224  endfunc
225  set formatexpr=Format()
226  norm gqG
227  bw!
228  set formatexpr=
229endfunc
230
231func Test_normal05_formatexpr_setopt()
232  " Change the 'formatexpr' value in the function
233  new
234  func! Format()
235    set formatexpr=
236  endfunc
237  set formatexpr=Format()
238  norm gqG
239  bw!
240  set formatexpr=
241endfunc
242
243" When 'formatexpr' returns non-zero, internal formatting is used.
244func Test_normal_formatexpr_returns_nonzero()
245  new
246  call setline(1, ['one', 'two'])
247  func! Format()
248    return 1
249  endfunc
250  setlocal formatexpr=Format()
251  normal VGgq
252  call assert_equal(['one two'], getline(1, '$'))
253
254  setlocal formatexpr=
255  delfunc Format
256  bwipe!
257endfunc
258
259" Test for using a script-local function for 'formatexpr'
260func Test_formatexpr_scriptlocal_func()
261  func! s:Format()
262    let g:FormatArgs = [v:lnum, v:count]
263  endfunc
264  set formatexpr=s:Format()
265  call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
266  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
267  new | only
268  call setline(1, range(1, 40))
269  let g:FormatArgs = []
270  normal! 2GVjgq
271  call assert_equal([2, 2], g:FormatArgs)
272  bw!
273  set formatexpr=<SID>Format()
274  call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
275  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
276  new | only
277  call setline(1, range(1, 40))
278  let g:FormatArgs = []
279  normal! 4GVjgq
280  call assert_equal([4, 2], g:FormatArgs)
281  bw!
282  let &formatexpr = 's:Format()'
283  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
284  new | only
285  call setline(1, range(1, 40))
286  let g:FormatArgs = []
287  normal! 6GVjgq
288  call assert_equal([6, 2], g:FormatArgs)
289  bw!
290  let &formatexpr = '<SID>Format()'
291  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
292  new | only
293  call setline(1, range(1, 40))
294  let g:FormatArgs = []
295  normal! 8GVjgq
296  call assert_equal([8, 2], g:FormatArgs)
297  bw!
298  setlocal formatexpr=
299  setglobal formatexpr=s:Format()
300  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
301  call assert_equal('', &formatexpr)
302  new
303  call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
304  call setline(1, range(1, 40))
305  let g:FormatArgs = []
306  normal! 10GVjgq
307  call assert_equal([10, 2], g:FormatArgs)
308  bw!
309  setglobal formatexpr=<SID>Format()
310  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
311  call assert_equal('', &formatexpr)
312  new
313  call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
314  call setline(1, range(1, 40))
315  let g:FormatArgs = []
316  normal! 12GVjgq
317  call assert_equal([12, 2], g:FormatArgs)
318  bw!
319  let &g:formatexpr = 's:Format()'
320  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
321  call assert_equal('', &formatexpr)
322  new
323  call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
324  call setline(1, range(1, 40))
325  let g:FormatArgs = []
326  normal! 14GVjgq
327  call assert_equal([14, 2], g:FormatArgs)
328  bw!
329  let &g:formatexpr = '<SID>Format()'
330  call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
331  call assert_equal('', &formatexpr)
332  new
333  call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
334  call setline(1, range(1, 40))
335  let g:FormatArgs = []
336  normal! 16GVjgq
337  call assert_equal([16, 2], g:FormatArgs)
338  bw!
339  set formatexpr=
340  delfunc s:Format
341  bw!
342endfunc
343
344" basic test for formatprg
345func Test_normal06_formatprg()
346  " only test on non windows platform
347  CheckNotMSWindows
348
349  " uses sed to number non-empty lines
350  call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/    /', '}'''], 'Xsed_format.sh', 'D')
351  call system('chmod +x ./Xsed_format.sh')
352  let text = ['a', '', 'c', '', ' ', 'd', 'e']
353  let expected = ['1    a', '', '3    c', '', '5     ', '6    d', '7    e']
354
355  10new
356  call setline(1, text)
357  set formatprg=./Xsed_format.sh
358  norm! gggqG
359  call assert_equal(expected, getline(1, '$'))
360  %d
361
362  call setline(1, text)
363  set formatprg=donothing
364  setlocal formatprg=./Xsed_format.sh
365  norm! gggqG
366  call assert_equal(expected, getline(1, '$'))
367  %d
368
369  " Check for the command-line ranges added to 'formatprg'
370  set formatprg=cat
371  call setline(1, ['one', 'two', 'three', 'four', 'five'])
372  call feedkeys('gggqG', 'xt')
373  call assert_equal('.,$!cat', @:)
374  call feedkeys('2Ggq2j', 'xt')
375  call assert_equal('.,.+2!cat', @:)
376
377  bw!
378  " clean up
379  set formatprg=
380  setlocal formatprg=
381endfunc
382
383func Test_normal07_internalfmt()
384  " basic test for internal formatter to textwidth of 12
385  let list=range(1,11)
386  call map(list, 'v:val."    "')
387  10new
388  call setline(1, list)
389  set tw=12
390  norm! ggVGgq
391  call assert_equal(['1    2    3', '4    5    6', '7    8    9', '10    11    '], getline(1, '$'))
392  " clean up
393  set tw=0
394  bw!
395endfunc
396
397" basic tests for foldopen/folddelete
398func Test_normal08_fold()
399  CheckFeature folding
400  call Setup_NewWindow()
401  50
402  setl foldenable fdm=marker
403  " First fold
404  norm! V4jzf
405  " check that folds have been created
406  call assert_equal(['50/* {{{ */', '51', '52', '53', '54/* }}} */'], getline(50,54))
407  " Second fold
408  46
409  norm! V10jzf
410  " check that folds have been created
411  call assert_equal('46/* {{{ */', getline(46))
412  call assert_equal('60/* }}} */', getline(60))
413  norm! k
414  call assert_equal('45', getline('.'))
415  norm! j
416  call assert_equal('46/* {{{ */', getline('.'))
417  norm! j
418  call assert_equal('61', getline('.'))
419  norm! k
420  " open a fold
421  norm! Vzo
422  norm! k
423  call assert_equal('45', getline('.'))
424  norm! j
425  call assert_equal('46/* {{{ */', getline('.'))
426  norm! j
427  call assert_equal('47', getline('.'))
428  norm! k
429  norm! zcVzO
430  call assert_equal('46/* {{{ */', getline('.'))
431  norm! j
432  call assert_equal('47', getline('.'))
433  norm! j
434  call assert_equal('48', getline('.'))
435  norm! j
436  call assert_equal('49', getline('.'))
437  norm! j
438  call assert_equal('50/* {{{ */', getline('.'))
439  norm! j
440  call assert_equal('51', getline('.'))
441  " delete folds
442  :46
443  " collapse fold
444  norm! V14jzC
445  " delete all folds recursively
446  norm! VzD
447  call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
448
449  " clean up
450  setl nofoldenable fdm=marker
451  bw!
452endfunc
453
454func Test_normal09a_operatorfunc()
455  " Test operatorfunc
456  call Setup_NewWindow()
457  " Add some spaces for counting
458  50,60s/$/  /
459  unlet! g:a
460  let g:a=0
461  nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
462  vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
463  50
464  norm V2j,,
465  call assert_equal(6, g:a)
466  norm V,,
467  call assert_equal(2, g:a)
468  norm ,,l
469  call assert_equal(0, g:a)
470  50
471  exe "norm 0\<c-v>10j2l,,"
472  call assert_equal(11, g:a)
473  50
474  norm V10j,,
475  call assert_equal(22, g:a)
476
477  " clean up
478  unmap <buffer> ,,
479  set opfunc=
480  unlet! g:a
481  bw!
482endfunc
483
484func Test_normal09b_operatorfunc()
485  " Test operatorfunc
486  call Setup_NewWindow()
487  " Add some spaces for counting
488  50,60s/$/  /
489  unlet! g:opt
490  set linebreak
491  nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
492  50
493  norm ,,j
494  exe "bd!" g:bufnr
495  call assert_true(&linebreak)
496  call assert_equal(g:opt, &linebreak)
497  set nolinebreak
498  norm ,,j
499  exe "bd!" g:bufnr
500  call assert_false(&linebreak)
501  call assert_equal(g:opt, &linebreak)
502
503  " clean up
504  unmap <buffer> ,,
505  set opfunc=
506  call assert_fails('normal Vg@', 'E774:')
507  bw!
508  unlet! g:opt
509endfunc
510
511func OperatorfuncRedo(_)
512  let g:opfunc_count = v:count
513endfunc
514
515func Underscorize(_)
516  normal! '[V']r_
517endfunc
518
519func Test_normal09c_operatorfunc()
520  " Test redoing operatorfunc
521  new
522  call setline(1, 'some text')
523  set operatorfunc=OperatorfuncRedo
524  normal v3g@
525  call assert_equal(3, g:opfunc_count)
526  let g:opfunc_count = 0
527  normal .
528  call assert_equal(3, g:opfunc_count)
529
530  bw!
531  unlet g:opfunc_count
532
533  " Test redoing Visual mode
534  set operatorfunc=Underscorize
535  new
536  call setline(1, ['first', 'first', 'third', 'third', 'second'])
537  normal! 1GVjg@
538  normal! 3G.
539  " Nvim: "." re-executes the captured keysequence ("Vjg@"), not an equal-size
540  " reselect. At the last line the replayed "j" fails, aborting the replay:
541  " nothing is applied (and the pending Visual mode is left active).
542  normal! 5G.
543  exe "normal! \<Esc>"
544  call assert_equal(['_____', '_____', '_____', '_____', 'second'], getline(1, '$'))
545  bwipe!
546  set operatorfunc=
547endfunc
548
549" Test for different ways of setting the 'operatorfunc' option
550func Test_opfunc_callback()
551  new
552  func OpFunc1(callnr, type)
553    let g:OpFunc1Args = [a:callnr, a:type]
554  endfunc
555  func OpFunc2(type)
556    let g:OpFunc2Args = [a:type]
557  endfunc
558
559  let lines =<< trim END
560    #" Test for using a function name
561    LET &opfunc = 'g:OpFunc2'
562    LET g:OpFunc2Args = []
563    normal! g@l
564    call assert_equal(['char'], g:OpFunc2Args)
565
566    #" Test for using a function()
567    set opfunc=function('g:OpFunc1',\ [10])
568    LET g:OpFunc1Args = []
569    normal! g@l
570    call assert_equal([10, 'char'], g:OpFunc1Args)
571
572    #" Using a funcref variable to set 'operatorfunc'
573    VAR Fn = function('g:OpFunc1', [11])
574    LET &opfunc = Fn
575    LET g:OpFunc1Args = []
576    normal! g@l
577    call assert_equal([11, 'char'], g:OpFunc1Args)
578
579    #" Using a string(funcref_variable) to set 'operatorfunc'
580    LET Fn = function('g:OpFunc1', [12])
581    LET &operatorfunc = string(Fn)
582    LET g:OpFunc1Args = []
583    normal! g@l
584    call assert_equal([12, 'char'], g:OpFunc1Args)
585
586    #" Test for using a funcref()
587    set operatorfunc=funcref('g:OpFunc1',\ [13])
588    LET g:OpFunc1Args = []
589    normal! g@l
590    call assert_equal([13, 'char'], g:OpFunc1Args)
591
592    #" Using a funcref variable to set 'operatorfunc'
593    LET Fn = funcref('g:OpFunc1', [14])
594    LET &opfunc = Fn
595    LET g:OpFunc1Args = []
596    normal! g@l
597    call assert_equal([14, 'char'], g:OpFunc1Args)
598
599    #" Using a string(funcref_variable) to set 'operatorfunc'
600    LET Fn = funcref('g:OpFunc1', [15])
601    LET &opfunc = string(Fn)
602    LET g:OpFunc1Args = []
603    normal! g@l
604    call assert_equal([15, 'char'], g:OpFunc1Args)
605
606    #" Test for using a lambda function using set
607    VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND"
608    LET optval = substitute(optval, ' ', '\\ ', 'g')
609    exe "set opfunc=" .. optval
610    LET g:OpFunc1Args = []
611    normal! g@l
612    call assert_equal([16, 'char'], g:OpFunc1Args)
613
614    #" Test for using a lambda function using LET
615    LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND
616    LET g:OpFunc1Args = []
617    normal! g@l
618    call assert_equal([17, 'char'], g:OpFunc1Args)
619
620    #" Set 'operatorfunc' to a string(lambda expression)
621    LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND'
622    LET g:OpFunc1Args = []
623    normal! g@l
624    call assert_equal([18, 'char'], g:OpFunc1Args)
625
626    #" Set 'operatorfunc' to a variable with a lambda expression
627    VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND
628    LET &opfunc = Lambda
629    LET g:OpFunc1Args = []
630    normal! g@l
631    call assert_equal([19, 'char'], g:OpFunc1Args)
632
633    #" Set 'operatorfunc' to a string(variable with a lambda expression)
634    LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND
635    LET &opfunc = string(Lambda)
636    LET g:OpFunc1Args = []
637    normal! g@l
638    call assert_equal([20, 'char'], g:OpFunc1Args)
639
640    #" Try to use 'operatorfunc' after the function is deleted
641    func g:TmpOpFunc1(type)
642      let g:TmpOpFunc1Args = [21, a:type]
643    endfunc
644    LET &opfunc = function('g:TmpOpFunc1')
645    delfunc g:TmpOpFunc1
646    call test_garbagecollect_now()
647    LET g:TmpOpFunc1Args = []
648    call assert_fails('normal! g@l', 'E117:')
649    call assert_equal([], g:TmpOpFunc1Args)
650
651    #" Try to use a function with two arguments for 'operatorfunc'
652    func g:TmpOpFunc2(x, y)
653      let g:TmpOpFunc2Args = [a:x, a:y]
654    endfunc
655    set opfunc=TmpOpFunc2
656    LET g:TmpOpFunc2Args = []
657    call assert_fails('normal! g@l', 'E119:')
658    call assert_equal([], g:TmpOpFunc2Args)
659    delfunc TmpOpFunc2
660
661    #" Try to use a lambda function with two arguments for 'operatorfunc'
662    LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND
663    LET g:OpFunc1Args = []
664    call assert_fails('normal! g@l', 'E119:')
665    call assert_equal([], g:OpFunc1Args)
666
667    #" Test for clearing the 'operatorfunc' option
668    set opfunc=''
669    set opfunc&
670    call assert_fails("set opfunc=function('abc')", "E700:")
671    call assert_fails("set opfunc=funcref('abc')", "E700:")
672
673    #" set 'operatorfunc' to a non-existing function
674    LET &opfunc = function('g:OpFunc1', [23])
675    call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:')
676    call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
677    LET g:OpFunc1Args = []
678    normal! g@l
679    call assert_equal([23, 'char'], g:OpFunc1Args)
680  END
681  call CheckTransLegacySuccess(lines)
682
683  " Test for using a script-local function name
684  func s:OpFunc3(type)
685    let g:OpFunc3Args = [a:type]
686  endfunc
687  set opfunc=s:OpFunc3
688  let g:OpFunc3Args = []
689  normal! g@l
690  call assert_equal(['char'], g:OpFunc3Args)
691
692  let &opfunc = 's:OpFunc3'
693  let g:OpFunc3Args = []
694  normal! g@l
695  call assert_equal(['char'], g:OpFunc3Args)
696  delfunc s:OpFunc3
697
698  " Using Vim9 lambda expression in legacy context should fail
699  set opfunc=(a)\ =>\ OpFunc1(24,\ a)
700  let g:OpFunc1Args = []
701  call assert_fails('normal! g@l', 'E117:')
702  call assert_equal([], g:OpFunc1Args)
703
704  " set 'operatorfunc' to a partial with dict. This used to cause a crash.
705  func SetOpFunc()
706    let operator = {'execute': function('OperatorExecute')}
707    let &opfunc = operator.execute
708  endfunc
709  func OperatorExecute(_) dict
710  endfunc
711  call SetOpFunc()
712  call test_garbagecollect_now()
713  set operatorfunc=
714  delfunc SetOpFunc
715  delfunc OperatorExecute
716
717  " Vim9 tests
718  let lines =<< trim END
719    vim9script
720
721    def g:Vim9opFunc(val: number, type: string): void
722      g:OpFunc1Args = [val, type]
723    enddef
724
725    # Test for using a def function with opfunc
726    set opfunc=function('g:Vim9opFunc',\ [60])
727    g:OpFunc1Args = []
728    normal! g@l
729    assert_equal([60, 'char'], g:OpFunc1Args)
730
731    # Test for using a global function name
732    &opfunc = g:OpFunc2
733    g:OpFunc2Args = []
734    normal! g@l
735    assert_equal(['char'], g:OpFunc2Args)
736    bw!
737
738    # Test for using a script-local function name
739    def LocalOpFunc(type: string): void
740      g:LocalOpFuncArgs = [type]
741    enddef
742    &opfunc = LocalOpFunc
743    g:LocalOpFuncArgs = []
744    normal! g@l
745    assert_equal(['char'], g:LocalOpFuncArgs)
746    bw!
747  END
748  call CheckScriptSuccess(lines)
749
750  " setting 'opfunc' to a script local function outside of a script context
751  " should fail
752  let cleanup =<< trim END
753    call writefile([execute('messages')], 'Xtest.out')
754    qall
755  END
756  call writefile(cleanup, 'Xverify.vim')
757  call RunVim([], [], "-c \"set opfunc=s:abc\" -S Xverify.vim")
758  call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
759  call delete('Xtest.out')
760  call delete('Xverify.vim')
761
762  " cleanup
763  set opfunc&
764  delfunc OpFunc1
765  delfunc OpFunc2
766  unlet g:OpFunc1Args g:OpFunc2Args
767  %bw!
768endfunc
769
770func Test_normal10_expand()
771  " Test for expand()
772  10new
773  call setline(1, ['1', 'ifooar,,cbar'])
774  2
775  norm! $
776  call assert_equal('cbar', expand('<cword>'))
777  call assert_equal('ifooar,,cbar', expand('<cWORD>'))
778
779  call setline(1, ['prx = list[idx];'])
780  1
781  let expected = ['', 'prx', 'prx', 'prx',
782	\ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
783	\ 'idx', 'idx', 'idx', 'idx',
784	\ 'list[idx]',
785	\ '];',
786	\ ]
787  for i in range(1, 16)
788    exe 'norm ' . i . '|'
789    call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
790  endfor
791
792  " Test for <cexpr> in state.val and ptr->val
793  call setline(1, 'x = state.val;')
794  call cursor(1, 10)
795  call assert_equal('state.val', expand('<cexpr>'))
796  call setline(1, 'x = ptr->val;')
797  call cursor(1, 9)
798  call assert_equal('ptr->val', expand('<cexpr>'))
799
800  if executable('echo')
801    " Test expand(`...`) i.e. backticks command expansion.
802    " MS-Windows has a trailing space.
803    call assert_match('^abcde *$', expand('`echo abcde`'))
804  endif
805
806  " Test expand(`=...`) i.e. backticks expression expansion
807  call assert_equal('5', expand('`=2+3`'))
808  call assert_equal('3.14', expand('`=3.14`'))
809
810  " clean up
811  bw!
812endfunc
813
814" Test for expand() in latin1 encoding
815func Test_normal_expand_latin1()
816  new
817  let save_enc = &encoding
818  " set encoding=latin1
819  call setline(1, 'val = item->color;')
820  call cursor(1, 11)
821  call assert_equal('color', expand("<cword>"))
822  call assert_equal('item->color', expand("<cexpr>"))
823  let &encoding = save_enc
824  bw!
825endfunc
826
827func Test_normal11_showcmd()
828  " test for 'showcmd'
829  10new
830  exe "norm! ofoobar\<esc>"
831  call assert_equal(2, line('$'))
832  set showcmd
833  exe "norm! ofoobar2\<esc>"
834  call assert_equal(3, line('$'))
835  exe "norm! VAfoobar3\<esc>"
836  call assert_equal(3, line('$'))
837  exe "norm! 0d3\<del>2l"
838  call assert_equal('obar2foobar3', getline('.'))
839  " test for the visual block size displayed in the status line
840  call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
841  call feedkeys("ggl\<C-V>lljj", 'xt')
842  redraw!
843  call assert_match('3x3$', Screenline(&lines))
844  call feedkeys("\<C-V>", 'xt')
845  " test for visually selecting a multi-byte character
846  call setline(1, ["\U2206"])
847  call feedkeys("ggv", 'xt')
848  redraw!
849  call assert_match('1-3$', Screenline(&lines))
850  call feedkeys("v", 'xt')
851  " test for visually selecting the end of line
852  call setline(1, ["foobar"])
853  call feedkeys("$vl", 'xt')
854  redraw!
855  call assert_match('2$', Screenline(&lines))
856  call feedkeys("y", 'xt')
857  call assert_equal("r\n", @")
858  bw!
859endfunc
860
861" Test for nv_error and normal command errors
862func Test_normal12_nv_error()
863  10new
864  call setline(1, range(1,5))
865  " should not do anything, just beep
866  call assert_beeps('exe "norm! <c-k>"')
867  call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
868  call assert_beeps('normal! G2dd')
869  call assert_beeps("normal! g\<C-A>")
870  call assert_beeps("normal! g\<C-X>")
871  call assert_beeps("normal! g\<C-B>")
872  " call assert_beeps("normal! vQ\<Esc>")
873  call assert_beeps("normal! 2[[")
874  call assert_beeps("normal! 2]]")
875  call assert_beeps("normal! 2[]")
876  call assert_beeps("normal! 2][")
877  call assert_beeps("normal! 4[z")
878  call assert_beeps("normal! 4]z")
879  call assert_beeps("normal! 4[c")
880  call assert_beeps("normal! 4]c")
881  call assert_beeps("normal! 200%")
882  call assert_beeps("normal! %")
883  call assert_beeps("normal! 2{")
884  call assert_beeps("normal! 2}")
885  call assert_beeps("normal! r\<Right>")
886  call assert_beeps("normal! 8ry")
887  call assert_beeps('normal! "@')
888  bw!
889endfunc
890
891func Test_normal13_help()
892  " Test for F1
893  call assert_equal(1, winnr())
894  call feedkeys("\<f1>", 'txi')
895  call assert_match('help\.txt', bufname('%'))
896  call assert_equal(2, winnr('$'))
897  bw!
898endfunc
899
900func Test_normal14_page()
901  " basic test for Ctrl-F and Ctrl-B
902  call Setup_NewWindow()
903  exe "norm! \<c-f>"
904  call assert_equal('9', getline('.'))
905  exe "norm! 2\<c-f>"
906  call assert_equal('25', getline('.'))
907  exe "norm! 2\<c-b>"
908  call assert_equal('18', getline('.'))
909  1
910  set scrolloff=5
911  exe "norm! 2\<c-f>"
912  call assert_equal('21', getline('.'))
913  exe "norm! \<c-b>"
914  call assert_equal('13', getline('.'))
915  1
916  set scrolloff=99
917  exe "norm! \<c-f>"
918  call assert_equal('13', getline('.'))
919  set scrolloff=0
920  100
921  exe "norm! $\<c-b>"
922  call assert_equal([0, 92, 1, 0, 1], getcurpos())
923  100
924  set nostartofline
925  exe "norm! $\<c-b>"
926  call assert_equal([0, 92, 2, 0, v:maxcol], getcurpos())
927  " cleanup
928  set startofline
929  bw!
930endfunc
931
932func Test_normal14_page_eol()
933  10new
934  norm oxxxxxxx
935  exe "norm 2\<c-f>"
936  " check with valgrind that cursor is put back in column 1
937  exe "norm 2\<c-b>"
938  bw!
939endfunc
940
941" Test for errors with z command
942func Test_normal_z_error()
943  call assert_beeps('normal! z2p')
944  call assert_beeps('normal! zK')
945  call assert_beeps('normal! cz1')
946endfunc
947
948func Test_normal15_z_scroll_vert()
949  " basic test for z commands that scroll the window
950  call Setup_NewWindow()
951  100
952  norm! >>
953  " Test for z<cr>
954  exe "norm! z\<cr>"
955  call assert_equal('	100', getline('.'))
956  call assert_equal(100, winsaveview()['topline'])
957  call assert_equal([0, 100, 2, 0, 9], getcurpos())
958
959  " Test for zt
960  21
961  norm! >>0zt
962  call assert_equal('	21', getline('.'))
963  call assert_equal(21, winsaveview()['topline'])
964  call assert_equal([0, 21, 1, 0, 8], getcurpos())
965
966  " Test for zb
967  30
968  norm! >>$ztzb
969  call assert_equal('	30', getline('.'))
970  call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
971  call assert_equal([0, 30, 3, 0, v:maxcol], getcurpos())
972
973  " Test for z-
974  1
975  30
976  norm! 0z-
977  call assert_equal('	30', getline('.'))
978  call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
979  call assert_equal([0, 30, 2, 0, 9], getcurpos())
980
981  " Test for z{height}<cr>
982  call assert_equal(10, winheight(0))
983  exe "norm! z12\<cr>"
984  call assert_equal(12, winheight(0))
985  exe "norm! z15\<Del>0\<cr>"
986  call assert_equal(10, winheight(0))
987
988  " Test for z.
989  1
990  21
991  norm! 0z.
992  call assert_equal('	21', getline('.'))
993  call assert_equal(17, winsaveview()['topline'])
994  call assert_equal([0, 21, 2, 0, 9], getcurpos())
995
996  " Test for zz
997  1
998  21
999  norm! 0zz
1000  call assert_equal('	21', getline('.'))
1001  call assert_equal(17, winsaveview()['topline'])
1002  call assert_equal([0, 21, 1, 0, 8], getcurpos())
1003
1004  " Test for z+
1005  11
1006  norm! zt
1007  norm! z+
1008  call assert_equal('	21', getline('.'))
1009  call assert_equal(21, winsaveview()['topline'])
1010  call assert_equal([0, 21, 2, 0, 9], getcurpos())
1011
1012  " Test for [count]z+
1013  1
1014  norm! 21z+
1015  call assert_equal('	21', getline('.'))
1016  call assert_equal(21, winsaveview()['topline'])
1017  call assert_equal([0, 21, 2, 0, 9], getcurpos())
1018
1019  " Test for z+ with [count] greater than buffer size
1020  1
1021  norm! 1000z+
1022  call assert_equal('	100', getline('.'))
1023  call assert_equal(100, winsaveview()['topline'])
1024  call assert_equal([0, 100, 2, 0, 9], getcurpos())
1025
1026  " Test for z+ from the last buffer line
1027  norm! Gz.z+
1028  call assert_equal('	100', getline('.'))
1029  call assert_equal(100, winsaveview()['topline'])
1030  call assert_equal([0, 100, 2, 0, 9], getcurpos())
1031
1032  " Test for z^
1033  norm! 22z+0
1034  norm! z^
1035  call assert_equal('	21', getline('.'))
1036  call assert_equal(12, winsaveview()['topline'])
1037  call assert_equal([0, 21, 2, 0, 9], getcurpos())
1038
1039  " Test for z^ from first buffer line
1040  norm! ggz^
1041  call assert_equal('1', getline('.'))
1042  call assert_equal(1, winsaveview()['topline'])
1043  call assert_equal([0, 1, 1, 0, 1], getcurpos())
1044
1045  " Test for [count]z^
1046  1
1047  norm! 30z^
1048  call assert_equal('	21', getline('.'))
1049  call assert_equal(12, winsaveview()['topline'])
1050  call assert_equal([0, 21, 2, 0, 9], getcurpos())
1051
1052  " cleanup
1053  bw!
1054endfunc
1055
1056func Test_normal16_z_scroll_hor()
1057  " basic test for z commands that scroll the window
1058  10new
1059  15vsp
1060  set nowrap listchars=
1061  let lineA='abcdefghijklmnopqrstuvwxyz'
1062  let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1063  $put =lineA
1064  $put =lineB
1065  1d
1066
1067  " Test for zl and zh with a count
1068  norm! 0z10l
1069  call assert_equal([11, 1], [col('.'), wincol()])
1070  norm! z4h
1071  call assert_equal([11, 5], [col('.'), wincol()])
1072  normal! 2gg
1073
1074  " Test for zl
1075  1
1076  norm! 5zl
1077  call assert_equal(lineA, getline('.'))
1078  call assert_equal(6, col('.'))
1079  call assert_equal(5, winsaveview()['leftcol'])
1080  norm! yl
1081  call assert_equal('f', @0)
1082
1083  " Test for zh
1084  norm! 2zh
1085  call assert_equal(lineA, getline('.'))
1086  call assert_equal(6, col('.'))
1087  norm! yl
1088  call assert_equal('f', @0)
1089  call assert_equal(3, winsaveview()['leftcol'])
1090
1091  " Test for zL
1092  norm! zL
1093  call assert_equal(11, col('.'))
1094  norm! yl
1095  call assert_equal('k', @0)
1096  call assert_equal(10, winsaveview()['leftcol'])
1097  norm! 2zL
1098  call assert_equal(25, col('.'))
1099  norm! yl
1100  call assert_equal('y', @0)
1101  call assert_equal(24, winsaveview()['leftcol'])
1102
1103  " Test for zH
1104  norm! 2zH
1105  call assert_equal(25, col('.'))
1106  call assert_equal(10, winsaveview()['leftcol'])
1107  norm! yl
1108  call assert_equal('y', @0)
1109
1110  " Test for zs
1111  norm! $zs
1112  call assert_equal(26, col('.'))
1113  call assert_equal(25, winsaveview()['leftcol'])
1114  norm! yl
1115  call assert_equal('z', @0)
1116
1117  " Test for ze
1118  norm! ze
1119  call assert_equal(26, col('.'))
1120  call assert_equal(11, winsaveview()['leftcol'])
1121  norm! yl
1122  call assert_equal('z', @0)
1123
1124  " Test for zs and ze with folds
1125  %fold
1126  norm! $zs
1127  call assert_equal(26, col('.'))
1128  call assert_equal(0, winsaveview()['leftcol'])
1129  norm! yl
1130  call assert_equal('z', @0)
1131  norm! ze
1132  call assert_equal(26, col('.'))
1133  call assert_equal(0, winsaveview()['leftcol'])
1134  norm! yl
1135  call assert_equal('z', @0)
1136
1137  " cleanup
1138  set wrap listchars=eol:$
1139  bw!
1140endfunc
1141
1142func Test_normal17_z_scroll_hor2()
1143  " basic test for z commands that scroll the window
1144  " using 'sidescrolloff' setting
1145  10new
1146  20vsp
1147  set nowrap listchars= sidescrolloff=5
1148  let lineA='abcdefghijklmnopqrstuvwxyz'
1149  let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1150  $put =lineA
1151  $put =lineB
1152  1d
1153
1154  " Test for zl
1155  1
1156  norm! 5zl
1157  call assert_equal(lineA, getline('.'))
1158  call assert_equal(11, col('.'))
1159  call assert_equal(5, winsaveview()['leftcol'])
1160  norm! yl
1161  call assert_equal('k', @0)
1162
1163  " Test for zh
1164  norm! 2zh
1165  call assert_equal(lineA, getline('.'))
1166  call assert_equal(11, col('.'))
1167  norm! yl
1168  call assert_equal('k', @0)
1169  call assert_equal(3, winsaveview()['leftcol'])
1170
1171  " Test for zL
1172  norm! 0zL
1173  call assert_equal(16, col('.'))
1174  norm! yl
1175  call assert_equal('p', @0)
1176  call assert_equal(10, winsaveview()['leftcol'])
1177  norm! 2zL
1178  call assert_equal(26, col('.'))
1179  norm! yl
1180  call assert_equal('z', @0)
1181  call assert_equal(15, winsaveview()['leftcol'])
1182
1183  " Test for zH
1184  norm! 2zH
1185  call assert_equal(15, col('.'))
1186  call assert_equal(0, winsaveview()['leftcol'])
1187  norm! yl
1188  call assert_equal('o', @0)
1189
1190  " Test for zs
1191  norm! $zs
1192  call assert_equal(26, col('.'))
1193  call assert_equal(20, winsaveview()['leftcol'])
1194  norm! yl
1195  call assert_equal('z', @0)
1196
1197  " Test for ze
1198  norm! ze
1199  call assert_equal(26, col('.'))
1200  call assert_equal(11, winsaveview()['leftcol'])
1201  norm! yl
1202  call assert_equal('z', @0)
1203
1204  " cleanup
1205  set wrap listchars=eol:$ sidescrolloff=0
1206  bw!
1207endfunc
1208
1209func Test_large_sidescrolloff_no_overflow()
1210  10new
1211  20vsp
1212  setlocal nowrap sidescrolloff=2147483647
1213  call setline(1, repeat('a', 40))
1214
1215  normal! $
1216  redraw!
1217  call assert_equal(29, winsaveview().leftcol)
1218
1219  normal! zs
1220  redraw!
1221  call assert_equal(29, winsaveview().leftcol)
1222
1223  normal! ze
1224  redraw!
1225  call assert_equal(29, winsaveview().leftcol)
1226
1227  normal! 0
1228  redraw!
1229  call assert_equal(0, winsaveview().leftcol)
1230
1231  bw!
1232endfunc
1233
1234" Test for commands that scroll the window horizontally. Test with folds.
1235"   H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
1236func Test_vert_scroll_cmds()
1237  15new
1238  call setline(1, range(1, 100))
1239  exe "normal! 30ggz\<CR>"
1240  set foldenable
1241  33,36fold
1242  40,43fold
1243  46,49fold
1244  let h = winheight(0)
1245
1246  " Test for H, M and L commands
1247  " Top of the screen = 30
1248  " Folded lines = 9
1249  " Bottom of the screen = 30 + h + 9 - 1
1250  normal! 4L
1251  call assert_equal(35 + h, line('.'))
1252  normal! 4H
1253  call assert_equal(33, line('.'))
1254
1255  " Test for using a large count value
1256  %d
1257  call setline(1, range(1, 4))
1258  norm! 6H
1259  call assert_equal(4, line('.'))
1260
1261  " Test for 'M' with folded lines
1262  %d
1263  call setline(1, range(1, 20))
1264  1,5fold
1265  norm! LM
1266  call assert_equal(12, line('.'))
1267
1268  " Test for the CTRL-E and CTRL-Y commands with folds
1269  %d
1270  call setline(1, range(1, 10))
1271  3,5fold
1272  exe "normal 6G3\<C-E>"
1273  call assert_equal(6, line('w0'))
1274  exe "normal 2\<C-Y>"
1275  call assert_equal(2, line('w0'))
1276
1277  " Test for CTRL-Y on a folded line
1278  %d
1279  call setline(1, range(1, 100))
1280  exe (h + 2) .. "," .. (h + 4) .. "fold"
1281  exe h + 5
1282  normal z-
1283  exe "normal \<C-Y>\<C-Y>"
1284  call assert_equal(h + 1, line('w$'))
1285
1286  " Test for CTRL-Y from the first line and CTRL-E from the last line
1287  %d
1288  set scrolloff=2
1289  call setline(1, range(1, 4))
1290  exe "normal gg\<C-Y>"
1291  call assert_equal(1, line('w0'))
1292  call assert_equal(1, line('.'))
1293  exe "normal G4\<C-E>\<C-E>"
1294  call assert_equal(4, line('w$'))
1295  call assert_equal(4, line('.'))
1296  set scrolloff&
1297
1298  " Using <PageUp> and <PageDown> in an empty buffer should beep
1299  %d
1300  call assert_beeps('exe "normal \<PageUp>"')
1301  call assert_beeps('exe "normal \<C-B>"')
1302  call assert_beeps('exe "normal \<PageDown>"')
1303  call assert_beeps('exe "normal \<C-F>"')
1304
1305  " Test for <C-U> and <C-D> with fold
1306  %d
1307  call setline(1, range(1, 100))
1308  10,35fold
1309  set scroll=10
1310  exe "normal \<C-D>"
1311  call assert_equal(36, line('.'))
1312  exe "normal \<C-D>"
1313  call assert_equal(46, line('.'))
1314  exe "normal \<C-U>"
1315  call assert_equal(36, line('.'))
1316  exe "normal \<C-U>"
1317  call assert_equal(1, line('.'))
1318  exe "normal \<C-U>"
1319  call assert_equal(1, line('.'))
1320  set scroll&
1321
1322  " Test for scrolling to the top of the file with <C-U> and a fold
1323  10
1324  normal ztL
1325  exe "normal \<C-U>\<C-U>"
1326  call assert_equal(1, line('w0'))
1327
1328  " Test for CTRL-D on a folded line
1329  %d
1330  call setline(1, range(1, 100))
1331  50,100fold
1332  75
1333  normal z-
1334  exe "normal \<C-D>"
1335  call assert_equal(50, line('.'))
1336  call assert_equal(100, line('w$'))
1337  normal z.
1338  let lnum = winline()
1339  exe "normal \<C-D>"
1340  call assert_equal(lnum, winline())
1341  call assert_equal(50, line('.'))
1342  normal zt
1343  exe "normal \<C-D>"
1344  call assert_equal(50, line('w0'))
1345
1346  " Test for <S-CR>. Page down.
1347  %d
1348  call setline(1, range(1, 100))
1349  call feedkeys("\<S-CR>", 'xt')
1350  call assert_equal(14, line('w0'))
1351  call assert_equal(28, line('w$'))
1352
1353  " Test for <S-->. Page up.
1354  call feedkeys("\<S-->", 'xt')
1355  call assert_equal(1, line('w0'))
1356  call assert_equal(15, line('w$'))
1357
1358  set foldenable&
1359  bwipe!
1360endfunc
1361
1362func Test_scroll_in_ex_mode()
1363  " This was using invalid memory because w_botline was invalid.
1364  let lines =<< trim END
1365      diffsplit
1366      norm os00(
1367      call writefile(['done'], 'Xdone')
1368      qa!
1369  END
1370  call writefile(lines, 'Xscript', 'D')
1371  call assert_equal(1, RunVim([], [], '--clean -X -Z -e -s -S Xscript'))
1372  call assert_equal(['done'], readfile('Xdone'))
1373
1374  call delete('Xdone')
1375endfunc
1376
1377func Test_scroll_and_paste_in_ex_mode()
1378  throw 'Skipped: does not work when Nvim is run from :!'
1379  " This used to crash because of moving cursor to line 0.
1380  let lines =<< trim END
1381      v/foo/vi|YY9PYQ
1382      v/bar/vi|YY9PYQ
1383      v/bar/exe line('.') == 1 ? "vi|Y\<C-B>9PYQ" : "vi|YQ"
1384      call writefile(['done'], 'Xdone')
1385      qa!
1386  END
1387  call writefile(lines, 'Xscript', 'D')
1388  call assert_equal(1, RunVim([], [], '-u NONE -i NONE -n -X -Z -e -s -S Xscript'))
1389  call assert_equal(['done'], readfile('Xdone'))
1390
1391  call delete('Xdone')
1392endfunc
1393
1394" Test for the 'sidescroll' option
1395func Test_sidescroll_opt()
1396  new
1397  20vnew
1398
1399  " scroll by 2 characters horizontally
1400  set sidescroll=2 nowrap
1401  call setline(1, repeat('a', 40))
1402  normal g$l
1403  call assert_equal(19, screenpos(0, 1, 21).col)
1404  normal l
1405  call assert_equal(20, screenpos(0, 1, 22).col)
1406  normal g0h
1407  call assert_equal(2, screenpos(0, 1, 2).col)
1408  call assert_equal(20, screenpos(0, 1, 20).col)
1409
1410  " when 'sidescroll' is 0, cursor positioned at the center
1411  set sidescroll=0
1412  normal g$l
1413  call assert_equal(11, screenpos(0, 1, 21).col)
1414  normal g0h
1415  call assert_equal(10, screenpos(0, 1, 10).col)
1416
1417  %bw!
1418  set wrap& sidescroll&
1419endfunc
1420
1421" basic tests for foldopen/folddelete
1422func Test_normal18_z_fold()
1423  CheckFeature folding
1424  call Setup_NewWindow()
1425  50
1426  setl foldenable fdm=marker foldlevel=5
1427
1428  call assert_beeps('normal! zj')
1429  call assert_beeps('normal! zk')
1430
1431  " Test for zF
1432  " First fold
1433  norm! 4zF
1434  " check that folds have been created
1435  call assert_equal(['50/* {{{ */', '51', '52', '53/* }}} */'], getline(50,53))
1436
1437  " Test for zd
1438  51
1439  norm! 2zF
1440  call assert_equal(2, foldlevel('.'))
1441  norm! kzd
1442  call assert_equal(['50', '51/* {{{ */', '52/* }}} */', '53'], getline(50,53))
1443  norm! j
1444  call assert_equal(1, foldlevel('.'))
1445
1446  " Test for zD
1447  " also deletes partially selected folds recursively
1448  51
1449  norm! zF
1450  call assert_equal(2, foldlevel('.'))
1451  norm! kV2jzD
1452  call assert_equal(['50', '51', '52', '53'], getline(50,53))
1453
1454  " Test for zE
1455  85
1456  norm! 4zF
1457  86
1458  norm! 2zF
1459  90
1460  norm! 4zF
1461  call assert_equal(['85/* {{{ */', '86/* {{{ */', '87/* }}} */', '88/* }}} */', '89', '90/* {{{ */', '91', '92', '93/* }}} */'], getline(85,93))
1462  norm! zE
1463  call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
1464
1465  " Test for zn
1466  50
1467  set foldlevel=0
1468  norm! 2zF
1469  norm! zn
1470  norm! k
1471  call assert_equal('49', getline('.'))
1472  norm! j
1473  call assert_equal('50/* {{{ */', getline('.'))
1474  norm! j
1475  call assert_equal('51/* }}} */', getline('.'))
1476  norm! j
1477  call assert_equal('52', getline('.'))
1478  call assert_equal(0, &foldenable)
1479
1480  " Test for zN
1481  49
1482  norm! zN
1483  call assert_equal('49', getline('.'))
1484  norm! j
1485  call assert_equal('50/* {{{ */', getline('.'))
1486  norm! j
1487  call assert_equal('52', getline('.'))
1488  call assert_equal(1, &foldenable)
1489
1490  " Test for zi
1491  norm! zi
1492  call assert_equal(0, &foldenable)
1493  norm! zi
1494  call assert_equal(1, &foldenable)
1495  norm! zi
1496  call assert_equal(0, &foldenable)
1497  norm! zi
1498  call assert_equal(1, &foldenable)
1499
1500  " Test for za
1501  50
1502  norm! za
1503  norm! k
1504  call assert_equal('49', getline('.'))
1505  norm! j
1506  call assert_equal('50/* {{{ */', getline('.'))
1507  norm! j
1508  call assert_equal('51/* }}} */', getline('.'))
1509  norm! j
1510  call assert_equal('52', getline('.'))
1511  50
1512  norm! za
1513  norm! k
1514  call assert_equal('49', getline('.'))
1515  norm! j
1516  call assert_equal('50/* {{{ */', getline('.'))
1517  norm! j
1518  call assert_equal('52', getline('.'))
1519
1520  49
1521  norm! 5zF
1522  norm! k
1523  call assert_equal('48', getline('.'))
1524  norm! j
1525  call assert_equal('49/* {{{ */', getline('.'))
1526  norm! j
1527  call assert_equal('55', getline('.'))
1528  49
1529  norm! za
1530  call assert_equal('49/* {{{ */', getline('.'))
1531  norm! j
1532  call assert_equal('50/* {{{ */', getline('.'))
1533  norm! j
1534  call assert_equal('52', getline('.'))
1535  set nofoldenable
1536  " close fold and set foldenable
1537  norm! za
1538  call assert_equal(1, &foldenable)
1539
1540  50
1541  " have to use {count}za to open all folds and make the cursor visible
1542  norm! 2za
1543  norm! 2k
1544  call assert_equal('48', getline('.'))
1545  norm! j
1546  call assert_equal('49/* {{{ */', getline('.'))
1547  norm! j
1548  call assert_equal('50/* {{{ */', getline('.'))
1549  norm! j
1550  call assert_equal('51/* }}} */', getline('.'))
1551  norm! j
1552  call assert_equal('52', getline('.'))
1553
1554  " Test for zA
1555  49
1556  set foldlevel=0
1557  50
1558  norm! zA
1559  norm! 2k
1560  call assert_equal('48', getline('.'))
1561  norm! j
1562  call assert_equal('49/* {{{ */', getline('.'))
1563  norm! j
1564  call assert_equal('50/* {{{ */', getline('.'))
1565  norm! j
1566  call assert_equal('51/* }}} */', getline('.'))
1567  norm! j
1568  call assert_equal('52', getline('.'))
1569
1570  " zA on an opened fold when foldenable is not set
1571  50
1572  set nofoldenable
1573  norm! zA
1574  call assert_equal(1, &foldenable)
1575  norm! k
1576  call assert_equal('48', getline('.'))
1577  norm! j
1578  call assert_equal('49/* {{{ */', getline('.'))
1579  norm! j
1580  call assert_equal('55', getline('.'))
1581
1582  " Test for zc
1583  norm! zE
1584  50
1585  norm! 2zF
1586  49
1587  norm! 5zF
1588  set nofoldenable
1589  50
1590  " There most likely is a bug somewhere:
1591  " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
1592  " TODO: Should this only close the inner most fold or both folds?
1593  norm! zc
1594  call assert_equal(1, &foldenable)
1595  norm! k
1596  call assert_equal('48', getline('.'))
1597  norm! j
1598  call assert_equal('49/* {{{ */', getline('.'))
1599  norm! j
1600  call assert_equal('55', getline('.'))
1601  set nofoldenable
1602  50
1603  norm! Vjzc
1604  norm! k
1605  call assert_equal('48', getline('.'))
1606  norm! j
1607  call assert_equal('49/* {{{ */', getline('.'))
1608  norm! j
1609  call assert_equal('55', getline('.'))
1610
1611  " Test for zC
1612  set nofoldenable
1613  50
1614  norm! zCk
1615  call assert_equal('48', getline('.'))
1616  norm! j
1617  call assert_equal('49/* {{{ */', getline('.'))
1618  norm! j
1619  call assert_equal('55', getline('.'))
1620
1621  " Test for zx
1622  " 1) close folds at line 49-54
1623  set nofoldenable
1624  48
1625  norm! zx
1626  call assert_equal(1, &foldenable)
1627  norm! j
1628  call assert_equal('49/* {{{ */', getline('.'))
1629  norm! j
1630  call assert_equal('55', getline('.'))
1631
1632  " 2) do not close fold under cursor
1633  51
1634  set nofoldenable
1635  norm! zx
1636  call assert_equal(1, &foldenable)
1637  norm! 3k
1638  call assert_equal('48', getline('.'))
1639  norm! j
1640  call assert_equal('49/* {{{ */', getline('.'))
1641  norm! j
1642  call assert_equal('50/* {{{ */', getline('.'))
1643  norm! j
1644  call assert_equal('51/* }}} */', getline('.'))
1645  norm! j
1646  call assert_equal('52', getline('.'))
1647  norm! j
1648  call assert_equal('53', getline('.'))
1649  norm! j
1650  call assert_equal('54/* }}} */', getline('.'))
1651  norm! j
1652  call assert_equal('55', getline('.'))
1653
1654  " 3) close one level of folds
1655  48
1656  set nofoldenable
1657  set foldlevel=1
1658  norm! zx
1659  call assert_equal(1, &foldenable)
1660  call assert_equal('48', getline('.'))
1661  norm! j
1662  call assert_equal('49/* {{{ */', getline('.'))
1663  norm! j
1664  call assert_equal('50/* {{{ */', getline('.'))
1665  norm! j
1666  call assert_equal('52', getline('.'))
1667  norm! j
1668  call assert_equal('53', getline('.'))
1669  norm! j
1670  call assert_equal('54/* }}} */', getline('.'))
1671  norm! j
1672  call assert_equal('55', getline('.'))
1673
1674  " Test for zX
1675  " Close all folds
1676  set foldlevel=0 nofoldenable
1677  50
1678  norm! zX
1679  call assert_equal(1, &foldenable)
1680  norm! k
1681  call assert_equal('48', getline('.'))
1682  norm! j
1683  call assert_equal('49/* {{{ */', getline('.'))
1684  norm! j
1685  call assert_equal('55', getline('.'))
1686
1687  " Test for zm
1688  50
1689  set nofoldenable foldlevel=2
1690  norm! zm
1691  call assert_equal(1, &foldenable)
1692  call assert_equal(1, &foldlevel)
1693  norm! zm
1694  call assert_equal(0, &foldlevel)
1695  norm! zm
1696  call assert_equal(0, &foldlevel)
1697  norm! k
1698  call assert_equal('48', getline('.'))
1699  norm! j
1700  call assert_equal('49/* {{{ */', getline('.'))
1701  norm! j
1702  call assert_equal('55', getline('.'))
1703
1704  " Test for zm with a count
1705  50
1706  set foldlevel=2
1707  norm! 3zm
1708  call assert_equal(0, &foldlevel)
1709  call assert_equal(49, foldclosed(line('.')))
1710
1711  " Test for zM
1712  48
1713  set nofoldenable foldlevel=99
1714  norm! zM
1715  call assert_equal(1, &foldenable)
1716  call assert_equal(0, &foldlevel)
1717  call assert_equal('48', getline('.'))
1718  norm! j
1719  call assert_equal('49/* {{{ */', getline('.'))
1720  norm! j
1721  call assert_equal('55', getline('.'))
1722
1723  " Test for zr
1724  48
1725  set nofoldenable foldlevel=0
1726  norm! zr
1727  call assert_equal(0, &foldenable)
1728  call assert_equal(1, &foldlevel)
1729  set foldlevel=0 foldenable
1730  norm! zr
1731  call assert_equal(1, &foldenable)
1732  call assert_equal(1, &foldlevel)
1733  norm! zr
1734  call assert_equal(2, &foldlevel)
1735  call assert_equal('48', getline('.'))
1736  norm! j
1737  call assert_equal('49/* {{{ */', getline('.'))
1738  norm! j
1739  call assert_equal('50/* {{{ */', getline('.'))
1740  norm! j
1741  call assert_equal('51/* }}} */', getline('.'))
1742  norm! j
1743  call assert_equal('52', getline('.'))
1744
1745  " Test for zR
1746  48
1747  set nofoldenable foldlevel=0
1748  norm! zR
1749  call assert_equal(0, &foldenable)
1750  call assert_equal(2, &foldlevel)
1751  set foldenable foldlevel=0
1752  norm! zR
1753  call assert_equal(1, &foldenable)
1754  call assert_equal(2, &foldlevel)
1755  call assert_equal('48', getline('.'))
1756  norm! j
1757  call assert_equal('49/* {{{ */', getline('.'))
1758  norm! j
1759  call assert_equal('50/* {{{ */', getline('.'))
1760  norm! j
1761  call assert_equal('51/* }}} */', getline('.'))
1762  norm! j
1763  call assert_equal('52', getline('.'))
1764  call append(50, ['a /* {{{ */', 'b /* }}} */'])
1765  48
1766  call assert_equal('48', getline('.'))
1767  norm! j
1768  call assert_equal('49/* {{{ */', getline('.'))
1769  norm! j
1770  call assert_equal('50/* {{{ */', getline('.'))
1771  norm! j
1772  call assert_equal('a /* {{{ */', getline('.'))
1773  norm! j
1774  call assert_equal('51/* }}} */', getline('.'))
1775  norm! j
1776  call assert_equal('52', getline('.'))
1777  48
1778  norm! zR
1779  call assert_equal(1, &foldenable)
1780  call assert_equal(3, &foldlevel)
1781  call assert_equal('48', getline('.'))
1782  norm! j
1783  call assert_equal('49/* {{{ */', getline('.'))
1784  norm! j
1785  call assert_equal('50/* {{{ */', getline('.'))
1786  norm! j
1787  call assert_equal('a /* {{{ */', getline('.'))
1788  norm! j
1789  call assert_equal('b /* }}} */', getline('.'))
1790  norm! j
1791  call assert_equal('51/* }}} */', getline('.'))
1792  norm! j
1793  call assert_equal('52', getline('.'))
1794
1795  " clean up
1796  setl nofoldenable fdm=marker foldlevel=0
1797  bw!
1798endfunc
1799
1800func Test_normal20_exmode()
1801  " Reading from redirected file doesn't work on MS-Windows
1802  CheckNotMSWindows
1803  call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1804  call writefile(['1', '2'], 'Xfile')
1805  call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
1806  let a=readfile('Xfile2')
1807  call assert_equal(['1', 'foo', 'bar', '2'], a)
1808
1809  " clean up
1810  for file in ['Xfile', 'Xfile2', 'Xscript']
1811    call delete(file)
1812  endfor
1813  bw!
1814endfunc
1815
1816func Test_normal21_nv_hat()
1817
1818  " Edit a fresh file and wipe the buffer list so that there is no alternate
1819  " file present.  Next, check for the expected command failures.
1820  edit Xfoo | %bw
1821  call assert_fails(':buffer #', 'E86')
1822  call assert_fails(':execute "normal! \<C-^>"', 'E23')
1823  call assert_fails("normal i\<C-R>#", 'E23:')
1824
1825  " Test for the expected behavior when switching between two named buffers.
1826  edit Xfoo | edit Xbar
1827  call feedkeys("\<C-^>", 'tx')
1828  call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1829  call feedkeys("\<C-^>", 'tx')
1830  call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1831
1832  " Test for the expected behavior when only one buffer is named.
1833  enew | let l:nr = bufnr('%')
1834  call feedkeys("\<C-^>", 'tx')
1835  call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1836  call feedkeys("\<C-^>", 'tx')
1837  call assert_equal('', bufname('%'))
1838  call assert_equal(l:nr, bufnr('%'))
1839
1840  " Test that no action is taken by "<C-^>" when an operator is pending.
1841  edit Xfoo
1842  call feedkeys("ci\<C-^>", 'tx')
1843  call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1844
1845  %bw!
1846endfunc
1847
1848func Test_normal22_zet()
1849  " Test for ZZ
1850  " let shell = &shell
1851  " let &shell = 'sh'
1852  call writefile(['1', '2'], 'Xn22file', 'D')
1853  let args = ' -N -i NONE --noplugins -X --headless'
1854  call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xn22file')
1855  let a = readfile('Xn22file')
1856  call assert_equal([], a)
1857  " Test for ZQ
1858  call writefile(['1', '2'], 'Xn22file')
1859  call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xn22file')
1860  let a = readfile('Xn22file')
1861  call assert_equal(['1', '2'], a)
1862
1863  " Unsupported Z command
1864  call assert_beeps('normal! ZW')
1865
1866  " clean up
1867  " let &shell = shell
1868endfunc
1869
1870func Test_normal23_K()
1871  " Test for K command
1872  new
1873  call append(0, ['helphelp.txt', 'man', 'aa%bb', 'cc|dd'])
1874  let k = &keywordprg
1875  set keywordprg=:help
1876  1
1877  norm! VK
1878  call assert_equal('helphelp.txt', fnamemodify(bufname('%'), ':t'))
1879  call assert_equal('help', &ft)
1880  call assert_match('\*helphelp.txt\*', getline('.'))
1881  helpclose
1882  norm! 0K
1883  call assert_equal('helphelp.txt', fnamemodify(bufname('%'), ':t'))
1884  call assert_equal('help', &ft)
1885  call assert_match('Help on help files', getline('.'))
1886  helpclose
1887
1888  set keywordprg=:new
1889  set iskeyword+=%
1890  set iskeyword+=\|
1891  2
1892  norm! K
1893  call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1894  bwipe!
1895  3
1896  norm! K
1897  call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1898  bwipe!
1899  if !has('win32')
1900    4
1901    norm! K
1902    call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1903    bwipe!
1904  endif
1905  set iskeyword-=%
1906  set iskeyword-=\|
1907
1908  " Test for specifying a count to K
1909  1
1910  com! -nargs=* Kprog let g:Kprog_Args = <q-args>
1911  set keywordprg=:Kprog
1912  norm! 3K
1913  call assert_equal('3 helphelp', g:Kprog_Args)
1914  delcom Kprog
1915
1916  " Only expect "man" to work on Unix
1917  if !has("unix") || has('nvim')  " Nvim K uses :terminal. #15398
1918    let &keywordprg = k
1919    bw!
1920    return
1921  endif
1922
1923  let not_gnu_man = has('mac') || has('bsd')
1924  if not_gnu_man
1925    " In macOS and BSD, the option for specifying a pager is different
1926    set keywordprg=man\ -P\ cat
1927  else
1928    set keywordprg=man\ --pager=cat
1929  endif
1930  " Test for using man
1931  2
1932  let a = execute('unsilent norm! K')
1933  if not_gnu_man
1934    call assert_match("man -P cat 'man'", a)
1935  else
1936    call assert_match("man --pager=cat 'man'", a)
1937  endif
1938
1939  " Error cases
1940  call setline(1, '#$#')
1941  call assert_fails('normal! ggK', 'E349:')
1942  call setline(1, '---')
1943  call assert_fails('normal! ggv2lK', 'E349:')
1944  call setline(1, ['abc', 'xyz'])
1945  call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
1946  call assert_beeps("normal! ggVjK")
1947
1948  " clean up
1949  let &keywordprg = k
1950  bw!
1951endfunc
1952
1953func Test_normal24_rot13()
1954  " Testing for g?? g?g?
1955  new
1956  call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1957  1
1958  norm! g??
1959  call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1960  norm! g?g?
1961  call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1962
1963  " clean up
1964  bw!
1965endfunc
1966
1967func Test_normal25_tag()
1968  CheckFeature quickfix
1969
1970  " Testing for CTRL-] g CTRL-] g]
1971  " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1972  help helphelp
1973  " Test for CTRL-]
1974  call search('\<x\>$')
1975  exe "norm! \<c-]>"
1976  call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1977  norm! yiW
1978  call assert_equal("*x*", @0)
1979  exe ":norm \<c-o>"
1980
1981  " Test for g_CTRL-]
1982  call search('\<v_u\>$')
1983  exe "norm! g\<c-]>"
1984  call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1985  norm! yiW
1986  call assert_equal("*v_u*", @0)
1987  exe ":norm \<c-o>"
1988
1989  " Test for g]
1990  call search('\<i_<Esc>$')
1991  let a = execute(":norm! g]")
1992  call assert_match('i_<Esc>.*insert.txt', a)
1993
1994  if !empty(exepath('cscope')) && has('cscope')
1995    " setting cscopetag changes how g] works
1996    set cst
1997    exe "norm! g]"
1998    call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1999    norm! yiW
2000    call assert_equal("*i_<Esc>*", @0)
2001    exe ":norm \<c-o>"
2002    " Test for CTRL-W g]
2003    exe "norm! \<C-W>g]"
2004    call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
2005    norm! yiW
2006    call assert_equal("*i_<Esc>*", @0)
2007    call assert_equal(3, winnr('$'))
2008    helpclose
2009    set nocst
2010  endif
2011
2012  " Test for CTRL-W g]
2013  let a = execute("norm! \<C-W>g]")
2014  call assert_match('i_<Esc>.*insert.txt', a)
2015
2016  " Test for CTRL-W CTRL-]
2017  exe "norm! \<C-W>\<C-]>"
2018  call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
2019  norm! yiW
2020  call assert_equal("*i_<Esc>*", @0)
2021  call assert_equal(3, winnr('$'))
2022  helpclose
2023
2024  " Test for CTRL-W g CTRL-]
2025  exe "norm! \<C-W>g\<C-]>"
2026  call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
2027  norm! yiW
2028  call assert_equal("*i_<Esc>*", @0)
2029  call assert_equal(3, winnr('$'))
2030  helpclose
2031
2032  " clean up
2033  helpclose
2034endfunc
2035
2036func Test_normal26_put()
2037  " Test for ]p ]P [p and [P
2038  new
2039  call append(0, ['while read LINE', 'do', '  ((count++))', '  if [ $? -ne 0 ]; then', "    echo 'Error writing file'", '  fi', 'done'])
2040  1
2041  /Error/y a
2042  2
2043  norm! "a]pj"a[p
2044  call assert_equal(['do', "echo 'Error writing file'", "  echo 'Error writing file'", '  ((count++))'], getline(2,5))
2045  1
2046  /^\s\{4}/
2047  exe "norm!  \"a]P3Eldt'"
2048  exe "norm! j\"a[P2Eldt'"
2049  call assert_equal(['  if [ $? -ne 0 ]; then', "    echo 'Error writing'", "    echo 'Error'", "    echo 'Error writing file'", '  fi'], getline(6,10))
2050
2051  " clean up
2052  bw!
2053endfunc
2054
2055func Test_normal27_bracket()
2056  " Test for [' [` ]' ]`
2057  call Setup_NewWindow()
2058  1,21s/.\+/  &   b/
2059  1
2060  norm! $ma
2061  5
2062  norm! $mb
2063  10
2064  norm! $mc
2065  15
2066  norm! $md
2067  20
2068  norm! $me
2069
2070  " Test for ['
2071  9
2072  norm! 2['
2073  call assert_equal('  1   b', getline('.'))
2074  call assert_equal(1, line('.'))
2075  call assert_equal(3, col('.'))
2076
2077  " Test for ]'
2078  norm! ]'
2079  call assert_equal('  5   b', getline('.'))
2080  call assert_equal(5, line('.'))
2081  call assert_equal(3, col('.'))
2082
2083  " No mark before line 1, cursor moves to first non-blank on current line
2084  1
2085  norm! 5|['
2086  call assert_equal('  1   b', getline('.'))
2087  call assert_equal(1, line('.'))
2088  call assert_equal(3, col('.'))
2089
2090  " No mark after line 21, cursor moves to first non-blank on current line
2091  21
2092  norm! 5|]'
2093  call assert_equal('  21   b', getline('.'))
2094  call assert_equal(21, line('.'))
2095  call assert_equal(3, col('.'))
2096
2097  " Test for [`
2098  norm! 2[`
2099  call assert_equal('  15   b', getline('.'))
2100  call assert_equal(15, line('.'))
2101  call assert_equal(8, col('.'))
2102
2103  " Test for ]`
2104  norm! ]`
2105  call assert_equal('  20   b', getline('.'))
2106  call assert_equal(20, line('.'))
2107  call assert_equal(8, col('.'))
2108
2109  " No mark before line 1, cursor does not move
2110  1
2111  norm! 5|[`
2112  call assert_equal('  1   b', getline('.'))
2113  call assert_equal(1, line('.'))
2114  call assert_equal(5, col('.'))
2115
2116  " No mark after line 21, cursor does not move
2117  21
2118  norm! 5|]`
2119  call assert_equal('  21   b', getline('.'))
2120  call assert_equal(21, line('.'))
2121  call assert_equal(5, col('.'))
2122
2123  " Count too large for [`
2124  " cursor moves to first lowercase mark
2125  norm! 99[`
2126  call assert_equal('  1   b', getline('.'))
2127  call assert_equal(1, line('.'))
2128  call assert_equal(7, col('.'))
2129
2130  " Count too large for ]`
2131  " cursor moves to last lowercase mark
2132  norm! 99]`
2133  call assert_equal('  20   b', getline('.'))
2134  call assert_equal(20, line('.'))
2135  call assert_equal(8, col('.'))
2136
2137  " clean up
2138  bw!
2139endfunc
2140
2141" Test for ( and ) sentence movements
2142func Test_normal28_parenthesis()
2143  new
2144  call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2145
2146  $
2147  norm! d(
2148  call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
2149  norm! 2d(
2150  call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
2151  1
2152  norm! 0d)
2153  call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
2154
2155  call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
2156  $
2157  norm! $d(
2158  call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
2159
2160  " Move to the next sentence from a paragraph macro
2161  %d
2162  call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
2163  call cursor(1, 1)
2164  normal )
2165  call assert_equal([2, 1], [line('.'), col('.')])
2166  normal )
2167  call assert_equal([2, 12], [line('.'), col('.')])
2168  normal ((
2169  call assert_equal([1, 1], [line('.'), col('.')])
2170
2171  " It is an error if a next sentence is not found
2172  %d
2173  call setline(1, '.SH')
2174  call assert_beeps('normal )')
2175
2176  " If only dot is present, don't treat that as a sentence
2177  call setline(1, '. This is a sentence.')
2178  normal $((
2179  call assert_equal(3, col('.'))
2180
2181  " Jumping to a fold should open the fold
2182  call setline(1, ['', '', 'one', 'two', 'three'])
2183  set foldenable
2184  2,$fold
2185  call feedkeys(')', 'xt')
2186  call assert_equal(3, line('.'))
2187  call assert_equal(1, foldlevel('.'))
2188  call assert_equal(-1, foldclosed('.'))
2189  set foldenable&
2190
2191  " clean up
2192  bw!
2193endfunc
2194
2195" Test for { and } paragraph movements
2196func Test_normal29_brace()
2197  let text =<< trim [DATA]
2198    A paragraph begins after each empty line, and also at each of a set of
2199    paragraph macros, specified by the pairs of characters in the 'paragraphs'
2200    option.  The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
2201    the macros ".IP", ".LP", etc.  (These are nroff macros, so the dot must be in
2202    the first column).  A section boundary is also a paragraph boundary.
2203    Note that a blank line (only containing white space) is NOT a paragraph
2204    boundary.
2205
2206
2207    Also note that this does not include a '{' or '}' in the first column.  When
2208    the '{' flag is in 'cpoptions' then '{' in the first column is used as a
2209    paragraph boundary |posix|.
2210    {
2211    This is no paragraph
2212    unless the '{' is set
2213    in 'cpoptions'
2214    }
2215    .IP
2216    The nroff macros IP separates a paragraph
2217    That means, it must be a '.'
2218    followed by IP
2219    .LPIt does not matter, if afterwards some
2220    more characters follow.
2221    .SHAlso section boundaries from the nroff
2222    macros terminate a paragraph. That means
2223    a character like this:
2224    .NH
2225    End of text here
2226  [DATA]
2227
2228  new
2229  call append(0, text)
2230  1
2231  norm! 0d2}
2232
2233  let expected =<< trim [DATA]
2234    .IP
2235    The nroff macros IP separates a paragraph
2236    That means, it must be a '.'
2237    followed by IP
2238    .LPIt does not matter, if afterwards some
2239    more characters follow.
2240    .SHAlso section boundaries from the nroff
2241    macros terminate a paragraph. That means
2242    a character like this:
2243    .NH
2244    End of text here
2245
2246  [DATA]
2247  call assert_equal(expected, getline(1, '$'))
2248
2249  norm! 0d}
2250
2251  let expected =<< trim [DATA]
2252    .LPIt does not matter, if afterwards some
2253    more characters follow.
2254    .SHAlso section boundaries from the nroff
2255    macros terminate a paragraph. That means
2256    a character like this:
2257    .NH
2258    End of text here
2259
2260  [DATA]
2261  call assert_equal(expected, getline(1, '$'))
2262
2263  $
2264  norm! d{
2265
2266  let expected =<< trim [DATA]
2267    .LPIt does not matter, if afterwards some
2268    more characters follow.
2269    .SHAlso section boundaries from the nroff
2270    macros terminate a paragraph. That means
2271    a character like this:
2272
2273  [DATA]
2274  call assert_equal(expected, getline(1, '$'))
2275
2276  norm! d{
2277
2278  let expected =<< trim [DATA]
2279    .LPIt does not matter, if afterwards some
2280    more characters follow.
2281
2282  [DATA]
2283  call assert_equal(expected, getline(1, '$'))
2284
2285  " Test with { in cpoptions
2286  %d
2287  call append(0, text)
2288  " Nvim: no "{" flag in 'cpoptions'.
2289  " set cpo+={
2290  " 1
2291  " norm! 0d2}
2292
2293  let expected =<< trim [DATA]
2294    {
2295    This is no paragraph
2296    unless the '{' is set
2297    in 'cpoptions'
2298    }
2299    .IP
2300    The nroff macros IP separates a paragraph
2301    That means, it must be a '.'
2302    followed by IP
2303    .LPIt does not matter, if afterwards some
2304    more characters follow.
2305    .SHAlso section boundaries from the nroff
2306    macros terminate a paragraph. That means
2307    a character like this:
2308    .NH
2309    End of text here
2310
2311  [DATA]
2312  " call assert_equal(expected, getline(1, '$'))
2313
2314  " $
2315  " norm! d}
2316
2317  let expected =<< trim [DATA]
2318    {
2319    This is no paragraph
2320    unless the '{' is set
2321    in 'cpoptions'
2322    }
2323    .IP
2324    The nroff macros IP separates a paragraph
2325    That means, it must be a '.'
2326    followed by IP
2327    .LPIt does not matter, if afterwards some
2328    more characters follow.
2329    .SHAlso section boundaries from the nroff
2330    macros terminate a paragraph. That means
2331    a character like this:
2332    .NH
2333    End of text here
2334
2335  [DATA]
2336  " call assert_equal(expected, getline(1, '$'))
2337
2338  " norm! gg}
2339  " norm! d5}
2340
2341  let expected =<< trim [DATA]
2342    {
2343    This is no paragraph
2344    unless the '{' is set
2345    in 'cpoptions'
2346    }
2347
2348  [DATA]
2349  " call assert_equal(expected, getline(1, '$'))
2350
2351  " Jumping to a fold should open the fold
2352  " %d
2353  " call setline(1, ['', 'one', 'two', ''])
2354  " set foldenable
2355  " 2,$fold
2356  " call feedkeys('}', 'xt')
2357  " call assert_equal(4, line('.'))
2358  " call assert_equal(1, foldlevel('.'))
2359  " call assert_equal(-1, foldclosed('.'))
2360  " set foldenable&
2361
2362  " clean up
2363  set cpo-={
2364  bw!
2365endfunc
2366
2367" Test for section movements
2368func Test_normal_section()
2369  new
2370  let lines =<< trim [END]
2371    int foo()
2372    {
2373      if (1)
2374      {
2375        a = 1;
2376      }
2377    }
2378  [END]
2379  call setline(1, lines)
2380
2381  " jumping to a folded line using [[ should open the fold
2382  2,3fold
2383  call cursor(5, 1)
2384  call feedkeys("[[", 'xt')
2385  call assert_equal(2, line('.'))
2386  call assert_equal(-1, foldclosedend(line('.')))
2387
2388  bwipe!
2389endfunc
2390
2391" Test for changing case using u, U, gu, gU and ~ (tilde) commands
2392func Test_normal30_changecase()
2393  new
2394  call append(0, 'This is a simple test: äüöß')
2395  norm! 1ggVu
2396  call assert_equal('this is a simple test: äüöß', getline('.'))
2397  norm! VU
2398  call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
2399  norm! guu
2400  call assert_equal('this is a simple test: äüöß', getline('.'))
2401  norm! gUgU
2402  call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
2403  norm! gugu
2404  call assert_equal('this is a simple test: äüöß', getline('.'))
2405  norm! gUU
2406  call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
2407  norm! 010~
2408  call assert_equal('this is a SIMPLE TEST: ÄÜÖẞ', getline('.'))
2409  norm! V~
2410  call assert_equal('THIS IS A simple test: äüöß', getline('.'))
2411  call assert_beeps('norm! c~')
2412  %d
2413  call assert_beeps('norm! ~')
2414
2415  " Test with multiple lines
2416  call setline(1, ['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'])
2417  norm! ggguG
2418  call assert_equal(['aa', 'bbbb', 'cccccc', 'dddddddd'], getline(1, '$'))
2419  norm! GgUgg
2420  call assert_equal(['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'], getline(1, '$'))
2421  %d
2422
2423  " Test for changing case across lines using 'whichwrap'
2424  call setline(1, ['aaaaaa', 'aaaaaa'])
2425  normal! gg10~
2426  call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
2427  set whichwrap+=~
2428  normal! gg10~
2429  call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
2430  set whichwrap&
2431
2432  " try changing the case with a double byte encoding (DBCS)
2433  %bw!
2434  let enc = &enc
2435  " set encoding=cp932
2436  call setline(1, "\u8470")
2437  normal ~
2438  normal gU$gu$gUgUg~g~gugu
2439  call assert_equal("\u8470", getline(1))
2440  let &encoding = enc
2441
2442  " clean up
2443  bw!
2444endfunc
2445
2446" Turkish ASCII turns to multi-byte.  On some systems Turkish locale
2447" is available but toupper()/tolower() don't do the right thing.
2448func Test_normal_changecase_turkish()
2449  new
2450  try
2451    lang tr_TR.UTF-8
2452    set casemap=
2453    let iupper = toupper('i')
2454    if iupper == "\u0130"
2455      call setline(1, 'iI')
2456      1normal gUU
2457      call assert_equal("\u0130I", getline(1))
2458      call assert_equal("\u0130I", toupper("iI"))
2459
2460      call setline(1, 'iI')
2461      1normal guu
2462      call assert_equal("i\u0131", getline(1))
2463      call assert_equal("i\u0131", tolower("iI"))
2464    elseif iupper == "I"
2465      call setline(1, 'iI')
2466      1normal gUU
2467      call assert_equal("II", getline(1))
2468      call assert_equal("II", toupper("iI"))
2469
2470      call setline(1, 'iI')
2471      1normal guu
2472      call assert_equal("ii", getline(1))
2473      call assert_equal("ii", tolower("iI"))
2474    else
2475      call assert_true(false, "expected toupper('i') to be either 'I' or '\u0131'")
2476    endif
2477    set casemap&
2478    call setline(1, 'iI')
2479    1normal gUU
2480    call assert_equal("II", getline(1))
2481    call assert_equal("II", toupper("iI"))
2482
2483    call setline(1, 'iI')
2484    1normal guu
2485    call assert_equal("ii", getline(1))
2486    call assert_equal("ii", tolower("iI"))
2487
2488    lang en_US.UTF-8
2489  catch /E197:/
2490    " can't use Turkish locale
2491    throw 'Skipped: Turkish locale not available'
2492  endtry
2493
2494  bwipe!
2495endfunc
2496
2497" Test for r (replace) command
2498func Test_normal31_r_cmd()
2499  new
2500  call append(0, 'This is a simple test: abcd')
2501  exe "norm! 1gg$r\<cr>"
2502  call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
2503  exe "norm! 1gg2wlr\<cr>"
2504  call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
2505  exe "norm! 2gg0W5r\<cr>"
2506  call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
2507  set autoindent
2508  call setline(2, ['simple test: abc', ''])
2509  exe "norm! 2gg0W5r\<cr>"
2510  call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
2511  exe "norm! 1ggVr\<cr>"
2512  call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
2513  call setline(1, 'This is a')
2514  exe "norm! 1gg05rf"
2515  call assert_equal('fffffis a', getline(1))
2516
2517  " When replacing characters, copy characters from above and below lines
2518  " using CTRL-Y and CTRL-E.
2519  " Different code paths are used for utf-8 and latin1 encodings
2520  set showmatch
2521  " for enc in ['latin1', 'utf-8']
2522  for enc in ['utf-8']
2523    enew!
2524    let &encoding = enc
2525    call setline(1, [' {a}', 'xxxxxxxxxx', '      [b]'])
2526    exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
2527    call assert_equal(' {a}x [b]x', getline(2))
2528  endfor
2529  set showmatch&
2530
2531  " r command should fail in operator pending mode
2532  call assert_beeps('normal! cr')
2533
2534  " replace a tab character in visual mode
2535  %d
2536  call setline(1, ["a\tb", "c\td", "e\tf"])
2537  normal gglvjjrx
2538  call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
2539
2540  " replace with a multibyte character (with multiple composing characters)
2541  %d
2542  new
2543  call setline(1, 'aaa')
2544  exe "normal $ra\u0328\u0301"
2545  call assert_equal("aaa\u0328\u0301", getline(1))
2546
2547  " clean up
2548  set noautoindent
2549  bw!
2550endfunc
2551
2552" Test for g*, g#
2553func Test_normal32_g_cmd1()
2554  new
2555  call append(0, ['abc.x_foo', 'x_foobar.abc'])
2556  1
2557  norm! $g*
2558  call assert_equal('x_foo', @/)
2559  call assert_equal('x_foobar.abc', getline('.'))
2560  norm! $g#
2561  call assert_equal('abc', @/)
2562  call assert_equal('abc.x_foo', getline('.'))
2563
2564  " clean up
2565  bw!
2566endfunc
2567
2568" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
2569" gi and gI commands
2570func Test_normal33_g_cmd2()
2571  call Setup_NewWindow()
2572  " Test for g`
2573  clearjumps
2574  norm! ma10j
2575  let a=execute(':jumps')
2576  " empty jumplist
2577  call assert_equal('>', a[-1:])
2578  norm! g`a
2579  call assert_equal('>', a[-1:])
2580  call assert_equal(1, line('.'))
2581  call assert_equal('1', getline('.'))
2582  call cursor(10, 1)
2583  norm! g'a
2584  call assert_equal('>', a[-1:])
2585  call assert_equal(1, line('.'))
2586  let v:errmsg = ''
2587  call assert_nobeep("normal! g`\<Esc>")
2588  call assert_equal('', v:errmsg)
2589  call assert_nobeep("normal! g'\<Esc>")
2590  call assert_equal('', v:errmsg)
2591
2592  " Test for g; and g,
2593  norm! g;
2594  " there is only one change in the changelist
2595  " currently, when we setup the window
2596  call assert_equal(2, line('.'))
2597  call assert_fails(':norm! g;', 'E662')
2598  call assert_fails(':norm! g,', 'E663')
2599  let &ul = &ul
2600  call append('$', ['a', 'b', 'c', 'd'])
2601  let &ul = &ul
2602  call append('$', ['Z', 'Y', 'X', 'W'])
2603  let a = execute(':changes')
2604  call assert_match('2\s\+0\s\+2', a)
2605  call assert_match('101\s\+0\s\+a', a)
2606  call assert_match('105\s\+0\s\+Z', a)
2607  norm! 3g;
2608  call assert_equal(2, line('.'))
2609  norm! 2g,
2610  call assert_equal(105, line('.'))
2611
2612  " Test for g& - global substitute
2613  %d
2614  call setline(1, range(1,10))
2615  call append('$', ['a', 'b', 'c', 'd'])
2616  $s/\w/&&/g
2617  exe "norm! /[1-8]\<cr>"
2618  norm! g&
2619  call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
2620
2621  " Jumping to a fold using gg should open the fold
2622  set foldenable
2623  set foldopen+=jump
2624  5,8fold
2625  call feedkeys('6gg', 'xt')
2626  call assert_equal(1, foldlevel('.'))
2627  call assert_equal(-1, foldclosed('.'))
2628  set foldopen-=jump
2629  set foldenable&
2630
2631  " Test for gv
2632  %d
2633  call append('$', repeat(['abcdefgh'], 8))
2634  exe "norm! 2gg02l\<c-v>2j2ly"
2635  call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
2636  " in visual mode, gv swaps current and last selected region
2637  exe "norm! G0\<c-v>4k4lgvd"
2638  call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
2639  exe "norm! G0\<c-v>4k4ly"
2640  exe "norm! gvood"
2641  call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
2642  " gv works in operator pending mode
2643  call assert_nobeep('normal! cgvxyza')
2644  call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'xyza', 'xyza', 'xyza', 'xyza', 'xyza'], getline(1,'$'))
2645  exe "norm! ^\<c-v>Gydgv..cgvbc"
2646  call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'bc', 'bc', 'bc', 'bc', 'bc'], getline(1,'$'))
2647  exe "norm! v^GragggUgv"
2648  call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'bA', 'AA', 'AA', 'AA', 'Ac'], getline(1,'$'))
2649
2650  " gv should beep without a previously selected visual area
2651  new
2652  call assert_beeps('normal! gv')
2653  close
2654
2655  " Test for gk/gj
2656  %d
2657  15vsp
2658  set wrap listchars= sbr=
2659  let lineA = 'abcdefghijklmnopqrstuvwxyz'
2660  let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
2661  let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
2662  $put =lineA
2663  $put =lineB
2664
2665  norm! 3gg0dgk
2666  call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
2667  set nu
2668  norm! 3gg0gjdgj
2669  call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2670
2671  " Test for gJ
2672  norm! 2gggJ
2673  call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2674  call assert_equal(16, col('.'))
2675  " shouldn't do anything
2676  norm! 10gJ
2677  call assert_equal(1, col('.'))
2678
2679  " Test for g0 g^ gm g$
2680  exe "norm! 2gg0gji   "
2681  call assert_equal(['', 'abcdefghijk   lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2682  norm! g0yl
2683  call assert_equal(12, col('.'))
2684  call assert_equal(' ', getreg(0))
2685  norm! g$yl
2686  call assert_equal(22, col('.'))
2687  call assert_equal('3', getreg(0))
2688  norm! gmyl
2689  call assert_equal(17, col('.'))
2690  call assert_equal('n', getreg(0))
2691  norm! g^yl
2692  call assert_equal(15, col('.'))
2693  call assert_equal('l', getreg(0))
2694  call assert_beeps('normal 5g$')
2695
2696  " Test for g$ with double-width character half displayed
2697  vsplit
2698  9wincmd |
2699  setlocal nowrap nonumber
2700  call setline(2, 'asdfasdfヨ')
2701  2
2702  normal 0g$
2703  call assert_equal(8, col('.'))
2704  10wincmd |
2705  normal 0g$
2706  call assert_equal(9, col('.'))
2707
2708  setlocal signcolumn=yes
2709  11wincmd |
2710  normal 0g$
2711  call assert_equal(8, col('.'))
2712  12wincmd |
2713  normal 0g$
2714  call assert_equal(9, col('.'))
2715
2716  close
2717
2718  " Test for g_
2719  call assert_beeps('normal! 100g_')
2720  call setline(2, ['  foo  ', '  foobar  '])
2721  normal! 2ggg_
2722  call assert_equal(5, col('.'))
2723  normal! 2g_
2724  call assert_equal(8, col('.'))
2725
2726  norm! 2ggdG
2727  $put =lineC
2728
2729  " Test for gM
2730  norm! gMyl
2731  call assert_equal(73, col('.'))
2732  call assert_equal('0', getreg(0))
2733  " Test for 20gM
2734  norm! 20gMyl
2735  call assert_equal(29, col('.'))
2736  call assert_equal('S', getreg(0))
2737  " Test for 60gM
2738  norm! 60gMyl
2739  call assert_equal(87, col('.'))
2740  call assert_equal('E', getreg(0))
2741
2742  " Have an odd number of chars in the line
2743  norm! A.
2744  call assert_equal(145, col('.'))
2745  norm! gMyl
2746  call assert_equal(73, col('.'))
2747  call assert_equal('0', getreg(0))
2748
2749  " 'listchars' "eol" should not affect gM behavior
2750  setlocal list listchars=eol:$
2751  norm! $
2752  call assert_equal(145, col('.'))
2753  norm! gMyl
2754  call assert_equal(73, col('.'))
2755  call assert_equal('0', getreg(0))
2756  setlocal nolist
2757
2758  " Test for gM with Tab characters
2759  call setline('.', "\ta\tb\tc\td\te\tf")
2760  norm! gMyl
2761  call assert_equal(6, col('.'))
2762  call assert_equal("c", getreg(0))
2763
2764  " Test for g Ctrl-G
2765  call setline('.', lineC)
2766  norm! 60gMyl
2767  set ff=unix
2768  let a=execute(":norm! g\<c-g>")
2769  call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
2770
2771  " Test for gI
2772  norm! gIfoo
2773  call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
2774
2775  " Test for gi
2776  wincmd c
2777  %d
2778  set tw=0
2779  call setline(1, ['foobar', 'new line'])
2780  norm! A next word
2781  $put ='third line'
2782  norm! gi another word
2783  call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
2784  call setline(1, 'foobar')
2785  normal! Ggifirst line
2786  call assert_equal('foobarfirst line', getline(1))
2787  " Test gi in 'virtualedit' mode with cursor after the end of the line
2788  set virtualedit=all
2789  call setline(1, 'foo')
2790  exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
2791  call setline(1, 'foo')
2792  normal! Ggifirst line
2793  call assert_equal('foo       first line', getline(1))
2794  set virtualedit&
2795
2796  " Test for aborting a g command using CTRL-\ CTRL-G
2797  exe "normal! g\<C-\>\<C-G>"
2798  call assert_equal('foo       first line', getline('.'))
2799
2800  " clean up
2801  bw!
2802endfunc
2803
2804func Test_normal_ex_substitute()
2805  throw 'Skipped: Nvim "gQ" restores multicursors (not Ex-mode)'
2806  " This was hanging on the substitute prompt.
2807  new
2808  call setline(1, 'a')
2809  exe "normal! gggQs/a/b/c\<CR>"
2810  call assert_equal('a', getline(1))
2811  bwipe!
2812endfunc
2813
2814" Test for g CTRL-G
2815func Test_g_ctrl_g()
2816  new
2817
2818  let a = execute(":norm! g\<c-g>")
2819  call assert_equal("\n--No lines in buffer--", a)
2820
2821  " Test for CTRL-G (same as :file)
2822  let a = execute(":norm! \<c-g>")
2823  call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
2824
2825  call setline(1, ['first line', 'second line'])
2826
2827  " Test g CTRL-g with dos, mac and unix file type.
2828  norm! gojll
2829  set ff=dos
2830  let a = execute(":norm! g\<c-g>")
2831  call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
2832
2833  set ff=mac
2834  let a = execute(":norm! g\<c-g>")
2835  call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2836
2837  set ff=unix
2838  let a = execute(":norm! g\<c-g>")
2839  call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2840
2841  " Test g CTRL-g in visual mode (v)
2842  let a = execute(":norm! gojllvlg\<c-g>")
2843  call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
2844
2845  " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2846  let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2847  call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2848
2849  " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2850  let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2851  call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2852
2853  " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2854  let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2855  call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2856
2857  " There should be one byte less with noeol
2858  set bin noeol
2859  let a = execute(":norm! \<Esc>gog\<c-g>")
2860  call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2861  set bin & eol&
2862
2863  call setline(1, ['Français', '日本語'])
2864
2865  let a = execute(":norm! \<Esc>gojlg\<c-g>")
2866  call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
2867
2868  let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2869  call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
2870
2871  let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2872  call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
2873
2874  set fenc=utf8 bomb
2875  let a = execute(":norm! \<Esc>gojlg\<c-g>")
2876  call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
2877
2878  set fenc=utf16 bomb
2879  let a = execute(":norm! g\<c-g>")
2880  call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
2881
2882  set fenc=utf32 bomb
2883  let a = execute(":norm! g\<c-g>")
2884  call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
2885
2886  set fenc& bomb&
2887
2888  set ff&
2889  bwipe!
2890endfunc
2891
2892" Test for g8
2893func Test_normal34_g_cmd3()
2894  new
2895  let a=execute(':norm! 1G0g8')
2896  call assert_equal("\nNUL", a)
2897
2898  call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2899  let a=execute(':norm! 1G$g8')
2900  call assert_equal("\nc3 b6 ", a)
2901
2902  call setline(1, "a\u0302")
2903  let a=execute(':norm! 1G0g8')
2904  call assert_equal("\n61 + cc 82 ", a)
2905
2906  " clean up
2907  bw!
2908endfunc
2909
2910" Test 8g8 which finds invalid utf8 at or after the cursor.
2911func Test_normal_8g8()
2912  new
2913
2914  " With invalid byte.
2915  call setline(1, "___\xff___")
2916  norm! 1G08g8g
2917  call assert_equal([0, 1, 4, 0, 4], getcurpos())
2918
2919  " With invalid byte before the cursor.
2920  call setline(1, "___\xff___")
2921  norm! 1G$h8g8g
2922  call assert_equal([0, 1, 6, 0, 9], getcurpos())
2923
2924  " With truncated sequence.
2925  call setline(1, "___\xE2\x82___")
2926  norm! 1G08g8g
2927  call assert_equal([0, 1, 4, 0, 4], getcurpos())
2928
2929  " With overlong sequence.
2930  call setline(1, "___\xF0\x82\x82\xAC___")
2931  norm! 1G08g8g
2932  call assert_equal([0, 1, 4, 0, 4], getcurpos())
2933
2934  " With valid utf8.
2935  call setline(1, "café")
2936  norm! 1G08g8
2937  call assert_equal([0, 1, 1, 0, 1], getcurpos())
2938
2939  bw!
2940endfunc
2941
2942" Test for g<
2943func Test_normal35_g_cmd4()
2944  " Cannot capture its output,
2945  " probably a bug, therefore, test disabled:
2946  throw "Skipped: output of g< can't be tested currently"
2947  echo "a\nb\nc\nd"
2948  let b=execute(':norm! g<')
2949  call assert_true(!empty(b), 'failed `execute(g<)`')
2950endfunc
2951
2952" Test for gp gP go
2953func Test_normal36_g_cmd5()
2954  new
2955  call append(0, 'abcdefghijklmnopqrstuvwxyz')
2956  set ff=unix
2957  " Test for gp gP
2958  call append(1, range(1,10))
2959  1
2960  norm! 1yy
2961  3
2962  norm! gp
2963  call assert_equal([0, 5, 1, 0, 1], getcurpos())
2964  $
2965  norm! gP
2966  call assert_equal([0, 14, 1, 0, 1], getcurpos())
2967
2968  " Test for go
2969  norm! 26go
2970  call assert_equal([0, 1, 26, 0, 26], getcurpos())
2971  norm! 27go
2972  call assert_equal([0, 1, 26, 0, 26], getcurpos())
2973  norm! 28go
2974  call assert_equal([0, 2, 1, 0, 1], getcurpos())
2975  set ff=dos
2976  norm! 29go
2977  call assert_equal([0, 2, 1, 0, 1], getcurpos())
2978  set ff=unix
2979  norm! gg0
2980  norm! 101go
2981  call assert_equal([0, 13, 26, 0, 26], getcurpos())
2982  norm! 103go
2983  call assert_equal([0, 14, 1, 0, 1], getcurpos())
2984  " count > buffer content
2985  norm! 120go
2986  call assert_equal([0, 14, 1, 0, v:maxcol], getcurpos())
2987  " clean up
2988  bw!
2989endfunc
2990
2991" Test for gt and gT
2992func Test_normal37_g_cmd6()
2993  tabnew 1.txt
2994  tabnew 2.txt
2995  tabnew 3.txt
2996  norm! 1gt
2997  call assert_equal(1, tabpagenr())
2998  norm! 3gt
2999  call assert_equal(3, tabpagenr())
3000  norm! 1gT
3001  " count gT goes not to the absolute tabpagenumber
3002  " but, but goes to the count previous tabpagenumber
3003  call assert_equal(2, tabpagenr())
3004  " wrap around
3005  norm! 3gT
3006  call assert_equal(3, tabpagenr())
3007  " gt does not wrap around
3008  norm! 5gt
3009  call assert_equal(3, tabpagenr())
3010
3011  for i in range(3)
3012    tabclose
3013  endfor
3014  " clean up
3015  call assert_fails(':tabclose', 'E784:')
3016endfunc
3017
3018" Test for <Home> and <C-Home> key
3019func Test_normal38_nvhome()
3020  new
3021  call setline(1, range(10))
3022  $
3023  setl et sw=2
3024  norm! V10>$
3025  " count is ignored
3026  exe "norm! 10\<home>"
3027  call assert_equal(1, col('.'))
3028  exe "norm! \<home>"
3029  call assert_equal([0, 10, 1, 0, 1], getcurpos())
3030  exe "norm! 5\<c-home>"
3031  call assert_equal([0, 5, 1, 0, 1], getcurpos())
3032  exe "norm! \<c-home>"
3033  call assert_equal([0, 1, 1, 0, 1], getcurpos())
3034  exe "norm! G\<c-kHome>"
3035  call assert_equal([0, 1, 1, 0, 1], getcurpos())
3036
3037  " clean up
3038  bw!
3039endfunc
3040
3041" Test for <End> and <C-End> keys
3042func Test_normal_nvend()
3043  new
3044  call setline(1, map(range(1, 10), '"line" .. v:val'))
3045  exe "normal! \<End>"
3046  call assert_equal(5, col('.'))
3047  exe "normal! 4\<End>"
3048  call assert_equal([4, 5], [line('.'), col('.')])
3049  exe "normal! \<C-End>"
3050  call assert_equal([10, 6], [line('.'), col('.')])
3051
3052  bwipe!
3053endfunc
3054
3055" Test for cw cW ce
3056func Test_normal39_cw()
3057  " Test for cw and cW on whitespace
3058  new
3059  set tw=0
3060  call append(0, 'here      are   some words')
3061  norm! 1gg0elcwZZZ
3062  call assert_equal('hereZZZare   some words', getline('.'))
3063  norm! 1gg0elcWYYY
3064  call assert_equal('hereZZZareYYYsome words', getline('.'))
3065  norm! 2gg0cwfoo
3066  call assert_equal('foo', getline('.'))
3067
3068  call setline(1, 'one; two')
3069  call cursor(1, 1)
3070  call feedkeys('cwvim', 'xt')
3071  call assert_equal('vim; two', getline(1))
3072  call feedkeys('0cWone', 'xt')
3073  call assert_equal('one two', getline(1))
3074  "When cursor is at the end of a word 'ce' will change until the end of the
3075  "next word, but 'cw' will change only one character
3076  call setline(1, 'one two')
3077  call feedkeys('0ecwce', 'xt')
3078  call assert_equal('once two', getline(1))
3079  call setline(1, 'one two')
3080  call feedkeys('0ecely', 'xt')
3081  call assert_equal('only', getline(1))
3082
3083  " clean up
3084  bw!
3085endfunc
3086
3087" Test for CTRL-\ commands
3088func Test_normal40_ctrl_bsl()
3089  " Nvim #40312: includes a cmdwin assertion that doesn't translate
3090  " (cmdwin is now a normal window so CTRL-\ CTRL-N is a no-op there).
3091  throw 'Skipped: Nvim supports cmdwin freedom #40312'
3092  new
3093  call append(0, 'here      are   some words')
3094  exe "norm! 1gg0a\<C-\>\<C-N>"
3095  call assert_equal('n', mode())
3096  call assert_equal(1, col('.'))
3097  call assert_equal('', visualmode())
3098  exe "norm! 1gg0viw\<C-\>\<C-N>"
3099  call assert_equal('n', mode())
3100  call assert_equal(4, col('.'))
3101  exe "norm! 1gg0a\<C-\>\<C-G>"
3102  call assert_equal('n', mode())
3103  call assert_equal(1, col('.'))
3104  "imap <buffer> , <c-\><c-n>
3105  " set im
3106  exe ":norm! \<c-\>\<c-n>dw"
3107  " set noim
3108  call assert_equal('are   some words', getline(1))
3109  call assert_false(&insertmode)
3110  call assert_beeps("normal! \<C-\>\<C-A>")
3111
3112  " Using CTRL-\ CTRL-N in cmd window should close the window
3113  call feedkeys("q:\<C-\>\<C-N>", 'xt')
3114  call assert_equal('', getcmdwintype())
3115
3116  " clean up
3117  bw!
3118endfunc
3119
3120" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
3121func Test_normal41_insert_reg()
3122  new
3123  set sts=2 sw=2 ts=8 tw=0
3124  call append(0, ["aaa\tbbb\tccc", '', '', ''])
3125  let a=getline(1)
3126  norm! 2gg0
3127  exe "norm! a\<c-r>=a\<cr>"
3128  norm! 3gg0
3129  exe "norm! a\<c-r>\<c-r>=a\<cr>"
3130  norm! 4gg0
3131  exe "norm! a\<c-r>\<c-o>=a\<cr>"
3132  call assert_equal(['aaa	bbb	ccc', 'aaa bbb	ccc', 'aaa bbb	ccc', 'aaa	bbb	ccc', ''], getline(1, '$'))
3133
3134  " clean up
3135  set sts=0 sw=8 ts=8
3136  bw!
3137endfunc
3138
3139" Test for Ctrl-D and Ctrl-U
3140func Test_normal42_halfpage()
3141  call Setup_NewWindow()
3142  call assert_equal(5, &scroll)
3143  exe "norm! \<c-d>"
3144  call assert_equal('6', getline('.'))
3145  exe "norm! 2\<c-d>"
3146  call assert_equal('8', getline('.'))
3147  call assert_equal(2, &scroll)
3148  set scroll=5
3149  exe "norm! \<c-u>"
3150  call assert_equal('3', getline('.'))
3151  1
3152  set scrolloff=5
3153  exe "norm! \<c-d>"
3154  call assert_equal('10', getline('.'))
3155  exe "norm! \<c-u>"
3156  call assert_equal('5', getline('.'))
3157  1
3158  set scrolloff=99
3159  exe "norm! \<c-d>"
3160  call assert_equal('10', getline('.'))
3161  set scrolloff=0
3162  100
3163  exe "norm! $\<c-u>"
3164  call assert_equal('95', getline('.'))
3165  call assert_equal([0, 95, 1, 0, 1], getcurpos())
3166  100
3167  set nostartofline
3168  exe "norm! $\<c-u>"
3169  call assert_equal('95', getline('.'))
3170  call assert_equal([0, 95, 2, 0, v:maxcol], getcurpos())
3171  " cleanup
3172  set startofline
3173  bw!
3174endfunc
3175
3176func Test_normal45_drop()
3177  if !has('dnd')
3178    " The ~ register does not exist
3179    call assert_beeps('norm! "~')
3180    return
3181  endif
3182
3183  " basic test for drag-n-drop
3184  " unfortunately, without a gui, we can't really test much here,
3185  " so simply test that ~p fails (which uses the drop register)
3186  new
3187  call assert_fails(':norm! "~p', 'E353')
3188  call assert_equal([],  getreg('~', 1, 1))
3189  " the ~ register is read only
3190  call assert_fails(':let @~="1"', 'E354')
3191  bw!
3192endfunc
3193
3194func Test_normal46_ignore()
3195  new
3196  " How to test this?
3197  " let's just for now test, that the buffer
3198  " does not change
3199  call feedkeys("\<c-s>", 't')
3200  call assert_equal([''], getline(1,'$'))
3201
3202  " no valid commands
3203  exe "norm! \<char-0x100>"
3204  call assert_equal([''], getline(1,'$'))
3205
3206  exe "norm! ä"
3207  call assert_equal([''], getline(1,'$'))
3208
3209  " clean up
3210  bw!
3211endfunc
3212
3213func Test_normal47_visual_buf_wipe()
3214  " This was causing a crash or ml_get error.
3215  enew!
3216  call setline(1,'xxx')
3217  normal $
3218  new
3219  call setline(1, range(1,2))
3220  2
3221  exe "norm \<C-V>$"
3222  bw!
3223  norm yp
3224  set nomodified
3225endfunc
3226
3227func Test_normal48_wincmd()
3228  new
3229  exe "norm! \<c-w>c"
3230  call assert_equal(1, winnr('$'))
3231  call assert_fails(":norm! \<c-w>c", "E444")
3232endfunc
3233
3234func Test_normal49_counts()
3235  new
3236  call setline(1, 'one two three four five six seven eight nine ten')
3237  1
3238  norm! 3d2w
3239  call assert_equal('seven eight nine ten', getline(1))
3240  bw!
3241endfunc
3242
3243func Test_normal50_commandline()
3244  CheckFeature timers
3245  CheckFeature cmdline_hist
3246
3247  func! DoTimerWork(id)
3248    call assert_equal(1, getbufinfo('')[0].command)
3249
3250    " Nvim removed the E11 "Invalid in command-line window" restriction (#40312, #40484).
3251    "call assert_fails(":wincmd p", 'E11')
3252
3253    " Return from commandline window.
3254    call feedkeys("\<CR>", 't')
3255  endfunc
3256
3257  let oldlang=v:lang
3258  lang C
3259  set updatetime=20
3260  call timer_start(100, 'DoTimerWork')
3261  try
3262    " throws E23, for whatever reason...
3263    call feedkeys('q:', 'x!')
3264  catch /E23/
3265    " no-op
3266  endtry
3267
3268  " clean up
3269  delfunc DoTimerWork
3270  set updatetime=4000
3271  exe "lang" oldlang
3272  bw!
3273endfunc
3274
3275func Test_normal51_FileChangedRO()
3276  CheckFeature autocmd
3277  call writefile(['foo'], 'Xreadonly.log')
3278  new Xreadonly.log
3279  setl ro
3280  au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
3281  call assert_fails(":norm! Af", 'E788')
3282  call assert_equal(['foo'], getline(1,'$'))
3283  call assert_equal('Xreadonly.log', bufname(''))
3284
3285  " cleanup
3286  bw!
3287  call delete("Xreadonly.log")
3288endfunc
3289
3290func Test_normal52_rl()
3291  CheckFeature rightleft
3292  new
3293  call setline(1, 'abcde fghij klmnopq')
3294  norm! 1gg$
3295  set rl
3296  call assert_equal(19, col('.'))
3297  call feedkeys('l', 'tx')
3298  call assert_equal(18, col('.'))
3299  call feedkeys('h', 'tx')
3300  call assert_equal(19, col('.'))
3301  call feedkeys("\<right>", 'tx')
3302  call assert_equal(18, col('.'))
3303  call feedkeys("\<left>", 'tx')
3304  call assert_equal(19, col('.'))
3305  call feedkeys("\<s-right>", 'tx')
3306  call assert_equal(13, col('.'))
3307  call feedkeys("\<c-right>", 'tx')
3308  call assert_equal(7, col('.'))
3309  call feedkeys("\<c-left>", 'tx')
3310  call assert_equal(13, col('.'))
3311  call feedkeys("\<s-left>", 'tx')
3312  call assert_equal(19, col('.'))
3313  call feedkeys("<<", 'tx')
3314  call assert_equal('	abcde fghij klmnopq',getline(1))
3315  call feedkeys(">>", 'tx')
3316  call assert_equal('abcde fghij klmnopq',getline(1))
3317
3318  " cleanup
3319  set norl
3320  bw!
3321endfunc
3322
3323func Test_normal54_Ctrl_bsl()
3324  new
3325  call setline(1, 'abcdefghijklmn')
3326  exe "norm! df\<c-\>\<c-n>"
3327  call assert_equal(['abcdefghijklmn'], getline(1,'$'))
3328  exe "norm! df\<c-\>\<c-g>"
3329  call assert_equal(['abcdefghijklmn'], getline(1,'$'))
3330  exe "norm! df\<c-\>m"
3331  call assert_equal(['abcdefghijklmn'], getline(1,'$'))
3332
3333  call setline(2, 'abcdefghijklmnāf')
3334  norm! 2gg0
3335  exe "norm! df\<Char-0x101>"
3336  call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
3337  norm! 1gg0
3338  exe "norm! df\<esc>"
3339  call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
3340
3341  " clean up
3342  bw!
3343endfunc
3344
3345func Test_normal_large_count()
3346  " This may fail with 32bit long, how do we detect that?
3347  new
3348  normal o
3349  normal 6666666666dL
3350  bwipe!
3351endfunc
3352
3353func Test_delete_until_paragraph()
3354  new
3355  normal grádv}
3356  call assert_equal('á', getline(1))
3357  normal grád}
3358  call assert_equal('', getline(1))
3359  bwipe!
3360endfunc
3361
3362" Test for the gr (virtual replace) command
3363func Test_gr_command()
3364  enew!
3365  " Test for the bug fixed by 7.4.387
3366  let save_cpo = &cpo
3367  call append(0, ['First line', 'Second line', 'Third line'])
3368  exe "normal i\<C-G>u"
3369  call cursor(2, 1)
3370  set cpo-=X
3371  normal 4gro
3372  call assert_equal('oooond line', getline(2))
3373  undo
3374  set cpo+=X
3375  normal 4gro
3376  call assert_equal('ooooecond line', getline(2))
3377  let &cpo = save_cpo
3378
3379  normal! ggvegrx
3380  call assert_equal('xxxxx line', getline(1))
3381  exe "normal! gggr\<C-V>122"
3382  call assert_equal('zxxxx line', getline(1))
3383
3384  set virtualedit=all
3385  normal! 15|grl
3386  call assert_equal('zxxxx line    l', getline(1))
3387  set virtualedit&
3388  set nomodifiable
3389  call assert_fails('normal! grx', 'E21:')
3390  call assert_fails('normal! gRx', 'E21:')
3391  call assert_nobeep("normal! gr\<Esc>")
3392  set modifiable&
3393
3394  call assert_nobeep("normal! gr\<Esc>")
3395  call assert_nobeep("normal! cgr\<Esc>")
3396  call assert_beeps("normal! cgrx")
3397
3398  call assert_equal('zxxxx line    l', getline(1))
3399  exe "normal! 2|gr\<C-V>\<Esc>"
3400  call assert_equal("z\<Esc>xx line    l", getline(1))
3401
3402  call setline(1, 'abcdef')
3403  exe "normal! 0gr\<C-O>lx"
3404  call assert_equal("\<C-O>def", getline(1))
3405
3406  call setline(1, 'abcdef')
3407  exe "normal! 0gr\<C-G>lx"
3408  call assert_equal("\<C-G>def", getline(1))
3409
3410  bwipe!
3411endfunc
3412
3413func Test_nv_hat_count()
3414  %bwipeout!
3415  let l:nr = bufnr('%') + 1
3416  call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
3417
3418  edit Xfoo
3419  let l:foo_nr = bufnr('Xfoo')
3420
3421  edit Xbar
3422  let l:bar_nr = bufnr('Xbar')
3423
3424  " Make sure we are not just using the alternate file.
3425  edit Xbaz
3426
3427  call feedkeys(l:foo_nr . "\<C-^>", 'tx')
3428  call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
3429
3430  call feedkeys(l:bar_nr . "\<C-^>", 'tx')
3431  call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
3432
3433  %bwipeout!
3434endfunc
3435
3436func Test_message_when_using_ctrl_c()
3437  " Make sure no buffers are changed.
3438  %bwipe!
3439
3440  exe "normal \<C-C>"
3441  call assert_match("Type  :qa  and press <Enter> to exit Nvim", Screenline(&lines))
3442
3443  new
3444  cal setline(1, 'hi!')
3445  exe "normal \<C-C>"
3446  call assert_match("Type  :qa!  and press <Enter> to abandon all changes and exit Nvim", Screenline(&lines))
3447
3448  bwipe!
3449endfunc
3450
3451func Test_mode_updated_after_ctrl_c()
3452  CheckScreendump
3453
3454  let buf = RunVimInTerminal('', {'rows': 5})
3455  call term_sendkeys(buf, "i")
3456  call term_sendkeys(buf, "\<C-O>")
3457  " wait a moment so that the "-- (insert) --" message is displayed
3458  call TermWait(buf, 50)
3459  call term_sendkeys(buf, "\<C-C>")
3460  call VerifyScreenDump(buf, 'Test_mode_updated_1', {})
3461
3462  call StopVimInTerminal(buf)
3463endfunc
3464
3465" Test for '[m', ']m', '[M' and ']M'
3466" Jumping to beginning and end of methods in Java-like languages
3467func Test_java_motion()
3468  new
3469  call assert_beeps('normal! [m')
3470  call assert_beeps('normal! ]m')
3471  call assert_beeps('normal! [M')
3472  call assert_beeps('normal! ]M')
3473  let lines =<< trim [CODE]
3474	Piece of Java
3475	{
3476		tt m1 {
3477			t1;
3478		} e1
3479
3480		tt m2 {
3481			t2;
3482		} e2
3483
3484		tt m3 {
3485			if (x)
3486			{
3487				t3;
3488			}
3489		} e3
3490	}
3491  [CODE]
3492  call setline(1, lines)
3493
3494  normal gg
3495
3496  normal 2]maA
3497  call assert_equal("\ttt m1 {A", getline('.'))
3498  call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
3499
3500  normal j]maB
3501  call assert_equal("\ttt m2 {B", getline('.'))
3502  call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
3503
3504  normal ]maC
3505  call assert_equal("\ttt m3 {C", getline('.'))
3506  call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
3507
3508  normal [maD
3509  call assert_equal("\ttt m3 {DC", getline('.'))
3510  call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
3511
3512  normal k2[maE
3513  call assert_equal("\ttt m1 {EA", getline('.'))
3514  call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
3515
3516  normal 3[maF
3517  call assert_equal("{F", getline('.'))
3518  call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
3519
3520  normal ]MaG
3521  call assert_equal("\t}G e1", getline('.'))
3522  call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
3523
3524  normal j2]MaH
3525  call assert_equal("\t}H e3", getline('.'))
3526  call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
3527
3528  normal ]M]M
3529  normal aI
3530  call assert_equal("}I", getline('.'))
3531  call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
3532
3533  normal 2[MaJ
3534  call assert_equal("\t}JH e3", getline('.'))
3535  call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
3536
3537  normal k[MaK
3538  call assert_equal("\t}K e2", getline('.'))
3539  call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
3540
3541  normal 3[MaL
3542  call assert_equal("{LF", getline('.'))
3543  call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
3544
3545  call cursor(2, 1)
3546  call assert_beeps('norm! 5]m')
3547
3548  " jumping to a method in a fold should open the fold
3549  6,10fold
3550  call feedkeys("gg3]m", 'xt')
3551  call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
3552  call assert_equal(-1, foldclosedend(7))
3553
3554  bwipe!
3555endfunc
3556
3557" Tests for g cmds
3558func Test_normal_gdollar_cmd()
3559  call Setup_NewWindow()
3560  " Make long lines that will wrap
3561  %s/$/\=repeat(' foobar', 10)/
3562  20vsp
3563  set wrap
3564  " Test for g$ with count
3565  norm! gg
3566  norm! 0vg$y
3567  call assert_equal(20, col("'>"))
3568  call assert_equal('1 foobar foobar foob', getreg(0))
3569  norm! gg
3570  norm! 0v4g$y
3571  call assert_equal(72, col("'>"))
3572  call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
3573  norm! gg
3574  norm! 0v6g$y
3575  call assert_equal(40, col("'>"))
3576  call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3577		  \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
3578  set nowrap
3579  " clean up
3580  norm! gg
3581  norm! 0vg$y
3582  call assert_equal(20, col("'>"))
3583  call assert_equal('1 foobar foobar foob', getreg(0))
3584  norm! gg
3585  norm! 0v4g$y
3586  call assert_equal(20, col("'>"))
3587  call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3588                 \  '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3589                 \  '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3590                 \  '4 foobar foobar foob', getreg(0))
3591  norm! gg
3592  norm! 0v6g$y
3593  call assert_equal(20, col("'>"))
3594  call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3595                 \  '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3596                 \  '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3597                 \  '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3598                 \  '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
3599                 \  '6 foobar foobar foob', getreg(0))
3600  " Move to last line, also down movement is not possible, should still move
3601  " the cursor to the last visible char
3602  norm! G
3603  norm! 0v6g$y
3604  call assert_equal(20, col("'>"))
3605  call assert_equal('100 foobar foobar fo', getreg(0))
3606  bw!
3607endfunc
3608
3609func Test_normal_gk_gj()
3610  " needs 80 column new window
3611  new
3612  vert 80new
3613  call assert_beeps('normal gk')
3614  put =[repeat('x',90)..' {{{1', 'x {{{1']
3615  norm! gk
3616  " In a 80 column wide terminal the window will be only 78 char
3617  " (because Vim will leave space for the other window),
3618  " but if the terminal is larger, it will be 80 chars, so verify the
3619  " cursor column correctly.
3620  call assert_equal(winwidth(0)+1, col('.'))
3621  call assert_equal(winwidth(0)+1, virtcol('.'))
3622  norm! j
3623  call assert_equal(6, col('.'))
3624  call assert_equal(6, virtcol('.'))
3625  norm! gk
3626  call assert_equal(95, col('.'))
3627  call assert_equal(95, virtcol('.'))
3628  %bw!
3629
3630  " needs 80 column new window
3631  new
3632  vert 80new
3633  call assert_beeps('normal gj')
3634  set number
3635  set numberwidth=10
3636  set cpoptions+=n
3637  put =[repeat('0',90), repeat('1',90)]
3638  norm! 075l
3639  call assert_equal(76, col('.'))
3640  norm! gk
3641  call assert_equal(1, col('.'))
3642  norm! gk
3643  call assert_equal(76, col('.'))
3644  norm! gk
3645  call assert_equal(1, col('.'))
3646  norm! gj
3647  call assert_equal(76, col('.'))
3648  norm! gj
3649  call assert_equal(1, col('.'))
3650  norm! gj
3651  call assert_equal(76, col('.'))
3652  " When 'nowrap' is set, gk and gj behave like k and j
3653  set nowrap
3654  normal! gk
3655  call assert_equal([2, 76], [line('.'), col('.')])
3656  normal! gj
3657  call assert_equal([3, 76], [line('.'), col('.')])
3658  %bw!
3659  set cpoptions& number& numberwidth& wrap&
3660endfunc
3661
3662" Test for using : to run a multi-line Ex command in operator pending mode
3663func Test_normal_yank_with_excmd()
3664  new
3665  call setline(1, ['foo', 'bar', 'baz'])
3666  let @a = ''
3667  call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
3668  call assert_equal('f', @a)
3669
3670  bwipe!
3671endfunc
3672
3673" Test for supplying a count to a normal-mode command across a cursorhold call
3674func Test_normal_cursorhold_with_count()
3675  throw 'Skipped: Nvim removed <CursorHold> key'
3676  func s:cHold()
3677    let g:cHold_Called += 1
3678  endfunc
3679  new
3680  augroup normalcHoldTest
3681    au!
3682    au CursorHold <buffer> call s:cHold()
3683  augroup END
3684  let g:cHold_Called = 0
3685  call feedkeys("3\<CursorHold>2ix", 'xt')
3686  call assert_equal(1, g:cHold_Called)
3687  call assert_equal(repeat('x', 32), getline(1))
3688  augroup normalcHoldTest
3689    au!
3690  augroup END
3691  au! normalcHoldTest
3692
3693  bwipe!
3694  delfunc s:cHold
3695endfunc
3696
3697" Test for using a count and a command with CTRL-W
3698func Test_wincmd_with_count()
3699  call feedkeys("\<C-W>12n", 'xt')
3700  call assert_equal(12, winheight(0))
3701endfunc
3702
3703" Test for 'b', 'B' 'ge' and 'gE' commands
3704func Test_horiz_motion()
3705  new
3706  normal! gg
3707  call assert_beeps('normal! b')
3708  call assert_beeps('normal! B')
3709  call assert_beeps('normal! gE')
3710  call assert_beeps('normal! ge')
3711  " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3712  call setline(1, 'one ,two ,three')
3713  exe "normal! $\<S-BS>"
3714  call assert_equal(11, col('.'))
3715  exe "normal! $\<C-BS>"
3716  call assert_equal(10, col('.'))
3717
3718  bwipe!
3719endfunc
3720
3721" Test for using a ":" command in operator pending mode
3722func Test_normal_colon_op()
3723  new
3724  call setline(1, ['one', 'two'])
3725  call assert_beeps("normal! Gc:d\<CR>")
3726  call assert_equal(['one'], getline(1, '$'))
3727
3728  call setline(1, ['one…two…three!'])
3729  normal! $
3730  " Using ":" as a movement is characterwise exclusive
3731  call feedkeys("d:normal! F…\<CR>", 'xt')
3732  call assert_equal(['one…two!'], getline(1, '$'))
3733  " Check that redoing a command with 0x80 bytes works
3734  call feedkeys('.', 'xt')
3735  call assert_equal(['one!'], getline(1, '$'))
3736
3737  call setline(1, ['one', 'two', 'three', 'four', 'five'])
3738  " Add this to the command history
3739  call feedkeys(":normal! G0\<CR>", 'xt')
3740  " Use :normal! with control characters in operator pending mode
3741  call feedkeys("d:normal! \<C-V>\<C-P>\<C-V>\<C-P>\<CR>", 'xt')
3742  call assert_equal(['one', 'two', 'five'], getline(1, '$'))
3743  " Check that redoing a command with control characters works
3744  call feedkeys('.', 'xt')
3745  call assert_equal(['five'], getline(1, '$'))
3746
3747  bwipe!
3748endfunc
3749
3750" Test for d and D commands
3751func Test_normal_delete_cmd()
3752  new
3753  " D in an empty line
3754  call setline(1, '')
3755  normal D
3756  call assert_equal('', getline(1))
3757  " D in an empty line in virtualedit mode
3758  set virtualedit=all
3759  normal D
3760  call assert_equal('', getline(1))
3761  set virtualedit&
3762  " delete to a readonly register
3763  call setline(1, ['abcd'])
3764  call assert_beeps('normal ":d2l')
3765
3766  " D and d with 'nomodifiable'
3767  call setline(1, ['abcd'])
3768  setlocal nomodifiable
3769  call assert_fails('normal D', 'E21:')
3770  call assert_fails('normal d$', 'E21:')
3771
3772  bwipe!
3773endfunc
3774
3775" Test for deleting or changing characters across lines with 'whichwrap'
3776" containing 's'. Should count <EOL> as one character.
3777func Test_normal_op_across_lines()
3778  new
3779  set whichwrap&
3780  call setline(1, ['one two', 'three four'])
3781  exe "norm! $3d\<Space>"
3782  call assert_equal(['one twhree four'], getline(1, '$'))
3783
3784  call setline(1, ['one two', 'three four'])
3785  exe "norm! $3c\<Space>x"
3786  call assert_equal(['one twxhree four'], getline(1, '$'))
3787
3788  set whichwrap+=l
3789  call setline(1, ['one two', 'three four'])
3790  exe "norm! $3x"
3791  call assert_equal(['one twhree four'], getline(1, '$'))
3792
3793  bwipe!
3794  set whichwrap&
3795endfunc
3796
3797" Test for 'w' and 'b' commands
3798func Test_normal_word_move()
3799  new
3800  call setline(1, ['foo bar a', '', 'foo bar b'])
3801  " copy a single character word at the end of a line
3802  normal 1G$yw
3803  call assert_equal('a', @")
3804  " copy a single character word at the end of a file
3805  normal G$yw
3806  call assert_equal('b', @")
3807  " check for a word movement handling an empty line properly
3808  normal 1G$vwy
3809  call assert_equal("a\n\n", @")
3810
3811  " copy using 'b' command
3812  %d
3813  " non-empty blank line at the start of file
3814  call setline(1, ['  ', 'foo bar'])
3815  normal 2Gyb
3816  call assert_equal("  \n", @")
3817  " try to copy backwards from the start of the file
3818  call setline(1, ['one two', 'foo bar'])
3819  call assert_beeps('normal ggyb')
3820  " 'b' command should stop at an empty line
3821  call setline(1, ['one two', '', 'foo bar'])
3822  normal 3Gyb
3823  call assert_equal("\n", @")
3824  normal 3Gy2b
3825  call assert_equal("two\n", @")
3826  " 'b' command should not stop at a non-empty blank line
3827  call setline(1, ['one two', '  ', 'foo bar'])
3828  normal 3Gyb
3829  call assert_equal("two\n  ", @")
3830
3831  bwipe!
3832endfunc
3833
3834" Test for 'scrolloff' with a long line that doesn't fit in the screen
3835func Test_normal_scrolloff()
3836  10new
3837  60vnew
3838  call setline(1, ' 1 ' .. repeat('a', 57)
3839             \ .. ' 2 ' .. repeat('b', 57)
3840             \ .. ' 3 ' .. repeat('c', 57)
3841             \ .. ' 4 ' .. repeat('d', 57)
3842             \ .. ' 5 ' .. repeat('e', 57)
3843             \ .. ' 6 ' .. repeat('f', 57)
3844             \ .. ' 7 ' .. repeat('g', 57)
3845             \ .. ' 8 ' .. repeat('h', 57)
3846             \ .. ' 9 ' .. repeat('i', 57)
3847             \ .. '10 ' .. repeat('j', 57)
3848             \ .. '11 ' .. repeat('k', 57)
3849             \ .. '12 ' .. repeat('l', 57)
3850             \ .. '13 ' .. repeat('m', 57)
3851             \ .. '14 ' .. repeat('n', 57)
3852             \ .. '15 ' .. repeat('o', 57)
3853             \ .. '16 ' .. repeat('p', 57)
3854             \ .. '17 ' .. repeat('q', 57)
3855             \ .. '18 ' .. repeat('r', 57)
3856             \ .. '19 ' .. repeat('s', 57)
3857             \ .. '20 ' .. repeat('t', 57)
3858             \ .. '21 ' .. repeat('u', 57)
3859             \ .. '22 ' .. repeat('v', 57)
3860             \ .. '23 ' .. repeat('w', 57)
3861             \ .. '24 ' .. repeat('x', 57)
3862             \ .. '25 ' .. repeat('y', 57)
3863             \ .. '26 ' .. repeat('z', 57)
3864             \ )
3865  set scrolloff=10
3866  normal gg10gj
3867  call assert_equal(6, winline())
3868  normal 10gj
3869  call assert_equal(6, winline())
3870  normal 10gk
3871  call assert_equal(6, winline())
3872  normal 0
3873  call assert_equal(1, winline())
3874  normal $
3875  call assert_equal(10, winline())
3876
3877  set scrolloff&
3878  bwipe!
3879endfunc
3880
3881" Test for vertical scrolling with CTRL-F and CTRL-B with a long line
3882func Test_normal_vert_scroll_longline()
3883  10new
3884  80vnew
3885  call setline(1, range(1, 10))
3886  call append(5, repeat('a', 1000))
3887  exe "normal gg\<C-F>"
3888  call assert_equal(6, line('.'))
3889  exe "normal \<C-F>\<C-F>"
3890  call assert_equal(11, line('.'))
3891  call assert_equal(1, winline())
3892  exe "normal \<C-B>"
3893  call assert_equal(11, line('.'))
3894  call assert_equal(5, winline())
3895  exe "normal \<C-B>\<C-B>"
3896  call assert_equal(5, line('.'))
3897  call assert_equal(5, winline())
3898
3899  bwipe!
3900endfunc
3901
3902" Test for jumping in a file using %
3903func Test_normal_percent_jump()
3904  new
3905  call setline(1, range(1, 100))
3906
3907  " jumping to a folded line should open the fold
3908  25,75fold
3909  call feedkeys('50%', 'xt')
3910  call assert_equal(50, line('.'))
3911  call assert_equal(-1, foldclosedend(50))
3912
3913  bwipe!
3914endfunc
3915
3916" Test that "%" skips parens inside comments when 'comments' defines C-style
3917" "//" or "/*" comments.
3918func Test_normal_percent_skip_comment()
3919  new
3920  setlocal comments=s1:/*,mb:*,ex:*/,://
3921
3922  " Forward: skip a ")" inside a // comment, match the real one.
3923  silent! %delete _
3924  call setline(1, ['foo(  // )', ');'])
3925  call cursor(1, 4)
3926  normal %
3927  call assert_equal([2, 1], [line('.'), col('.')])
3928
3929  " Forward: skip a ")" inside a /* */ comment, match the real one.
3930  silent! %delete _
3931  call setline(1, ['bar( /* ) */ x)'])
3932  call cursor(1, 4)
3933  normal %
3934  call assert_equal([1, 15], [line('.'), col('.')])
3935
3936  " Backward: skip a "(" inside a // comment, match the real one.
3937  silent! %delete _
3938  call setline(1, ['( // (', ')'])
3939  call cursor(2, 1)
3940  normal %
3941  call assert_equal([1, 1], [line('.'), col('.')])
3942
3943  " Cursor inside a // comment: a match inside that comment is still found.
3944  silent! %delete _
3945  call setline(1, ['x // ( y )'])
3946  call cursor(1, 6)
3947  normal %
3948  call assert_equal([1, 10], [line('.'), col('.')])
3949
3950  " Cursor inside a /* */ comment: a match inside that comment is still found.
3951  silent! %delete _
3952  call setline(1, ['/* a ( b ) c */'])
3953  call cursor(1, 6)
3954  normal %
3955  call assert_equal([1, 10], [line('.'), col('.')])
3956
3957  " When 'comments' has no C-style comments the parens are not skipped.
3958  setlocal comments=b:#
3959  silent! %delete _
3960  call setline(1, ['foo(  // )', ');'])
3961  call cursor(1, 4)
3962  normal %
3963  call assert_equal([1, 10], [line('.'), col('.')])
3964
3965  " With "%" in 'cpoptions' Vi-compatible matching is used and the parens
3966  " inside comments are not skipped.
3967  let save_cpo = &cpoptions
3968  setlocal comments=s1:/*,mb:*,ex:*/,://
3969  set cpoptions+=%
3970  silent! %delete _
3971  call setline(1, ['foo(  // )', ');'])
3972  call cursor(1, 4)
3973  normal %
3974  call assert_equal([1, 10], [line('.'), col('.')])
3975  let &cpoptions = save_cpo
3976
3977  bwipe!
3978endfunc
3979
3980" A "//" inside a string must not be treated as a line comment by "%".  The
3981" line is scanned in a single pass, so this stays fast even on lines with many
3982" slashes (e.g. base64 data).
3983func Test_normal_percent_skip_comment_string()
3984  new
3985  setlocal comments=s1:/*,mb:*,ex:*/,://
3986
3987  " The "//" inside the string is not a comment, so "(" matches the real ")".
3988  call setline(1, ['("a // b")'])
3989  call cursor(1, 1)
3990  normal %
3991  call assert_equal([1, 10], [line('.'), col('.')])
3992
3993  " JSON-like: "{" matches the closing "}" although the string has slashes.
3994  silent! %delete _
3995  call setline(1, ['{', '  "k": "x//y",', '}'])
3996  call cursor(1, 1)
3997  normal %
3998  call assert_equal([3, 1], [line('.'), col('.')])
3999
4000  " A "/*" inside a string must not start a block comment, so "(" still
4001  " matches the real ")" after the string.
4002  silent! %delete _
4003  call setline(1, ['( "a /* b" )'])
4004  call cursor(1, 1)
4005  normal %
4006  call assert_equal([1, 12], [line('.'), col('.')])
4007
4008  " A real /* */ block comment is still skipped: "(" matches the last ")".
4009  silent! %delete _
4010  call setline(1, ['( /* ) */ x )'])
4011  call cursor(1, 1)
4012  normal %
4013  call assert_equal([1, 13], [line('.'), col('.')])
4014
4015  bwipe!
4016endfunc
4017
4018" Test for << and >> commands to shift text by 'shiftwidth'
4019func Test_normal_shift_rightleft()
4020  new
4021  call setline(1, ['one', '', "\t", '  two', "\tthree", '      four'])
4022  set shiftwidth=2 tabstop=8
4023  normal gg6>>
4024  call assert_equal(['  one', '', "\t  ", '    two', "\t  three", "\tfour"],
4025        \ getline(1, '$'))
4026  normal ggVG2>>
4027  call assert_equal(['      one', '', "\t      ", "\ttwo",
4028        \ "\t      three", "\t    four"], getline(1, '$'))
4029  normal gg6<<
4030  call assert_equal(['    one', '', "\t    ", '      two', "\t    three",
4031        \ "\t  four"], getline(1, '$'))
4032  normal ggVG2<<
4033  call assert_equal(['one', '', "\t", '  two', "\tthree", '      four'],
4034        \ getline(1, '$'))
4035  set shiftwidth& tabstop&
4036  bw!
4037endfunc
4038
4039" Some commands like yy, cc, dd, >>, << and !! accept a count after
4040" typing the first letter of the command.
4041func Test_normal_count_after_operator()
4042  new
4043  setlocal shiftwidth=4 tabstop=8 autoindent
4044  call setline(1, ['one', 'two', 'three', 'four', 'five'])
4045  let @a = ''
4046  normal! j"ay4y
4047  call assert_equal("two\nthree\nfour\nfive\n", @a)
4048  normal! 3G>2>
4049  call assert_equal(['one', 'two', '    three', '    four', 'five'],
4050        \ getline(1, '$'))
4051  exe "normal! 3G0c2cred\nblue"
4052  call assert_equal(['one', 'two', '    red', '    blue', 'five'],
4053        \ getline(1, '$'))
4054  exe "normal! gg<8<"
4055  call assert_equal(['one', 'two', 'red', 'blue', 'five'],
4056        \ getline(1, '$'))
4057  exe "normal! ggd3d"
4058  call assert_equal(['blue', 'five'], getline(1, '$'))
4059  call setline(1, range(1, 4))
4060  call feedkeys("gg!3!\<C-B>\"\<CR>", 'xt')
4061  call assert_equal('".,.+2!', @:)
4062  call feedkeys("gg!1!\<C-B>\"\<CR>", 'xt')
4063  call assert_equal('".!', @:)
4064  call feedkeys("gg!9!\<C-B>\"\<CR>", 'xt')
4065  call assert_equal('".,$!', @:)
4066  bw!
4067endfunc
4068
4069func Test_normal_gj_on_6_cell_wide_unprintable_char()
4070  new | 25vsp
4071  let text='1 foooooooo ar e  ins​zwe1 foooooooo ins​zwei' .
4072         \ ' i drei vier fünf sechs sieben acht un zehn elf zwöfl' .
4073         \ ' dreizehn v ierzehn fünfzehn'
4074  put =text
4075  call cursor(2,1)
4076  norm! gj
4077  call assert_equal([0,2,25,0], getpos('.'))
4078  bw!
4079endfunc
4080
4081func Test_normal_count_out_of_range()
4082  new
4083  call setline(1, 'text')
4084  normal 44444444444|
4085  call assert_equal(999999999, v:count)
4086  normal 444444444444|
4087  call assert_equal(999999999, v:count)
4088  normal 4444444444444|
4089  call assert_equal(999999999, v:count)
4090  normal 4444444444444444444|
4091  call assert_equal(999999999, v:count)
4092
4093  normal 9y99999999|
4094  call assert_equal(899999991, v:count)
4095  normal 10y99999999|
4096  call assert_equal(999999999, v:count)
4097  normal 44444444444y44444444444|
4098  call assert_equal(999999999, v:count)
4099  bwipe!
4100endfunc
4101
4102" Test that mouse shape is restored to Normal mode after failed "c" operation.
4103func Test_mouse_shape_after_failed_change()
4104  CheckFeature mouseshape
4105  CheckCanRunGui
4106
4107  let lines =<< trim END
4108    vim9script
4109    set mouseshape+=o:busy
4110    setlocal nomodifiable
4111    var mouse_shapes = []
4112
4113    feedkeys('c')
4114    timer_start(50, (_) => {
4115      mouse_shapes += [getmouseshape()]
4116      timer_start(50, (_) => {
4117        feedkeys('c')
4118        timer_start(50, (_) => {
4119          mouse_shapes += [getmouseshape()]
4120          timer_start(50, (_) => {
4121            writefile(mouse_shapes, 'Xmouseshapes')
4122            quit
4123          })
4124        })
4125      })
4126    })
4127  END
4128  call writefile(lines, 'Xmouseshape.vim', 'D')
4129  call RunVim([], [], "-g -S Xmouseshape.vim")
4130  call WaitForAssert({-> assert_equal(['busy', 'arrow'], readfile('Xmouseshapes'))}, 300)
4131
4132  call delete('Xmouseshapes')
4133endfunc
4134
4135" Test that mouse shape is restored to Normal mode after cancelling "gr".
4136func Test_mouse_shape_after_cancelling_gr()
4137  CheckFeature mouseshape
4138  CheckCanRunGui
4139
4140  let lines =<< trim END
4141    vim9script
4142    var mouse_shapes = []
4143
4144    feedkeys('gr')
4145    timer_start(50, (_) => {
4146      mouse_shapes += [getmouseshape()]
4147      timer_start(50, (_) => {
4148        feedkeys("\<Esc>")
4149        timer_start(50, (_) => {
4150          mouse_shapes += [getmouseshape()]
4151          timer_start(50, (_) => {
4152            writefile(mouse_shapes, 'Xmouseshapes')
4153            quit
4154          })
4155        })
4156      })
4157    })
4158  END
4159  call writefile(lines, 'Xmouseshape.vim', 'D')
4160  call RunVim([], [], "-g -S Xmouseshape.vim")
4161  call WaitForAssert({-> assert_equal(['beam', 'arrow'], readfile('Xmouseshapes'))}, 300)
4162
4163  call delete('Xmouseshapes')
4164endfunc
4165
4166" Test that "j" does not skip lines when scrolling below botline and
4167" 'foldmethod' is not "manual".
4168func Test_normal_j_below_botline()
4169  CheckScreendump
4170
4171  let lines =<< trim END
4172    set number foldmethod=diff scrolloff=0
4173    call setline(1, map(range(1, 9), 'repeat(v:val, 200)'))
4174    norm Lj
4175  END
4176  call writefile(lines, 'XNormalJBelowBotline', 'D')
4177  let buf = RunVimInTerminal('-S XNormalJBelowBotline', #{rows: 19, cols: 40})
4178
4179  call VerifyScreenDump(buf, 'Test_normal_j_below_botline', {})
4180
4181  call StopVimInTerminal(buf)
4182endfunc
4183
4184" Test for r (replace) command with CTRL_V and CTRL_Q
4185func Test_normal_r_ctrl_v_cmd()
4186  new
4187  call append(0, 'This is a simple test: abcd')
4188  exe "norm! 1gg$r\<C-V>\<C-V>"
4189  call assert_equal(['This is a simple test: abc', ''], getline(1,'$'))
4190  exe "norm! 1gg$hr\<C-Q>\<C-Q>"
4191  call assert_equal(['This is a simple test: ab', ''], getline(1,'$'))
4192  exe "norm! 1gg$2hr\<C-V>x7e"
4193  call assert_equal(['This is a simple test: a~', ''], getline(1,'$'))
4194  exe "norm! 1gg$3hr\<C-Q>x7e"
4195  call assert_equal(['This is a simple test: ~~', ''], getline(1,'$'))
4196
4197  if &encoding == 'utf-8'
4198    exe "norm! 1gg$4hr\<C-V>u20ac"
4199    call assert_equal(['This is a simple test:€~~', ''], getline(1,'$'))
4200    exe "norm! 1gg$5hr\<C-Q>u20ac"
4201    call assert_equal(['This is a simple test€€~~', ''], getline(1,'$'))
4202    exe "norm! 1gg0R\<C-V>xff WAS  \<esc>"
4203    call assert_equal(['ÿ WAS   a simple test€€~~', ''], getline(1,'$'))
4204    exe "norm! 1gg0elR\<C-Q>xffNOT\<esc>"
4205    call assert_equal(['ÿ WASÿNOT simple test€€~~', ''], getline(1,'$'))
4206  endif
4207
4208  call setline(1, 'This is a simple test: abcd')
4209  exe "norm! 1gg$gr\<C-V>\<C-V>"
4210  call assert_equal(['This is a simple test: abc', ''], getline(1,'$'))
4211  exe "norm! 1gg$hgr\<C-Q>\<C-Q>"
4212  call assert_equal(['This is a simple test: ab ', ''], getline(1,'$'))
4213  exe "norm! 1gg$2hgr\<C-V>x7e"
4214  call assert_equal(['This is a simple test: a~ ', ''], getline(1,'$'))
4215  exe "norm! 1gg$3hgr\<C-Q>x7e"
4216  call assert_equal(['This is a simple test: ~~ ', ''], getline(1,'$'))
4217
4218  " clean up
4219  bw!
4220endfunc
4221
4222" Test clicking on a TAB or an unprintable character in Normal mode
4223func Test_normal_click_on_ctrl_char()
4224  let save_mouse = &mouse
4225  set mouse=a
4226  new
4227
4228  call setline(1, "a\<Tab>b\<C-K>c")
4229  redraw
4230  call Ntest_setmouse(1, 1)
4231  call feedkeys("\<LeftMouse>", 'xt')
4232  call assert_equal([0, 1, 1, 0, 1], getcurpos())
4233  call Ntest_setmouse(1, 2)
4234  call feedkeys("\<LeftMouse>", 'xt')
4235  call assert_equal([0, 1, 2, 0, 2], getcurpos())
4236  call Ntest_setmouse(1, 3)
4237  call feedkeys("\<LeftMouse>", 'xt')
4238  call assert_equal([0, 1, 2, 0, 3], getcurpos())
4239  call Ntest_setmouse(1, 7)
4240  call feedkeys("\<LeftMouse>", 'xt')
4241  call assert_equal([0, 1, 2, 0, 7], getcurpos())
4242  call Ntest_setmouse(1, 8)
4243  call feedkeys("\<LeftMouse>", 'xt')
4244  call assert_equal([0, 1, 2, 0, 8], getcurpos())
4245  call Ntest_setmouse(1, 9)
4246  call feedkeys("\<LeftMouse>", 'xt')
4247  call assert_equal([0, 1, 3, 0, 9], getcurpos())
4248  call Ntest_setmouse(1, 10)
4249  call feedkeys("\<LeftMouse>", 'xt')
4250  call assert_equal([0, 1, 4, 0, 10], getcurpos())
4251  call Ntest_setmouse(1, 11)
4252  call feedkeys("\<LeftMouse>", 'xt')
4253  call assert_equal([0, 1, 4, 0, 11], getcurpos())
4254  call Ntest_setmouse(1, 12)
4255  call feedkeys("\<LeftMouse>", 'xt')
4256  call assert_equal([0, 1, 5, 0, 12], getcurpos())
4257  call Ntest_setmouse(1, 13)
4258  call feedkeys("\<LeftMouse>", 'xt')
4259  call assert_equal([0, 1, 5, 0, 13], getcurpos())
4260
4261  bwipe!
4262  let &mouse = save_mouse
4263endfunc
4264
4265" Test clicking on a double-width character in Normal mode
4266func Test_normal_click_on_double_width_char()
4267  let save_mouse = &mouse
4268  set mouse=a
4269  new
4270
4271  call setline(1, "口口")
4272  redraw
4273  call Ntest_setmouse(1, 1)
4274  call feedkeys("\<LeftMouse>", 'xt')
4275  call assert_equal([0, 1, 1, 0, 1], getcurpos())
4276  call Ntest_setmouse(1, 2)
4277  call feedkeys("\<LeftMouse>", 'xt')
4278  call assert_equal([0, 1, 1, 0, 2], getcurpos())
4279  call Ntest_setmouse(1, 3)
4280  call feedkeys("\<LeftMouse>", 'xt')
4281  call assert_equal([0, 1, 4, 0, 3], getcurpos())
4282  call Ntest_setmouse(1, 4)
4283  call feedkeys("\<LeftMouse>", 'xt')
4284  call assert_equal([0, 1, 4, 0, 4], getcurpos())
4285
4286  bwipe!
4287  let &mouse = save_mouse
4288endfunc
4289
4290func Test_normal_click_on_empty_line()
4291  let save_mouse = &mouse
4292  set mouse=a
4293  botright new
4294  call setline(1, ['', '', ''])
4295  let row = win_screenpos(0)[0] + 2
4296  20vsplit
4297  redraw
4298
4299  call Ntest_setmouse(row, 1)
4300  call feedkeys("\<LeftMouse>", 'xt')
4301  call assert_equal([0, 3, 1, 0, 1], getcurpos())
4302  call Ntest_setmouse(row, 2)
4303  call feedkeys("\<LeftMouse>", 'xt')
4304  call assert_equal([0, 3, 1, 0, 2], getcurpos())
4305  call Ntest_setmouse(row, 10)
4306  call feedkeys("\<LeftMouse>", 'xt')
4307  call assert_equal([0, 3, 1, 0, 10], getcurpos())
4308
4309  call Ntest_setmouse(row, 21 + 1)
4310  call feedkeys("\<LeftMouse>", 'xt')
4311  call assert_equal([0, 3, 1, 0, 1], getcurpos())
4312  call Ntest_setmouse(row, 21 + 2)
4313  call feedkeys("\<LeftMouse>", 'xt')
4314  call assert_equal([0, 3, 1, 0, 2], getcurpos())
4315  call Ntest_setmouse(row, 21 + 10)
4316  call feedkeys("\<LeftMouse>", 'xt')
4317  call assert_equal([0, 3, 1, 0, 10], getcurpos())
4318
4319  bwipe!
4320  let &mouse = save_mouse
4321endfunc
4322
4323func Test_normal33_g_cmd_nonblank()
4324  " Test that g<End> goes to the last non-blank char and g$ to the last
4325  " visible column
4326  20vnew
4327  setlocal nowrap nonumber signcolumn=no
4328  call setline(1, ['fooo   fooo         fooo   fooo         fooo   fooo         fooo   fooo        '])
4329  exe "normal 0g\<End>"
4330  call assert_equal(11, col('.'))
4331  normal 0g$
4332  call assert_equal(20, col('.'))
4333  exe "normal 0g\<kEnd>"
4334  call assert_equal(11, col('.'))
4335  setlocal wrap
4336  exe "normal 0g\<End>"
4337  call assert_equal(11, col('.'))
4338  normal 0g$
4339  call assert_equal(20, col('.'))
4340  exe "normal 0g\<kEnd>"
4341  call assert_equal(11, col('.'))
4342
4343  " Test visual mode at end of line
4344  normal 0$bvg$y
4345  call assert_equal(80, col("'>"))
4346  exe "normal 0$bvg\<End>y"
4347  call assert_equal(71, col("'>"))
4348  setlocal nowrap virtualedit=all
4349  exe "normal 0$\<C-v>llg\<End>y"
4350  call assert_equal(71, col("'<"))
4351  exe "normal 0$llvg\<End>y"
4352  call assert_equal(71, col("'<"))
4353  bw!
4354endfunc
4355
4356func Test_normal34_zet_large()
4357  " shouldn't cause overflow
4358  norm! z9765405999999999999
4359endfunc
4360
4361" Test for { and } paragraph movements in a single line
4362func Test_brace_single_line()
4363  new
4364  call setline(1, ['foobar one two three'])
4365  1
4366  norm! 0}
4367
4368  call assert_equal([0, 1, 20, 0], getpos('.'))
4369  norm! {
4370  call assert_equal([0, 1, 1, 0], getpos('.'))
4371  bw!
4372endfunc
4373
4374" Test for Ctrl-B/Ctrl-U in buffer with a single line
4375func Test_single_line_scroll()
4376  CheckFeature textprop
4377
4378  new
4379  call setline(1, ['foobar one two three'])
4380  let vt = 'virt_above'
4381  call prop_type_add(vt, {'highlight': 'IncSearch'})
4382  call prop_add(1, 0, {'type': vt, 'text': '---', 'text_align': 'above'})
4383  call cursor(1, 1)
4384
4385  " Ctrl-B/Ctrl-U scroll up with hidden "above" virtual text.
4386  set smoothscroll
4387  exe "normal \<C-E>"
4388  call assert_notequal(0, winsaveview().skipcol)
4389  exe "normal \<C-B>"
4390  call assert_equal(0, winsaveview().skipcol)
4391  exe "normal \<C-E>"
4392  call assert_notequal(0, winsaveview().skipcol)
4393  exe "normal \<C-U>"
4394  call assert_equal(0, winsaveview().skipcol)
4395
4396  set smoothscroll&
4397  bw!
4398  call prop_type_delete(vt)
4399endfunc
4400
4401" Test for zb in buffer with a single line and filler lines
4402func Test_single_line_filler_zb()
4403  call setline(1, ['', 'foobar one two three'])
4404  diffthis
4405  new
4406  call setline(1, ['foobar one two three'])
4407  diffthis
4408
4409  " zb scrolls to reveal filler lines at the start of the buffer.
4410  exe "normal \<C-E>zb"
4411  call assert_equal(1, winsaveview().topfill)
4412
4413  bw!
4414endfunc
4415
4416" Test for zb with fewer buffer lines than window height, non-zero 'scrolloff'
4417" and cursor on or just above a fold.
4418func Test_zb_with_cursor_on_or_just_above_fold()
4419  15new
4420  call setline(1, range(1, 5) + ['', 'foo{{{', 'bar}}}', '', 'baz'])
4421  setlocal foldmethod=marker scrolloff=1
4422  call assert_equal(8, foldclosedend(7))
4423
4424  call cursor(7, 1)
4425  normal! zb
4426  call assert_equal(1, line('w0'))
4427
4428  call cursor(6, 1)
4429  normal! zb
4430  call assert_equal(1, line('w0'))
4431
4432  bwipe!
4433endfunc
4434
4435" Test for Ctrl-U not getting stuck at end of buffer with 'scrolloff'.
4436func Test_halfpage_scrolloff_eob()
4437  set scrolloff=5
4438
4439  call setline(1, range(1, 100))
4440  exe "norm! Gzz\<C-U>zz"
4441  call assert_notequal(100, line('.'))
4442
4443  set scrolloff&
4444  bwipe!
4445endfunc
4446
4447" Test for Ctrl-U/D moving the cursor at the buffer boundaries.
4448func Test_halfpage_cursor_startend()
4449  call setline(1, range(1, 100))
4450  exe "norm! jztj\<C-U>"
4451  call assert_equal(1, line('.'))
4452  exe "norm! G\<C-Y>k\<C-D>"
4453  call assert_equal(100, line('.'))
4454  bwipe!
4455endfunc
4456
4457" Test for Ctrl-F/B moving the cursor to the window boundaries.
4458func Test_page_cursor_topbot()
4459  10new
4460  call setline(1, range(1, 100))
4461  exe "norm! gg2\<C-F>"
4462  call assert_equal(17, line('.'))
4463  exe "norm! \<C-B>"
4464  call assert_equal(18, line('.'))
4465  exe "norm! \<C-B>\<C-F>"
4466  call assert_equal(9, line('.'))
4467  " Not when already at the start of the buffer.
4468  exe "norm! ggj\<C-B>"
4469  call assert_equal(2, line('.'))
4470  bwipe!
4471endfunc
4472
4473" Test for Ctrl-D with long line
4474func Test_halfpage_longline()
4475  10new
4476  40vsplit
4477  call setline(1, ['long'->repeat(1000), 'short'])
4478  exe "norm! \<C-D>"
4479  call assert_equal(2, line('.'))
4480  bwipe!
4481endfunc
4482
4483" Test for Ctrl-E with long line and very narrow window,
4484" used to cause an infinite loop
4485func Test_scroll_longline_no_loop()
4486  4vnew
4487  setl smoothscroll number showbreak=> scrolloff=2
4488  call setline(1, repeat(['Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'], 3))
4489  exe "normal! \<C-E>"
4490  bwipe!
4491endfunc
4492
4493" Test for go command
4494func Test_normal_go()
4495  new
4496  call setline(1, ['one two three four'])
4497  call cursor(1, 5)
4498  norm! dvgo
4499  call assert_equal('wo three four', getline(1))
4500  norm! ...
4501  call assert_equal('three four', getline(1))
4502
4503  bwipe!
4504endfunc
4505
4506" Test for Ctrl-D with 'scrolloff' and narrow window does not get stuck.
4507func Test_scroll_longline_scrolloff()
4508  11new
4509  36vsplit
4510  set scrolloff=5
4511
4512  call setline(1, ['']->repeat(5))
4513  call setline(6, ['foo'->repeat(20)]->repeat(2))
4514  call setline(8, ['bar'->repeat(30)])
4515  call setline(9, ['']->repeat(5))
4516  exe "normal! \<C-D>"
4517  call assert_equal(6, line('w0'))
4518  exe "normal! \<C-D>"
4519  call assert_equal(7, line('w0'))
4520
4521  set scrolloff&
4522  bwipe!
4523endfunc
4524
4525" Benchmark test for Ctrl-F with 'nosmoothscroll'
4526func Test_scroll_longline_benchmark()
4527  call setline(1, ['foo'->repeat(20000)] + [''])
4528  let start = reltime()
4529  exe "normal! \<C-F>"
4530  call assert_inrange(0, 0.1, reltimefloat(reltime(start)))
4531  bwipe!
4532endfunc
4533
4534" Test Ctrl-B with 'nosmoothscroll' not stuck with line exactly window width.
4535func Test_scroll_longline_winwidth()
4536  10new
4537  call setline(1, ['']->repeat(20) + ['A'->repeat(20 * winwidth(0))] + ['']->repeat(20))
4538  exe "normal! G3\<C-B>"
4539  call assert_equal(22, line('w0'))
4540  exe "normal! \<C-B>"
4541  call assert_equal(21, line('w0'))
4542  exe "normal! \<C-B>"
4543  call assert_equal(11, line('w0'))
4544  exe "normal! \<C-B>"
4545  call assert_equal(3, line('w0'))
4546  exe "normal! \<C-B>"
4547  call assert_equal(1, line('w0'))
4548  bwipe!
4549endfunc
4550
4551func Test_pos_percentage_in_turkish_locale()
4552  CheckRunVimInTerminal
4553  CheckNotMac
4554  defer execute(':lang C')
4555  if !filereadable('../po/tr.mo')
4556        throw 'Skipped: tr.mo not built, run make in src/po first'
4557  endif
4558
4559  try
4560    let dir = expand('$VIMRUNTIME/lang/tr/')
4561    let target = expand('$VIMRUNTIME/lang/tr/LC_MESSAGES/')
4562    let tr = '../po/tr.mo'
4563    call mkdir(dir, 'R')
4564    call mkdir(target, '')
4565    call filecopy(tr, target .. 'vim.mo')
4566    lang tr_TR.UTF-8
4567    let buf = RunVimInTerminal('', {'rows': 5, 'cols': 40})
4568    call term_sendkeys(buf, ":lang tr_TR.UTF-8\<cr>")
4569    call term_sendkeys(buf, ":put =range(1,40)\<cr>")
4570    call term_sendkeys(buf, ":5\<cr>")
4571    call WaitForAssert({-> assert_match('%8$', term_getline(buf, 5))})
4572
4573    call StopVimInTerminal(buf)
4574  catch /E197:/
4575    " can't use Turkish locale
4576    throw 'Skipped: Turkish locale not available'
4577  endtry
4578endfunc
4579
4580" This test simulates the problem with gvim on Windows, observed when
4581" Test_normal11_showcmd in test_normal.vim is executed consecutively after
4582" Test_mouse_shape_after_failed_change.
4583"
4584" The problem occurred because WM_SETFOCUS was processed slowly, and typebuf
4585" was not empty when it should have been.
4586" TODO: Is this test flaky?
4587func Test_win32_gui_setfocus_prevent_showcmd()
4588  if !has('win32') || !has('gui_running')
4589    throw 'Skipped: Windows GUI regression test'
4590  endif
4591
4592  " WM_SETFOCUS event occurs when finish to execute filter command in gvim
4593  exe 'silent !echo foo'
4594
4595  set showcmd
4596  10new
4597  call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
4598  call feedkeys("ggl\<C-V>lljj", 'xt')
4599
4600  " showcmd could not be updated because events originating from WM_SETFOCUS
4601  " were stored in typebuf at here.  clear_showcmd() executed from redraw,
4602  " will not draw the selection information unless you are in visual mode and
4603  " typebuf is empty.
4604  redraw!
4605
4606  call assert_match('3x3$', Screenline(&lines))
4607  call feedkeys("\<C-V>", 'xt')
4608endfunc
4609
4610" vim: shiftwidth=2 sts=2 expandtab nofoldenable