xref: /vim-8.2.3635/src/testdir/test_visual.vim (revision 3a724290)
1" Tests for various Visual modes.
2
3source shared.vim
4source check.vim
5source screendump.vim
6
7func Test_block_shift_multibyte()
8  " Uses double-wide character.
9  split
10  call setline(1, ['xヹxxx', 'ヹxxx'])
11  exe "normal 1G0l\<C-V>jl>"
12  call assert_equal('x	 ヹxxx', getline(1))
13  call assert_equal('	ヹxxx', getline(2))
14  q!
15endfunc
16
17func Test_block_shift_overflow()
18  " This used to cause a multiplication overflow followed by a crash.
19  new
20  normal ii
21  exe "normal \<C-V>876543210>"
22  q!
23endfunc
24
25func Test_dotregister_paste()
26  new
27  exe "norm! ihello world\<esc>"
28  norm! 0ve".p
29  call assert_equal('hello world world', getline(1))
30  q!
31endfunc
32
33func Test_Visual_ctrl_o()
34  new
35  call setline(1, ['one', 'two', 'three'])
36  call cursor(1,2)
37  set noshowmode
38  set tw=0
39  call feedkeys("\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>", 'tx')
40  call assert_equal(['oane', 'tawo', 'tahree'], getline(1, 3))
41  call assert_equal(88, &tw)
42  set tw&
43  bw!
44endfu
45
46func Test_Visual_vapo()
47  new
48  normal oxx
49  normal vapo
50  bwipe!
51endfunc
52
53func Test_Visual_inner_quote()
54  new
55  normal oxX
56  normal vki'
57  bwipe!
58endfunc
59
60" Test for Visual mode not being reset causing E315 error.
61func TriggerTheProblem()
62  " At this point there is no visual selection because :call reset it.
63  " Let's restore the selection:
64  normal gv
65  '<,'>del _
66  try
67      exe "normal \<Esc>"
68  catch /^Vim\%((\a\+)\)\=:E315/
69      echom 'Snap! E315 error!'
70      let g:msg = 'Snap! E315 error!'
71  endtry
72endfunc
73
74func Test_visual_mode_reset()
75  enew
76  let g:msg = "Everything's fine."
77  enew
78  setl buftype=nofile
79  call append(line('$'), 'Delete this line.')
80
81  " NOTE: this has to be done by a call to a function because executing :del
82  " the ex-way will require the colon operator which resets the visual mode
83  " thus preventing the problem:
84  exe "normal! GV:call TriggerTheProblem()\<CR>"
85  call assert_equal("Everything's fine.", g:msg)
86endfunc
87
88" Test for visual block shift and tab characters.
89func Test_block_shift_tab()
90  new
91  call append(0, repeat(['one two three'], 5))
92  call cursor(1,1)
93  exe "normal i\<C-G>u"
94  exe "normal fe\<C-V>4jR\<Esc>ugvr1"
95  call assert_equal('on1 two three', getline(1))
96  call assert_equal('on1 two three', getline(2))
97  call assert_equal('on1 two three', getline(5))
98
99  %d _
100  call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5))
101  call cursor(1,1)
102  exe "normal \<C-V>4jI    \<Esc>j<<11|D"
103  exe "normal j7|a\<Tab>\<Tab>"
104  exe "normal j7|a\<Tab>\<Tab>   "
105  exe "normal j7|a\<Tab>       \<Tab>\<Esc>4k13|\<C-V>4j<"
106  call assert_equal('    abcdefghijklmnopqrstuvwxyz', getline(1))
107  call assert_equal('abcdefghij', getline(2))
108  call assert_equal("    abc\<Tab>    defghijklmnopqrstuvwxyz", getline(3))
109  call assert_equal("    abc\<Tab>    defghijklmnopqrstuvwxyz", getline(4))
110  call assert_equal("    abc\<Tab>    defghijklmnopqrstuvwxyz", getline(5))
111
112  %s/\s\+//g
113  call cursor(1,1)
114  exe "normal \<C-V>4jI    \<Esc>j<<"
115  exe "normal j7|a\<Tab>\<Tab>"
116  exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>"
117  exe "normal j7|a\<Tab>       \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<"
118  call assert_equal('    abcdefghijklmnopqrstuvwxyz', getline(1))
119  call assert_equal('abcdefghij', getline(2))
120  call assert_equal("    abc\<Tab>    defghijklmnopqrstuvwxyz", getline(3))
121  call assert_equal("    abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4))
122  call assert_equal("    abc\<Tab>    defghijklmnopqrstuvwxyz", getline(5))
123
124  " Test for block shift with space characters at the beginning and with
125  " 'noexpandtab' and 'expandtab'
126  %d _
127  call setline(1, ["      1", "      2", "      3"])
128  setlocal shiftwidth=2 noexpandtab
129  exe "normal gg\<C-V>3j>"
130  call assert_equal(["\t1", "\t2", "\t3"], getline(1, '$'))
131  %d _
132  call setline(1, ["      1", "      2", "      3"])
133  setlocal shiftwidth=2 expandtab
134  exe "normal gg\<C-V>3j>"
135  call assert_equal(["        1", "        2", "        3"], getline(1, '$'))
136  setlocal shiftwidth&
137
138  bw!
139endfunc
140
141" Tests Blockwise Visual when there are TABs before the text.
142func Test_blockwise_visual()
143  new
144  call append(0, ['123456',
145	      \ '234567',
146	      \ '345678',
147	      \ '',
148	      \ 'test text test tex start here',
149	      \ "\t\tsome text",
150	      \ "\t\ttest text",
151	      \ 'test text'])
152  call cursor(1,1)
153  exe "normal /start here$\<CR>"
154  exe 'normal "by$' . "\<C-V>jjlld"
155  exe "normal /456$\<CR>"
156  exe "normal \<C-V>jj" . '"bP'
157  call assert_equal(['123start here56',
158	      \ '234start here67',
159	      \ '345start here78',
160	      \ '',
161	      \ 'test text test tex rt here',
162	      \ "\t\tsomext",
163	      \ "\t\ttesext"], getline(1, 7))
164
165  bw!
166endfunc
167
168" Test swapping corners in blockwise visual mode with o and O
169func Test_blockwise_visual_o_O()
170  new
171
172  exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr "
173  exe "norm! gvO\<Esc>ra"
174  exe "norm! gvO\<Esc>rb"
175  exe "norm! gvo\<C-c>rc"
176  exe "norm! gvO\<C-c>rd"
177  set selection=exclusive
178  exe "norm! gvOo\<C-c>re"
179  call assert_equal('...a   be.', getline(4))
180  exe "norm! gvOO\<C-c>rf"
181  set selection&
182
183  call assert_equal(['..........',
184        \            '...c   d..',
185        \            '...     ..',
186        \            '...a   bf.',
187        \            '..........'], getline(1, '$'))
188
189  bw!
190endfun
191
192" Test Virtual replace mode.
193func Test_virtual_replace()
194  if exists('&t_kD')
195    let save_t_kD = &t_kD
196  endif
197  if exists('&t_kb')
198    let save_t_kb = &t_kb
199  endif
200  exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08"
201  enew!
202  exe "normal a\nabcdefghi\njk\tlmn\n    opq	rst\n\<C-D>uvwxyz"
203  call cursor(1,1)
204  set ai bs=2
205  exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR"
206  call assert_equal([' 1',
207	      \ ' A',
208	      \ ' BCDEFGHIJ',
209	      \ ' 	KL',
210	      \ '	MNO',
211	      \ '	PQR',
212	      \ ], getline(1, 6))
213  normal G
214  mark a
215  exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n    opq\trst\n\<C-D>uvwxyz\n"
216  exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29)
217  call assert_equal([' 1',
218	      \ 'abcdefghi',
219	      \ 'jk	lmn',
220	      \ '    opq	rst',
221	      \ 'uvwxyz'], getline(7, 11))
222  normal G
223  exe "normal iab\tcdefghi\tjkl"
224  exe "normal 0gRAB......CDEFGHI.J\<Esc>o"
225  exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR"
226  call assert_equal(['AB......CDEFGHI.Jkl',
227	      \ 'AB	IJKLMNO	QRst'], getline(12, 13))
228
229  " Test inserting Tab with 'noexpandtab' and 'softabstop' set to 4
230  %d
231  call setline(1, 'aaaaaaaaaaaaa')
232  set softtabstop=4
233  exe "normal gggR\<Tab>\<Tab>x"
234  call assert_equal("\txaaaa", getline(1))
235  set softtabstop&
236
237  enew!
238  set noai bs&vim
239  if exists('save_t_kD')
240    let &t_kD = save_t_kD
241  endif
242  if exists('save_t_kb')
243    let &t_kb = save_t_kb
244  endif
245endfunc
246
247" Test Virtual replace mode.
248func Test_virtual_replace2()
249  enew!
250  set bs=2
251  exe "normal a\nabcdefghi\njk\tlmn\n    opq	rst\n\<C-D>uvwxyz"
252  call cursor(1,1)
253  " Test 1: Test that del deletes the newline
254  exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR"
255  call assert_equal(['0 1',
256	      \ 'A',
257	      \ 'BCDEFGHIJ',
258	      \ '	KL',
259	      \ 'MNO',
260	      \ 'PQR',
261	      \ ], getline(1, 6))
262  " Test 2:
263  " a newline is not deleted, if no newline has been added in virtual replace mode
264  %d_
265  call setline(1, ['abcd', 'efgh', 'ijkl'])
266  call cursor(2,1)
267  exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>"
268  call assert_equal(['abcd',
269        \ '123h',
270        \ 'ijkl'], getline(1, '$'))
271  " Test 3:
272  " a newline is deleted, if a newline has been inserted before in virtual replace mode
273  %d_
274  call setline(1, ['abcd', 'efgh', 'ijkl'])
275  call cursor(2,1)
276  exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>"
277  call assert_equal(['abcd',
278        \ '1234',
279        \ 'ijkl'], getline(1, '$'))
280  " Test 4:
281  " delete add a newline, delete it, add it again and check undo
282  %d_
283  call setline(1, ['abcd', 'efgh', 'ijkl'])
284  call cursor(2,1)
285  " break undo sequence explicitly
286  let &ul = &ul
287  exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>"
288  let &ul = &ul
289  call assert_equal(['abcd',
290        \ '123456',
291        \ ''], getline(1, '$'))
292  norm! u
293  call assert_equal(['abcd',
294        \ 'efgh',
295        \ 'ijkl'], getline(1, '$'))
296
297  " Test for truncating spaces in a newly added line using 'autoindent' if
298  " characters are not added to that line.
299  %d_
300  call setline(1, ['    app', '    bee', '    cat'])
301  setlocal autoindent
302  exe "normal gg$gRt\n\nr"
303  call assert_equal(['    apt', '', '    rat'], getline(1, '$'))
304
305  " clean up
306  %d_
307  set bs&vim
308endfunc
309
310func Test_Visual_word_textobject()
311  new
312  call setline(1, ['First sentence. Second sentence.'])
313
314  " When start and end of visual area are identical, 'aw' or 'iw' select
315  " the whole word.
316  norm! 1go2fcvawy
317  call assert_equal('Second ', @")
318  norm! 1go2fcviwy
319  call assert_equal('Second', @")
320
321  " When start and end of visual area are not identical, 'aw' or 'iw'
322  " extend the word in direction of the end of the visual area.
323  norm! 1go2fcvlawy
324  call assert_equal('cond ', @")
325  norm! gv2awy
326  call assert_equal('cond sentence.', @")
327
328  norm! 1go2fcvliwy
329  call assert_equal('cond', @")
330  norm! gv2iwy
331  call assert_equal('cond sentence', @")
332
333  " Extend visual area in opposite direction.
334  norm! 1go2fcvhawy
335  call assert_equal(' Sec', @")
336  norm! gv2awy
337  call assert_equal(' sentence. Sec', @")
338
339  norm! 1go2fcvhiwy
340  call assert_equal('Sec', @")
341  norm! gv2iwy
342  call assert_equal('. Sec', @")
343
344  bwipe!
345endfunc
346
347func Test_Visual_sentence_textobject()
348  new
349  call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence'])
350
351  " When start and end of visual area are identical, 'as' or 'is' select
352  " the whole sentence.
353  norm! 1gofdvasy
354  call assert_equal('Second sentence. ', @")
355  norm! 1gofdvisy
356  call assert_equal('Second sentence.', @")
357
358  " When start and end of visual area are not identical, 'as' or 'is'
359  " extend the sentence in direction of the end of the visual area.
360  norm! 1gofdvlasy
361  call assert_equal('d sentence. ', @")
362  norm! gvasy
363  call assert_equal("d sentence. Third\nsentence. ", @")
364
365  norm! 1gofdvlisy
366  call assert_equal('d sentence.', @")
367  norm! gvisy
368  call assert_equal('d sentence. ', @")
369  norm! gvisy
370  call assert_equal("d sentence. Third\nsentence.", @")
371
372  " Extend visual area in opposite direction.
373  norm! 1gofdvhasy
374  call assert_equal(' Second', @")
375  norm! gvasy
376  call assert_equal("First sentence. Second", @")
377
378  norm! 1gofdvhisy
379  call assert_equal('Second', @")
380  norm! gvisy
381  call assert_equal(' Second', @")
382  norm! gvisy
383  call assert_equal('First sentence. Second', @")
384
385  bwipe!
386endfunc
387
388func Test_Visual_paragraph_textobject()
389  new
390  let lines =<< trim [END]
391    First line.
392
393    Second line.
394    Third line.
395    Fourth line.
396    Fifth line.
397
398    Sixth line.
399  [END]
400  call setline(1, lines)
401
402  " When start and end of visual area are identical, 'ap' or 'ip' select
403  " the whole paragraph.
404  norm! 4ggvapy
405  call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @")
406  norm! 4ggvipy
407  call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @")
408
409  " When start and end of visual area are not identical, 'ap' or 'ip'
410  " extend the sentence in direction of the end of the visual area.
411  " FIXME: actually, it is not sufficient to have different start and
412  " end of visual selection, the start line and end line have to differ,
413  " which is not consistent with the documentation.
414  norm! 4ggVjapy
415  call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @")
416  norm! gvapy
417  call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @")
418  norm! 4ggVjipy
419  call assert_equal("Third line.\nFourth line.\nFifth line.\n", @")
420  norm! gvipy
421  call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @")
422  norm! gvipy
423  call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @")
424
425  " Extend visual area in opposite direction.
426  norm! 5ggVkapy
427  call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @")
428  norm! gvapy
429  call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @")
430  norm! 5ggVkipy
431  call assert_equal("Second line.\nThird line.\nFourth line.\n", @")
432  norma gvipy
433  call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @")
434  norm! gvipy
435  call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @")
436
437  bwipe!
438endfunc
439
440func Test_curswant_not_changed()
441  new
442  call setline(1, ['one', 'two'])
443  au InsertLeave * call getcurpos()
444  call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt')
445  call assert_equal([0, 2, 1, 0, 1], getcurpos())
446
447  bwipe!
448  au! InsertLeave
449endfunc
450
451" Tests for "vaBiB", end could be wrong.
452func Test_Visual_Block()
453  new
454  a
455- Bug in "vPPPP" on this text:
456	{
457		cmd;
458		{
459			cmd;\t/* <-- Start cursor here */
460			{
461			}
462		}
463	}
464.
465  normal gg
466  call search('Start cursor here')
467  normal vaBiBD
468  call assert_equal(['- Bug in "vPPPP" on this text:',
469	      \ "\t{",
470	      \ "\t}"], getline(1, '$'))
471
472  close!
473endfunc
474
475" Test for 'p'ut in visual block mode
476func Test_visual_block_put()
477  new
478  call append(0, ['One', 'Two', 'Three'])
479  normal gg
480  yank
481  call feedkeys("jl\<C-V>ljp", 'xt')
482  call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$'))
483  bw!
484endfunc
485
486" Visual modes (v V CTRL-V) followed by an operator; count; repeating
487func Test_visual_mode_op()
488  new
489  call append(0, '')
490
491  call setline(1, 'apple banana cherry')
492  call cursor(1, 1)
493  normal lvld.l3vd.
494  call assert_equal('a y', getline(1))
495
496  call setline(1, ['line 1 line 1', 'line 2 line 2', 'line 3 line 3',
497        \ 'line 4 line 4', 'line 5 line 5', 'line 6 line 6'])
498  call cursor(1, 1)
499  exe "normal Vcnewline\<Esc>j.j2Vd."
500  call assert_equal(['newline', 'newline'], getline(1, '$'))
501
502  call deletebufline('', 1, '$')
503  call setline(1, ['xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxx',
504        \ 'xxxxxxxxxxxxx'])
505  exe "normal \<C-V>jlc  \<Esc>l.l2\<C-V>c----\<Esc>l."
506  call assert_equal(['    --------x',
507        \ '    --------x',
508        \ 'xxxx--------x',
509        \ 'xxxx--------x'], getline(1, '$'))
510
511  bwipe!
512endfunc
513
514" Visual mode maps (movement and text object)
515" Visual mode maps; count; repeating
516"   - Simple
517"   - With an Ex command (custom text object)
518func Test_visual_mode_maps()
519  new
520  call append(0, '')
521
522  func SelectInCaps()
523    let [line1, col1] = searchpos('\u', 'bcnW')
524    let [line2, col2] = searchpos('.\u', 'nW')
525    call setpos("'<", [0, line1, col1, 0])
526    call setpos("'>", [0, line2, col2, 0])
527    normal! gv
528  endfunction
529
530  vnoremap W /\u/s-1<CR>
531  vnoremap iW :<C-U>call SelectInCaps()<CR>
532
533  call setline(1, 'KiwiRaspberryDateWatermelonPeach')
534  call cursor(1, 1)
535  exe "normal vWcNo\<Esc>l.fD2vd."
536  call assert_equal('NoNoberryach', getline(1))
537
538  call setline(1, 'JambuRambutanBananaTangerineMango')
539  call cursor(1, 1)
540  exe "normal llviWc-\<Esc>l.l2vdl."
541  call assert_equal('--ago', getline(1))
542
543  vunmap W
544  vunmap iW
545  bwipe!
546  delfunc SelectInCaps
547endfunc
548
549" Operator-pending mode maps (movement and text object)
550"   - Simple
551"   - With Ex command moving the cursor
552"   - With Ex command and Visual selection (custom text object)
553func Test_visual_oper_pending_mode_maps()
554  new
555  call append(0, '')
556
557  func MoveToCap()
558    call search('\u', 'W')
559  endfunction
560
561  func SelectInCaps()
562    let [line1, col1] = searchpos('\u', 'bcnW')
563    let [line2, col2] = searchpos('.\u', 'nW')
564    call setpos("'<", [0, line1, col1, 0])
565    call setpos("'>", [0, line2, col2, 0])
566    normal! gv
567  endfunction
568
569  onoremap W /\u/<CR>
570  onoremap <Leader>W :<C-U>call MoveToCap()<CR>
571  onoremap iW :<C-U>call SelectInCaps()<CR>
572
573  call setline(1, 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ')
574  call cursor(1, 1)
575  exe "normal cW-\<Esc>l.l2.l."
576  call assert_equal('----Z', getline(1))
577
578  call setline(1, 'JuniperDurianZ')
579  call cursor(1, 1)
580  exe "normal g?\WfD."
581  call assert_equal('WhavcreQhevnaZ', getline(1))
582
583  call setline(1, 'LemonNectarineZ')
584  call cursor(1, 1)
585  exe "normal yiWPlciWNew\<Esc>fr."
586  call assert_equal('LemonNewNewZ', getline(1))
587
588  ounmap W
589  ounmap <Leader>W
590  ounmap iW
591  bwipe!
592  delfunc MoveToCap
593  delfunc SelectInCaps
594endfunc
595
596" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc.
597func Test_op_pend_mode_abort()
598  new
599  call append(0, '')
600
601  call setline(1, ['zzzz', 'zzzz'])
602  call cursor(1, 1)
603
604  exe "normal dV:\<CR>dv:\<CR>"
605  call assert_equal(['zzz'], getline(1, 2))
606  set nomodifiable
607  call assert_fails('exe "normal d:\<CR>"', 'E21:')
608  set modifiable
609  call feedkeys("dv:\<Esc>dV:\<Esc>", 'xt')
610  call assert_equal(['zzz'], getline(1, 2))
611  set nomodifiable
612  let v:errmsg = ''
613  call feedkeys("d:\<Esc>", 'xt')
614  call assert_true(v:errmsg !~# '^E21:')
615  set modifiable
616
617  bwipe!
618endfunc
619
620func Test_characterwise_visual_mode()
621  new
622
623  " characterwise visual mode: replace last line
624  $put ='a'
625  let @" = 'x'
626  normal v$p
627  call assert_equal('x', getline('$'))
628
629  " characterwise visual mode: delete middle line
630  call deletebufline('', 1, '$')
631  call append('$', ['a', 'b', 'c'])
632  normal G
633  normal kkv$d
634  call assert_equal(['', 'b', 'c'], getline(1, '$'))
635
636  " characterwise visual mode: delete middle two lines
637  call deletebufline('', 1, '$')
638  call append('$', ['a', 'b', 'c'])
639  normal Gkkvj$d
640  call assert_equal(['', 'c'], getline(1, '$'))
641
642  " characterwise visual mode: delete last line
643  call deletebufline('', 1, '$')
644  call append('$', ['a', 'b', 'c'])
645  normal Gv$d
646  call assert_equal(['', 'a', 'b', ''], getline(1, '$'))
647
648  " characterwise visual mode: delete last two lines
649  call deletebufline('', 1, '$')
650  call append('$', ['a', 'b', 'c'])
651  normal Gkvj$d
652  call assert_equal(['', 'a', ''], getline(1, '$'))
653
654  " characterwise visual mode: use a count with the visual mode from the last
655  " line in the buffer
656  %d _
657  call setline(1, ['one', 'two', 'three', 'four'])
658  norm! vj$y
659  norm! G1vy
660  call assert_equal('four', @")
661
662  " characterwise visual mode: replace a single character line and the eol
663  %d _
664  call setline(1, "a")
665  normal v$rx
666  call assert_equal(['x'], getline(1, '$'))
667
668  bwipe!
669endfunc
670
671func Test_visual_mode_put()
672  new
673
674  " v_p: replace last character with line register at middle line
675  call append('$', ['aaa', 'bbb', 'ccc'])
676  normal G
677  -2yank
678  normal k$vp
679  call assert_equal(['', 'aaa', 'bb', 'aaa', '', 'ccc'], getline(1, '$'))
680
681  " v_p: replace last character with line register at middle line selecting
682  " newline
683  call deletebufline('', 1, '$')
684  call append('$', ['aaa', 'bbb', 'ccc'])
685  normal G
686  -2yank
687  normal k$v$p
688  call assert_equal(['', 'aaa', 'bb', 'aaa', 'ccc'], getline(1, '$'))
689
690  " v_p: replace last character with line register at last line
691  call deletebufline('', 1, '$')
692  call append('$', ['aaa', 'bbb', 'ccc'])
693  normal G
694  -2yank
695  normal $vp
696  call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$'))
697
698  " v_p: replace last character with line register at last line selecting
699  " newline
700  call deletebufline('', 1, '$')
701  call append('$', ['aaa', 'bbb', 'ccc'])
702  normal G
703  -2yank
704  normal $v$p
705  call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$'))
706
707  bwipe!
708endfunc
709
710func Test_gv_with_exclusive_selection()
711  new
712
713  " gv with exclusive selection after an operation
714  call append('$', ['zzz ', 'äà '])
715  set selection=exclusive
716  normal Gkv3lyjv3lpgvcxxx
717  call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$'))
718
719  " gv with exclusive selection without an operation
720  call deletebufline('', 1, '$')
721  call append('$', 'zzz ')
722  set selection=exclusive
723  exe "normal G0v3l\<Esc>gvcxxx"
724  call assert_equal(['', 'xxx '], getline(1, '$'))
725
726  set selection&vim
727  bwipe!
728endfunc
729
730" Tests for the visual block mode commands
731func Test_visual_block_mode()
732  new
733  call append(0, '')
734  call setline(1, repeat(['abcdefghijklm'], 5))
735  call cursor(1, 1)
736
737  " Test shift-right of a block
738  exe "normal jllll\<C-V>jj>wll\<C-V>jlll>"
739  " Test shift-left of a block
740  exe "normal G$hhhh\<C-V>kk<"
741  " Test block-insert
742  exe "normal Gkl\<C-V>kkkIxyz"
743  " Test block-replace
744  exe "normal Gllll\<C-V>kkklllrq"
745  " Test block-change
746  exe "normal G$khhh\<C-V>hhkkcmno"
747  call assert_equal(['axyzbcdefghijklm',
748        \ 'axyzqqqq   mno	      ghijklm',
749        \ 'axyzqqqqef mno        ghijklm',
750        \ 'axyzqqqqefgmnoklm',
751        \ 'abcdqqqqijklm'], getline(1, 5))
752
753  " Test 'C' to change till the end of the line
754  call cursor(3, 4)
755  exe "normal! \<C-V>j3lCooo"
756  call assert_equal(['axyooo', 'axyooo'], getline(3, 4))
757
758  " Test 'D' to delete till the end of the line
759  call cursor(3, 3)
760  exe "normal! \<C-V>j2lD"
761  call assert_equal(['ax', 'ax'], getline(3, 4))
762
763  " Test block insert with a short line that ends before the block
764  %d _
765  call setline(1, ["  one", "a", "  two"])
766  exe "normal gg\<C-V>2jIx"
767  call assert_equal(["  xone", "a", "  xtwo"], getline(1, '$'))
768
769  " Test block append at EOL with '$' and without '$'
770  %d _
771  call setline(1, ["one", "a", "two"])
772  exe "normal gg$\<C-V>2jAx"
773  call assert_equal(["onex", "ax", "twox"], getline(1, '$'))
774  %d _
775  call setline(1, ["one", "a", "two"])
776  exe "normal gg3l\<C-V>2jAx"
777  call assert_equal(["onex", "a  x", "twox"], getline(1, '$'))
778
779  " Test block replace with an empty line in the middle and use $ to jump to
780  " the end of the line.
781  %d _
782  call setline(1, ['one', '', 'two'])
783  exe "normal gg$\<C-V>2jrx"
784  call assert_equal(["onx", "", "twx"], getline(1, '$'))
785
786  " Test block replace with an empty line in the middle and move cursor to the
787  " end of the line
788  %d _
789  call setline(1, ['one', '', 'two'])
790  exe "normal gg2l\<C-V>2jrx"
791  call assert_equal(["onx", "", "twx"], getline(1, '$'))
792
793  " Replace odd number of characters with a multibyte character
794  %d _
795  call setline(1, ['abcd', 'efgh'])
796  exe "normal ggl\<C-V>2ljr\u1100"
797  call assert_equal(["a\u1100 ", "e\u1100 "], getline(1, '$'))
798
799  " During visual block append, if the cursor moved outside of the selected
800  " range, then the edit should not be applied to the block.
801  %d _
802  call setline(1, ['aaa', 'bbb', 'ccc'])
803  exe "normal 2G\<C-V>jAx\<Up>"
804  call assert_equal(['aaa', 'bxbb', 'ccc'], getline(1, '$'))
805
806  " During visual block append, if the cursor is moved before the start of the
807  " block, then the new text should be appended there.
808  %d _
809  call setline(1, ['aaa', 'bbb', 'ccc'])
810  exe "normal $\<C-V>2jA\<Left>x"
811  call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
812  " Repeat the previous test but use 'l' to move the cursor instead of '$'
813  call setline(1, ['aaa', 'bbb', 'ccc'])
814  exe "normal! gg2l\<C-V>2jA\<Left>x"
815  call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
816
817  " Change a characterwise motion to a blockwise motion using CTRL-V
818  %d _
819  call setline(1, ['123', '456', '789'])
820  exe "normal ld\<C-V>j"
821  call assert_equal(['13', '46', '789'], getline(1, '$'))
822
823  " Test from ':help v_b_I_example'
824  %d _
825  setlocal tabstop=8 shiftwidth=4
826  let lines =<< trim END
827    abcdefghijklmnopqrstuvwxyz
828    abc		defghijklmnopqrstuvwxyz
829    abcdef  ghi		jklmnopqrstuvwxyz
830    abcdefghijklmnopqrstuvwxyz
831  END
832  call setline(1, lines)
833  exe "normal ggfo\<C-V>3jISTRING"
834  let expected =<< trim END
835    abcdefghijklmnSTRINGopqrstuvwxyz
836    abc	      STRING  defghijklmnopqrstuvwxyz
837    abcdef  ghi   STRING  	jklmnopqrstuvwxyz
838    abcdefghijklmnSTRINGopqrstuvwxyz
839  END
840  call assert_equal(expected, getline(1, '$'))
841
842  " Test from ':help v_b_A_example'
843  %d _
844  let lines =<< trim END
845    abcdefghijklmnopqrstuvwxyz
846    abc		defghijklmnopqrstuvwxyz
847    abcdef  ghi		jklmnopqrstuvwxyz
848    abcdefghijklmnopqrstuvwxyz
849  END
850  call setline(1, lines)
851  exe "normal ggfo\<C-V>3j$ASTRING"
852  let expected =<< trim END
853    abcdefghijklmnopqrstuvwxyzSTRING
854    abc		defghijklmnopqrstuvwxyzSTRING
855    abcdef  ghi		jklmnopqrstuvwxyzSTRING
856    abcdefghijklmnopqrstuvwxyzSTRING
857  END
858  call assert_equal(expected, getline(1, '$'))
859
860  " Test from ':help v_b_<_example'
861  %d _
862  let lines =<< trim END
863    abcdefghijklmnopqrstuvwxyz
864    abc		defghijklmnopqrstuvwxyz
865    abcdef  ghi		jklmnopqrstuvwxyz
866    abcdefghijklmnopqrstuvwxyz
867  END
868  call setline(1, lines)
869  exe "normal ggfo\<C-V>3j3l<.."
870  let expected =<< trim END
871    abcdefghijklmnopqrstuvwxyz
872    abc	      defghijklmnopqrstuvwxyz
873    abcdef  ghi   jklmnopqrstuvwxyz
874    abcdefghijklmnopqrstuvwxyz
875  END
876  call assert_equal(expected, getline(1, '$'))
877
878  " Test from ':help v_b_>_example'
879  %d _
880  let lines =<< trim END
881    abcdefghijklmnopqrstuvwxyz
882    abc		defghijklmnopqrstuvwxyz
883    abcdef  ghi		jklmnopqrstuvwxyz
884    abcdefghijklmnopqrstuvwxyz
885  END
886  call setline(1, lines)
887  exe "normal ggfo\<C-V>3j>.."
888  let expected =<< trim END
889    abcdefghijklmn		  opqrstuvwxyz
890    abc			    defghijklmnopqrstuvwxyz
891    abcdef  ghi			    jklmnopqrstuvwxyz
892    abcdefghijklmn		  opqrstuvwxyz
893  END
894  call assert_equal(expected, getline(1, '$'))
895
896  " Test from ':help v_b_r_example'
897  %d _
898  let lines =<< trim END
899    abcdefghijklmnopqrstuvwxyz
900    abc		defghijklmnopqrstuvwxyz
901    abcdef  ghi		jklmnopqrstuvwxyz
902    abcdefghijklmnopqrstuvwxyz
903  END
904  call setline(1, lines)
905  exe "normal ggfo\<C-V>5l3jrX"
906  let expected =<< trim END
907    abcdefghijklmnXXXXXXuvwxyz
908    abc	      XXXXXXhijklmnopqrstuvwxyz
909    abcdef  ghi   XXXXXX    jklmnopqrstuvwxyz
910    abcdefghijklmnXXXXXXuvwxyz
911  END
912  call assert_equal(expected, getline(1, '$'))
913
914  bwipe!
915  set tabstop& shiftwidth&
916endfunc
917
918func Test_visual_force_motion_feedkeys()
919    onoremap <expr> i- execute('let g:mode = mode(1)')->slice(0, 0)
920    call feedkeys('dvi-', 'x')
921    call assert_equal('nov', g:mode)
922    call feedkeys('di-', 'x')
923    call assert_equal('no', g:mode)
924    ounmap i-
925endfunc
926
927" Test block-insert using cursor keys for movement
928func Test_visual_block_insert_cursor_keys()
929  new
930  call append(0, ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd'])
931  call cursor(1, 1)
932
933  exe "norm! l\<C-V>jjjlllI\<Right>\<Right>  \<Esc>"
934  call assert_equal(['aaa  aaa', 'bbb  bbb', 'ccc  ccc', 'ddd  ddd'],
935        \ getline(1, 4))
936
937  call deletebufline('', 1, '$')
938  call setline(1, ['xaaa', 'bbbb', 'cccc', 'dddd'])
939  call cursor(1, 1)
940  exe "norm! \<C-V>jjjI<>\<Left>p\<Esc>"
941  call assert_equal(['<p>xaaa', '<p>bbbb', '<p>cccc', '<p>dddd'],
942        \ getline(1, 4))
943  bwipe!
944endfunc
945
946func Test_visual_block_create()
947  new
948  call append(0, '')
949  " Test for Visual block was created with the last <C-v>$
950  call setline(1, ['A23', '4567'])
951  call cursor(1, 1)
952  exe "norm! l\<C-V>j$Aab\<Esc>"
953  call assert_equal(['A23ab', '4567ab'], getline(1, 2))
954
955  " Test for Visual block was created with the middle <C-v>$ (1)
956  call deletebufline('', 1, '$')
957  call setline(1, ['B23', '4567'])
958  call cursor(1, 1)
959  exe "norm! l\<C-V>j$hAab\<Esc>"
960  call assert_equal(['B23 ab', '4567ab'], getline(1, 2))
961
962  " Test for Visual block was created with the middle <C-v>$ (2)
963  call deletebufline('', 1, '$')
964  call setline(1, ['C23', '4567'])
965  call cursor(1, 1)
966  exe "norm! l\<C-V>j$hhAab\<Esc>"
967  call assert_equal(['C23ab', '456ab7'], getline(1, 2))
968  bwipe!
969endfunc
970
971" Test for Visual block insert when virtualedit=all
972func Test_virtualedit_visual_block()
973  set ve=all
974  new
975  call append(0, ["\t\tline1", "\t\tline2", "\t\tline3"])
976  call cursor(1, 1)
977  exe "norm! 07l\<C-V>jjIx\<Esc>"
978  call assert_equal(["       x \tline1",
979        \ "       x \tline2",
980        \ "       x \tline3"], getline(1, 3))
981
982  " Test for Visual block append when virtualedit=all
983  exe "norm! 012l\<C-v>jjAx\<Esc>"
984  call assert_equal(['       x     x   line1',
985        \ '       x     x   line2',
986        \ '       x     x   line3'], getline(1, 3))
987  set ve=
988  bwipe!
989endfunc
990
991" Test for changing case
992func Test_visual_change_case()
993  new
994  " gUe must uppercase a whole word, also when ß changes to SS
995  exe "normal Gothe youtußeuu end\<Esc>Ypk0wgUe\r"
996  " gUfx must uppercase until x, inclusive.
997  exe "normal O- youßtußexu -\<Esc>0fogUfx\r"
998  " VU must uppercase a whole line
999  exe "normal YpkVU\r"
1000  " same, when it's the last line in the buffer
1001  exe "normal YPGi111\<Esc>VUddP\r"
1002  " Uppercase two lines
1003  exe "normal Oblah di\rdoh dut\<Esc>VkUj\r"
1004  " Uppercase part of two lines
1005  exe "normal ddppi333\<Esc>k0i222\<Esc>fyllvjfuUk"
1006  call assert_equal(['the YOUTUSSEUU end', '- yOUSSTUSSEXu -',
1007        \ 'THE YOUTUSSEUU END', '111THE YOUTUSSEUU END', 'BLAH DI', 'DOH DUT',
1008        \ '222the yoUTUSSEUU END', '333THE YOUTUßeuu end'], getline(2, '$'))
1009  bwipe!
1010endfunc
1011
1012" Test for Visual replace using Enter or NL
1013func Test_visual_replace_crnl()
1014  new
1015  exe "normal G3o123456789\e2k05l\<C-V>2jr\r"
1016  exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\r\n"
1017  exe "normal G3o123456789\e2k05l\<C-V>2jr\n"
1018  exe "normal G3o98765\e2k02l\<C-V>2jr\<C-V>\n"
1019  call assert_equal(['12345', '789', '12345', '789', '12345', '789', "98\r65",
1020        \ "98\r65", "98\r65", '12345', '789', '12345', '789', '12345', '789',
1021        \ "98\n65", "98\n65", "98\n65"], getline(2, '$'))
1022  bwipe!
1023endfunc
1024
1025func Test_ve_block_curpos()
1026  new
1027  " Test cursor position. When ve=block and Visual block mode and $gj
1028  call append(0, ['12345', '789'])
1029  call cursor(1, 3)
1030  set virtualedit=block
1031  exe "norm! \<C-V>$gj\<Esc>"
1032  call assert_equal([0, 2, 4, 0], getpos("'>"))
1033  set virtualedit=
1034  bwipe!
1035endfunc
1036
1037" Test for block_insert when replacing spaces in front of the a with tabs
1038func Test_block_insert_replace_tabs()
1039  new
1040  set ts=8 sts=4 sw=4
1041  call append(0, ["#define BO_ALL\t    0x0001",
1042        \ "#define BO_BS\t    0x0002",
1043        \ "#define BO_CRSR\t    0x0004"])
1044  call cursor(1, 1)
1045  exe "norm! f0\<C-V>2jI\<tab>\<esc>"
1046  call assert_equal([
1047        \ "#define BO_ALL\t\t0x0001",
1048        \ "#define BO_BS\t    \t0x0002",
1049        \ "#define BO_CRSR\t    \t0x0004", ''], getline(1, '$'))
1050  set ts& sts& sw&
1051  bwipe!
1052endfunc
1053
1054" Test for * register in :
1055func Test_star_register()
1056  call assert_fails('*bfirst', 'E16:')
1057  new
1058  call setline(1, ['foo', 'bar', 'baz', 'qux'])
1059  exe "normal jVj\<ESC>"
1060  *yank r
1061  call assert_equal("bar\nbaz\n", @r)
1062
1063  delmarks < >
1064  call assert_fails('*yank', 'E20:')
1065  close!
1066endfunc
1067
1068" Test for changing text in visual mode with 'exclusive' selection
1069func Test_exclusive_selection()
1070  new
1071  call setline(1, ['one', 'two'])
1072  set selection=exclusive
1073  call feedkeys("vwcabc", 'xt')
1074  call assert_equal('abctwo', getline(1))
1075  call setline(1, ["\tone"])
1076  set virtualedit=all
1077  call feedkeys('0v2lcl', 'xt')
1078  call assert_equal('l      one', getline(1))
1079  set virtualedit&
1080  set selection&
1081  close!
1082endfunc
1083
1084" Test for starting linewise visual with a count.
1085" This test needs to be run without any previous visual mode. Otherwise the
1086" count will use the count from the previous visual mode.
1087func Test_linewise_visual_with_count()
1088  let after =<< trim [CODE]
1089    call setline(1, ['one', 'two', 'three', 'four'])
1090    norm! 3Vy
1091    call assert_equal("one\ntwo\nthree\n", @")
1092    call writefile(v:errors, 'Xtestout')
1093    qall!
1094  [CODE]
1095  if RunVim([], after, '')
1096    call assert_equal([], readfile('Xtestout'))
1097    call delete('Xtestout')
1098  endif
1099endfunc
1100
1101" Test for starting characterwise visual with a count.
1102" This test needs to be run without any previous visual mode. Otherwise the
1103" count will use the count from the previous visual mode.
1104func Test_characterwise_visual_with_count()
1105  let after =<< trim [CODE]
1106    call setline(1, ['one two', 'three'])
1107    norm! l5vy
1108    call assert_equal("ne tw", @")
1109    call writefile(v:errors, 'Xtestout')
1110    qall!
1111  [CODE]
1112  if RunVim([], after, '')
1113    call assert_equal([], readfile('Xtestout'))
1114    call delete('Xtestout')
1115  endif
1116endfunc
1117
1118" Test for visually selecting an inner block (iB)
1119func Test_visual_inner_block()
1120  new
1121  call setline(1, ['one', '{', 'two', '{', 'three', '}', 'four', '}', 'five'])
1122  call cursor(5, 1)
1123  " visually select all the lines in the block and then execute iB
1124  call feedkeys("ViB\<C-C>", 'xt')
1125  call assert_equal([0, 5, 1, 0], getpos("'<"))
1126  call assert_equal([0, 5, 6, 0], getpos("'>"))
1127  " visually select two inner blocks
1128  call feedkeys("ViBiB\<C-C>", 'xt')
1129  call assert_equal([0, 3, 1, 0], getpos("'<"))
1130  call assert_equal([0, 7, 5, 0], getpos("'>"))
1131  " try to select non-existing inner block
1132  call cursor(5, 1)
1133  call assert_beeps('normal ViBiBiB')
1134  " try to select a unclosed inner block
1135  8,9d
1136  call cursor(5, 1)
1137  call assert_beeps('normal ViBiB')
1138  close!
1139endfunc
1140
1141func Test_visual_put_in_block()
1142  new
1143  call setline(1, ['xxxx', 'y∞yy', 'zzzz'])
1144  normal 1G2yl
1145  exe "normal 1G2l\<C-V>jjlp"
1146  call assert_equal(['xxxx', 'y∞xx', 'zzxx'], getline(1, 3))
1147  bwipe!
1148endfunc
1149
1150func Test_visual_put_in_block_using_zp()
1151  new
1152  " paste using zP
1153  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1154    \ '/subdir',
1155    \ '/longsubdir',
1156    \ '/longlongsubdir'])
1157  exe "normal! 5G\<c-v>2j$y"
1158  norm! 1Gf;zP
1159  call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3))
1160  %d
1161  " paste using zP
1162  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1163    \ '/subdir',
1164    \ '/longsubdir',
1165    \ '/longlongsubdir'])
1166  exe "normal! 5G\<c-v>2j$y"
1167  norm! 1Gf;hzp
1168  call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3))
1169  bwipe!
1170endfunc
1171
1172func Test_visual_put_in_block_using_zy_and_zp()
1173  new
1174
1175  " Test 1) Paste using zp - after the cursor without trailing spaces
1176  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1177    \ 'texttext  /subdir           columntext',
1178		\ 'texttext  /longsubdir       columntext',
1179    \ 'texttext  /longlongsubdir   columntext'])
1180  exe "normal! 5G0f/\<c-v>2jezy"
1181  norm! 1G0f;hzp
1182  call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3))
1183
1184  " Test 2) Paste using zP - in front of the cursor without trailing spaces
1185  %d
1186  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1187    \ 'texttext  /subdir           columntext',
1188		\ 'texttext  /longsubdir       columntext',
1189    \ 'texttext  /longlongsubdir   columntext'])
1190  exe "normal! 5G0f/\<c-v>2jezy"
1191  norm! 1G0f;zP
1192  call assert_equal(['/path/subdir;text', '/path/longsubdir;text', '/path/longlongsubdir;text'], getline(1, 3))
1193
1194  " Test 3) Paste using p - with trailing spaces
1195  %d
1196  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1197    \ 'texttext  /subdir           columntext',
1198		\ 'texttext  /longsubdir       columntext',
1199    \ 'texttext  /longlongsubdir   columntext'])
1200  exe "normal! 5G0f/\<c-v>2jezy"
1201  norm! 1G0f;hp
1202  call assert_equal(['/path/subdir        ;text', '/path/longsubdir    ;text', '/path/longlongsubdir;text'], getline(1, 3))
1203
1204  " Test 4) Paste using P - with trailing spaces
1205  %d
1206  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1207    \ 'texttext  /subdir           columntext',
1208		\ 'texttext  /longsubdir       columntext',
1209    \ 'texttext  /longlongsubdir   columntext'])
1210  exe "normal! 5G0f/\<c-v>2jezy"
1211  norm! 1G0f;P
1212  call assert_equal(['/path/subdir        ;text', '/path/longsubdir    ;text', '/path/longlongsubdir;text'], getline(1, 3))
1213
1214  " Test 5) Yank with spaces inside the block
1215  %d
1216  call setline(1, ['/path;text', '/path;text', '/path;text', '',
1217    \ 'texttext  /sub    dir/           columntext',
1218    \ 'texttext  /lon    gsubdir/       columntext',
1219    \ 'texttext  /lon    glongsubdir/   columntext'])
1220  exe "normal! 5G0f/\<c-v>2jf/zy"
1221  norm! 1G0f;zP
1222  call assert_equal(['/path/sub    dir/;text', '/path/lon    gsubdir/;text', '/path/lon    glongsubdir/;text'], getline(1, 3))
1223  bwipe!
1224endfunc
1225
1226func Test_visual_put_blockedit_zy_and_zp()
1227  new
1228
1229  call setline(1, ['aa', 'bbbbb', 'ccc', '', 'XX', 'GGHHJ', 'RTZU'])
1230  exe "normal! gg0\<c-v>2j$zy"
1231  norm! 5gg0zP
1232  call assert_equal(['aa', 'bbbbb', 'ccc', '', 'aaXX', 'bbbbbGGHHJ', 'cccRTZU'], getline(1, 7))
1233  "
1234  " now with blockmode editing
1235  sil %d
1236  :set ve=block
1237  call setline(1, ['aa', 'bbbbb', 'ccc', '', 'XX', 'GGHHJ', 'RTZU'])
1238  exe "normal! gg0\<c-v>2j$zy"
1239  norm! 5gg0zP
1240  call assert_equal(['aa', 'bbbbb', 'ccc', '', 'aaXX', 'bbbbbGGHHJ', 'cccRTZU'], getline(1, 7))
1241  set ve&vim
1242  bw!
1243endfunc
1244
1245func Test_visual_block_with_virtualedit()
1246  CheckScreendump
1247
1248  let lines =<< trim END
1249    call setline(1, ['aaaaaa', 'bbbb', 'cc'])
1250    set virtualedit=block
1251    normal G
1252  END
1253  call writefile(lines, 'XTest_block')
1254
1255  let buf = RunVimInTerminal('-S XTest_block', {'rows': 8, 'cols': 50})
1256  call term_sendkeys(buf, "\<C-V>gg$")
1257  call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit', {})
1258
1259  call term_sendkeys(buf, "\<Esc>gg\<C-V>G$")
1260  call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit2', {})
1261
1262  " clean up
1263  call term_sendkeys(buf, "\<Esc>")
1264  call StopVimInTerminal(buf)
1265  call delete('XTest_block')
1266endfunc
1267
1268func Test_visual_reselect_with_count()
1269  " this was causing an illegal memory access
1270  let lines =<< trim END
1271
1272
1273
1274      :
1275      r<sfile>
1276      exe "%norm e3\<c-v>kr\t"
1277      :
1278
1279      :
1280  END
1281  call writefile(lines, 'XvisualReselect')
1282  source XvisualReselect
1283
1284  bwipe!
1285  call delete('XvisualReselect')
1286endfunc
1287
1288
1289" vim: shiftwidth=2 sts=2 expandtab
1290