blob: a4b120bea1cab24edb08c7cccf486a8f2b7a1d4f [file] [log] [blame]
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +01001" Tests for various Visual mode.
Bram Moolenaarc3c766e2017-03-08 22:55:19 +01002
Bram Moolenaar019b9c62016-03-05 17:26:00 +01003func Test_block_shift_multibyte()
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +01004 " Uses double-wide character.
Bram Moolenaar019b9c62016-03-05 17:26:00 +01005 split
6 call setline(1, ['xヹxxx', 'ヹxxx'])
7 exe "normal 1G0l\<C-V>jl>"
8 call assert_equal('x ヹxxx', getline(1))
9 call assert_equal(' ヹxxx', getline(2))
10 q!
11endfunc
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +010012
Bram Moolenaarbae5a172017-08-06 15:42:06 +020013func Test_block_shift_overflow()
14 " This used to cause a multiplication overflow followed by a crash.
15 new
16 normal ii
17 exe "normal \<C-V>876543210>"
18 q!
19endfunc
20
Bram Moolenaarf8eb9c52017-01-02 17:31:24 +010021func Test_dotregister_paste()
22 new
23 exe "norm! ihello world\<esc>"
24 norm! 0ve".p
25 call assert_equal('hello world world', getline(1))
26 q!
27endfunc
Bram Moolenaar23fa81d2017-02-01 21:50:21 +010028
29func Test_Visual_ctrl_o()
30 new
31 call setline(1, ['one', 'two', 'three'])
32 call cursor(1,2)
33 set noshowmode
34 set tw=0
35 call feedkeys("\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>", 'tx')
36 call assert_equal(['oane', 'tawo', 'tahree'], getline(1, 3))
37 call assert_equal(88, &tw)
38 set tw&
39 bw!
40endfu
Bram Moolenaar84b2a382017-02-17 11:40:00 +010041
42func Test_Visual_vapo()
43 new
44 normal oxx
45 normal vapo
46 bwipe!
47endfunc
Bram Moolenaar46522af2017-02-18 23:12:01 +010048
49func Test_Visual_inner_quote()
50 new
51 normal oxX
52 normal vki'
53 bwipe!
54endfunc
Bram Moolenaar75373f32017-08-07 22:02:30 +020055
56" Test for Visual mode not being reset causing E315 error.
57func TriggerTheProblem()
58 " At this point there is no visual selection because :call reset it.
59 " Let's restore the selection:
60 normal gv
61 '<,'>del _
62 try
63 exe "normal \<Esc>"
64 catch /^Vim\%((\a\+)\)\=:E315/
65 echom 'Snap! E315 error!'
Bram Moolenaar63e82db2018-03-06 12:10:48 +010066 let g:msg = 'Snap! E315 error!'
Bram Moolenaar75373f32017-08-07 22:02:30 +020067 endtry
68endfunc
69
70func Test_visual_mode_reset()
Bram Moolenaar75373f32017-08-07 22:02:30 +020071 enew
Bram Moolenaar63e82db2018-03-06 12:10:48 +010072 let g:msg = "Everything's fine."
Bram Moolenaar75373f32017-08-07 22:02:30 +020073 enew
74 setl buftype=nofile
75 call append(line('$'), 'Delete this line.')
76
77 " NOTE: this has to be done by a call to a function because executing :del
78 " the ex-way will require the colon operator which resets the visual mode
79 " thus preventing the problem:
80 exe "normal! GV:call TriggerTheProblem()\<CR>"
81 call assert_equal("Everything's fine.", g:msg)
82
Bram Moolenaar75373f32017-08-07 22:02:30 +020083endfunc
Bram Moolenaar67418d92017-10-15 22:07:39 +020084
Bram Moolenaar15993ce2017-10-26 20:21:44 +020085" Test for visual block shift and tab characters.
86func Test_block_shift_tab()
87 enew!
88 call append(0, repeat(['one two three'], 5))
89 call cursor(1,1)
90 exe "normal i\<C-G>u"
91 exe "normal fe\<C-V>4jR\<Esc>ugvr1"
92 call assert_equal('on1 two three', getline(1))
93 call assert_equal('on1 two three', getline(2))
94 call assert_equal('on1 two three', getline(5))
95
96 enew!
97 call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5))
98 call cursor(1,1)
99 exe "normal \<C-V>4jI \<Esc>j<<11|D"
100 exe "normal j7|a\<Tab>\<Tab>"
101 exe "normal j7|a\<Tab>\<Tab> "
102 exe "normal j7|a\<Tab> \<Tab>\<Esc>4k13|\<C-V>4j<"
103 call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1))
104 call assert_equal('abcdefghij', getline(2))
105 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3))
106 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(4))
107 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5))
108
109 %s/\s\+//g
110 call cursor(1,1)
111 exe "normal \<C-V>4jI \<Esc>j<<"
112 exe "normal j7|a\<Tab>\<Tab>"
113 exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>"
114 exe "normal j7|a\<Tab> \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<"
115 call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1))
116 call assert_equal('abcdefghij', getline(2))
117 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3))
118 call assert_equal(" abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4))
119 call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5))
120
121 enew!
122endfunc
123
124" Tests Blockwise Visual when there are TABs before the text.
125func Test_blockwise_visual()
126 enew!
127 call append(0, ['123456',
128 \ '234567',
129 \ '345678',
130 \ '',
131 \ 'test text test tex start here',
132 \ "\t\tsome text",
133 \ "\t\ttest text",
134 \ 'test text'])
135 call cursor(1,1)
136 exe "normal /start here$\<CR>"
137 exe 'normal "by$' . "\<C-V>jjlld"
138 exe "normal /456$\<CR>"
139 exe "normal \<C-V>jj" . '"bP'
140 call assert_equal(['123start here56',
141 \ '234start here67',
142 \ '345start here78',
143 \ '',
144 \ 'test text test tex rt here',
145 \ "\t\tsomext",
146 \ "\t\ttesext"], getline(1, 7))
147
148 enew!
149endfunc
150
Bram Moolenaar2e949762018-05-20 14:06:38 +0200151" Test swapping corners in blockwise visual mode with o and O
152func Test_blockwise_visual_o_O()
153 enew!
154
155 exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr "
156 exe "norm! gvO\<Esc>ra"
157 exe "norm! gvO\<Esc>rb"
158 exe "norm! gvo\<C-c>rc"
159 exe "norm! gvO\<C-c>rd"
160
161 call assert_equal(['..........',
162 \ '...c d..',
163 \ '... ..',
164 \ '...a b..',
165 \ '..........'], getline(1, '$'))
166
167 enew!
168endfun
169
Bram Moolenaar15993ce2017-10-26 20:21:44 +0200170" Test Virtual replace mode.
171func Test_virtual_replace()
Bram Moolenaardf0d24b2018-03-06 14:22:58 +0100172 if exists('&t_kD')
173 let save_t_kD = &t_kD
174 endif
175 if exists('&t_kb')
176 let save_t_kb = &t_kb
177 endif
Bram Moolenaar15993ce2017-10-26 20:21:44 +0200178 exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08"
179 enew!
180 exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz"
181 call cursor(1,1)
182 set ai bs=2
183 exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR"
184 call assert_equal([' 1',
185 \ ' A',
186 \ ' BCDEFGHIJ',
187 \ ' KL',
188 \ ' MNO',
189 \ ' PQR',
190 \ ], getline(1, 6))
191 normal G
192 mark a
193 exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n"
194 exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29)
195 call assert_equal([' 1',
196 \ 'abcdefghi',
197 \ 'jk lmn',
198 \ ' opq rst',
199 \ 'uvwxyz'], getline(7, 11))
200 normal G
201 exe "normal iab\tcdefghi\tjkl"
202 exe "normal 0gRAB......CDEFGHI.J\<Esc>o"
203 exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR"
204 call assert_equal(['AB......CDEFGHI.Jkl',
205 \ 'AB IJKLMNO QRst'], getline(12, 13))
206 enew!
Bram Moolenaare7808482018-03-06 13:17:23 +0100207 set noai bs&vim
Bram Moolenaardf0d24b2018-03-06 14:22:58 +0100208 if exists('save_t_kD')
209 let &t_kD = save_t_kD
210 endif
211 if exists('save_t_kb')
212 let &t_kb = save_t_kb
213 endif
Bram Moolenaar63e82db2018-03-06 12:10:48 +0100214endfunc
215
216" Test Virtual replace mode.
217func Test_virtual_replace2()
218 enew!
219 set bs=2
220 exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz"
221 call cursor(1,1)
222 " Test 1: Test that del deletes the newline
223 exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR"
224 call assert_equal(['0 1',
225 \ 'A',
226 \ 'BCDEFGHIJ',
227 \ ' KL',
228 \ 'MNO',
229 \ 'PQR',
230 \ ], getline(1, 6))
231 " Test 2:
232 " a newline is not deleted, if no newline has been added in virtual replace mode
233 %d_
234 call setline(1, ['abcd', 'efgh', 'ijkl'])
235 call cursor(2,1)
236 exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>"
237 call assert_equal(['abcd',
238 \ '123h',
239 \ 'ijkl'], getline(1, '$'))
240 " Test 3:
241 " a newline is deleted, if a newline has been inserted before in virtual replace mode
242 %d_
243 call setline(1, ['abcd', 'efgh', 'ijkl'])
244 call cursor(2,1)
245 exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>"
246 call assert_equal(['abcd',
247 \ '1234',
248 \ 'ijkl'], getline(1, '$'))
249 " Test 4:
250 " delete add a newline, delete it, add it again and check undo
251 %d_
252 call setline(1, ['abcd', 'efgh', 'ijkl'])
253 call cursor(2,1)
254 " break undo sequence explicitly
255 let &ul = &ul
256 exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>"
257 let &ul = &ul
258 call assert_equal(['abcd',
259 \ '123456',
260 \ ''], getline(1, '$'))
261 norm! u
262 call assert_equal(['abcd',
263 \ 'efgh',
264 \ 'ijkl'], getline(1, '$'))
265 " clean up
266 %d_
267 set bs&vim
Bram Moolenaar15993ce2017-10-26 20:21:44 +0200268endfunc
Bram Moolenaar6d3a1942019-01-03 23:10:32 +0100269
Bram Moolenaar81b1ba42019-01-13 16:12:40 +0100270func Test_Visual_word_textobject()
271 new
272 call setline(1, ['First sentence. Second sentence.'])
273
274 " When start and end of visual area are identical, 'aw' or 'iw' select
275 " the whole word.
276 norm! 1go2fcvawy
277 call assert_equal('Second ', @")
278 norm! 1go2fcviwy
279 call assert_equal('Second', @")
280
281 " When start and end of visual area are not identical, 'aw' or 'iw'
282 " extend the word in direction of the end of the visual area.
283 norm! 1go2fcvlawy
284 call assert_equal('cond ', @")
285 norm! gv2awy
286 call assert_equal('cond sentence.', @")
287
288 norm! 1go2fcvliwy
289 call assert_equal('cond', @")
290 norm! gv2iwy
291 call assert_equal('cond sentence', @")
292
293 " Extend visual area in opposite direction.
294 norm! 1go2fcvhawy
295 call assert_equal(' Sec', @")
296 norm! gv2awy
297 call assert_equal(' sentence. Sec', @")
298
299 norm! 1go2fcvhiwy
300 call assert_equal('Sec', @")
301 norm! gv2iwy
302 call assert_equal('. Sec', @")
303
304 bwipe!
305endfunc
306
Bram Moolenaar6d3a1942019-01-03 23:10:32 +0100307func Test_Visual_sentence_textobject()
308 new
Bram Moolenaar81b1ba42019-01-13 16:12:40 +0100309 call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence'])
Bram Moolenaar6d3a1942019-01-03 23:10:32 +0100310
311 " When start and end of visual area are identical, 'as' or 'is' select
312 " the whole sentence.
313 norm! 1gofdvasy
314 call assert_equal('Second sentence. ', @")
315 norm! 1gofdvisy
316 call assert_equal('Second sentence.', @")
317
318 " When start and end of visual area are not identical, 'as' or 'is'
319 " extend the sentence in direction of the end of the visual area.
320 norm! 1gofdvlasy
321 call assert_equal('d sentence. ', @")
322 norm! gvasy
323 call assert_equal("d sentence. Third\nsentence. ", @")
324
325 norm! 1gofdvlisy
326 call assert_equal('d sentence.', @")
327 norm! gvisy
328 call assert_equal('d sentence. ', @")
329 norm! gvisy
330 call assert_equal("d sentence. Third\nsentence.", @")
331
332 " Extend visual area in opposite direction.
333 norm! 1gofdvhasy
334 call assert_equal(' Second', @")
335 norm! gvasy
336 call assert_equal("First sentence. Second", @")
337
338 norm! 1gofdvhisy
339 call assert_equal('Second', @")
340 norm! gvisy
341 call assert_equal(' Second', @")
342 norm! gvisy
343 call assert_equal('First sentence. Second', @")
344
345 bwipe!
346endfunc
Bram Moolenaar81b1ba42019-01-13 16:12:40 +0100347
348func Test_Visual_paragraph_textobject()
349 new
350 call setline(1, ['First line.',
351 \ '',
352 \ 'Second line.',
353 \ 'Third line.',
354 \ 'Fourth line.',
355 \ 'Fifth line.',
356 \ '',
357 \ 'Sixth line.'])
358
359 " When start and end of visual area are identical, 'ap' or 'ip' select
360 " the whole paragraph.
361 norm! 4ggvapy
362 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @")
363 norm! 4ggvipy
364 call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @")
365
366 " When start and end of visual area are not identical, 'ap' or 'ip'
367 " extend the sentence in direction of the end of the visual area.
368 " FIXME: actually, it is not sufficient to have different start and
369 " end of visual selection, the start line and end line have to differ,
370 " which is not consistent with the documentation.
371 norm! 4ggVjapy
372 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @")
373 norm! gvapy
374 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @")
375 norm! 4ggVjipy
376 call assert_equal("Third line.\nFourth line.\nFifth line.\n", @")
377 norm! gvipy
378 call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @")
379 norm! gvipy
380 call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @")
381
382 " Extend visual area in opposite direction.
383 norm! 5ggVkapy
384 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @")
385 norm! gvapy
386 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @")
387 norm! 5ggVkipy
388 call assert_equal("Second line.\nThird line.\nFourth line.\n", @")
389 norma gvipy
390 call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @")
391 norm! gvipy
392 call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @")
393
394 bwipe!
395endfunc
Bram Moolenaar19a66852019-03-07 11:25:32 +0100396
397func Test_curswant_not_changed()
398 new
399 call setline(1, ['one', 'two'])
400 au InsertLeave * call getcurpos()
401 call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt')
402 call assert_equal([0, 2, 1, 0, 1], getcurpos())
403
404 bwipe!
405 au! InsertLeave
406endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +0200407
408" Tests for "vaBiB", end could be wrong.
409func Test_Visual_Block()
410 new
411 a
412- Bug in "vPPPP" on this text:
413 {
414 cmd;
415 {
416 cmd;\t/* <-- Start cursor here */
417 {
418 }
419 }
420 }
421.
422 normal gg
423 call search('Start cursor here')
424 normal vaBiBD
425 call assert_equal(['- Bug in "vPPPP" on this text:',
426 \ "\t{",
427 \ "\t}"], getline(1, '$'))
428
429 close!
430endfunc
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100431
432" Test for 'p'ut in visual block mode
433func Test_visual_block_put()
434 enew
435
436 call append(0, ['One', 'Two', 'Three'])
437 normal gg
438 yank
439 call feedkeys("jl\<C-V>ljp", 'xt')
440 call assert_equal(['One', 'T', 'Tee', 'One', ''], getline(1, '$'))
441
442 enew!
443endfunc
444
Bram Moolenaar309976e2019-12-05 18:16:33 +0100445" Visual modes (v V CTRL-V) followed by an operator; count; repeating
446func Test_visual_mode_op()
447 new
448 call append(0, '')
449
450 call setline(1, 'apple banana cherry')
451 call cursor(1, 1)
452 normal lvld.l3vd.
453 call assert_equal('a y', getline(1))
454
455 call setline(1, ['line 1 line 1', 'line 2 line 2', 'line 3 line 3',
456 \ 'line 4 line 4', 'line 5 line 5', 'line 6 line 6'])
457 call cursor(1, 1)
458 exe "normal Vcnewline\<Esc>j.j2Vd."
459 call assert_equal(['newline', 'newline'], getline(1, '$'))
460
461 call deletebufline('', 1, '$')
462 call setline(1, ['xxxxxxxxxxxxx', 'xxxxxxxxxxxxx', 'xxxxxxxxxxxxx',
463 \ 'xxxxxxxxxxxxx'])
464 exe "normal \<C-V>jlc \<Esc>l.l2\<C-V>c----\<Esc>l."
465 call assert_equal([' --------x',
466 \ ' --------x',
467 \ 'xxxx--------x',
468 \ 'xxxx--------x'], getline(1, '$'))
469
470 bwipe!
471endfunc
472
473" Visual mode maps (movement and text object)
474" Visual mode maps; count; repeating
475" - Simple
476" - With an Ex command (custom text object)
477func Test_visual_mode_maps()
478 new
479 call append(0, '')
480
481 func SelectInCaps()
482 let [line1, col1] = searchpos('\u', 'bcnW')
483 let [line2, col2] = searchpos('.\u', 'nW')
484 call setpos("'<", [0, line1, col1, 0])
485 call setpos("'>", [0, line2, col2, 0])
486 normal! gv
487 endfunction
488
489 vnoremap W /\u/s-1<CR>
490 vnoremap iW :<C-U>call SelectInCaps()<CR>
491
492 call setline(1, 'KiwiRaspberryDateWatermelonPeach')
493 call cursor(1, 1)
494 exe "normal vWcNo\<Esc>l.fD2vd."
495 call assert_equal('NoNoberryach', getline(1))
496
497 call setline(1, 'JambuRambutanBananaTangerineMango')
498 call cursor(1, 1)
499 exe "normal llviWc-\<Esc>l.l2vdl."
500 call assert_equal('--ago', getline(1))
501
502 vunmap W
503 vunmap iW
504 bwipe!
505 delfunc SelectInCaps
506endfunc
507
508" Operator-pending mode maps (movement and text object)
509" - Simple
510" - With Ex command moving the cursor
511" - With Ex command and Visual selection (custom text object)
512func Test_visual_oper_pending_mode_maps()
513 new
514 call append(0, '')
515
516 func MoveToCap()
517 call search('\u', 'W')
518 endfunction
519
520 func SelectInCaps()
521 let [line1, col1] = searchpos('\u', 'bcnW')
522 let [line2, col2] = searchpos('.\u', 'nW')
523 call setpos("'<", [0, line1, col1, 0])
524 call setpos("'>", [0, line2, col2, 0])
525 normal! gv
526 endfunction
527
528 onoremap W /\u/<CR>
529 onoremap <Leader>W :<C-U>call MoveToCap()<CR>
530 onoremap iW :<C-U>call SelectInCaps()<CR>
531
532 call setline(1, 'PineappleQuinceLoganberryOrangeGrapefruitKiwiZ')
533 call cursor(1, 1)
534 exe "normal cW-\<Esc>l.l2.l."
535 call assert_equal('----Z', getline(1))
536
537 call setline(1, 'JuniperDurianZ')
538 call cursor(1, 1)
539 exe "normal g?\WfD."
540 call assert_equal('WhavcreQhevnaZ', getline(1))
541
542 call setline(1, 'LemonNectarineZ')
543 call cursor(1, 1)
544 exe "normal yiWPlciWNew\<Esc>fr."
545 call assert_equal('LemonNewNewZ', getline(1))
546
547 ounmap W
548 ounmap <Leader>W
549 ounmap iW
550 bwipe!
551 delfunc MoveToCap
552 delfunc SelectInCaps
553endfunc
554
555" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc.
556func Test_op_pend_mode_abort()
557 new
558 call append(0, '')
559
560 call setline(1, ['zzzz', 'zzzz'])
561 call cursor(1, 1)
562
563 exe "normal dV:\<CR>dv:\<CR>"
564 call assert_equal(['zzz'], getline(1, 2))
565 set nomodifiable
566 call assert_fails('exe "normal d:\<CR>"', 'E21:')
567 set modifiable
568 call feedkeys("dv:\<Esc>dV:\<Esc>", 'xt')
569 call assert_equal(['zzz'], getline(1, 2))
570 set nomodifiable
571 let v:errmsg = ''
572 call feedkeys("d:\<Esc>", 'xt')
573 call assert_true(v:errmsg !~# '^E21:')
574 set modifiable
575
576 bwipe!
577endfunc
578
579func Test_characterwise_visual_mode()
580 new
581
582 " characterwise visual mode: replace last line
583 $put ='a'
584 let @" = 'x'
585 normal v$p
586 call assert_equal('x', getline('$'))
587
588 " characterwise visual mode: delete middle line
589 call deletebufline('', 1, '$')
590 call append('$', ['a', 'b', 'c'])
591 normal G
592 normal kkv$d
593 call assert_equal(['', 'b', 'c'], getline(1, '$'))
594
595 " characterwise visual mode: delete middle two lines
596 call deletebufline('', 1, '$')
597 call append('$', ['a', 'b', 'c'])
598 normal Gkkvj$d
599 call assert_equal(['', 'c'], getline(1, '$'))
600
601 " characterwise visual mode: delete last line
602 call deletebufline('', 1, '$')
603 call append('$', ['a', 'b', 'c'])
604 normal Gv$d
605 call assert_equal(['', 'a', 'b', ''], getline(1, '$'))
606
607 " characterwise visual mode: delete last two lines
608 call deletebufline('', 1, '$')
609 call append('$', ['a', 'b', 'c'])
610 normal Gkvj$d
611 call assert_equal(['', 'a', ''], getline(1, '$'))
612
613 bwipe!
614endfunc
615
616func Test_characterwise_select_mode()
617 new
618
619 " Select mode maps
620 snoremap <lt>End> <End>
621 snoremap <lt>Down> <Down>
622 snoremap <lt>Del> <Del>
623
624 " characterwise select mode: delete middle line
625 call deletebufline('', 1, '$')
626 call append('$', ['a', 'b', 'c'])
627 exe "normal Gkkgh\<End>\<Del>"
628 call assert_equal(['', 'b', 'c'], getline(1, '$'))
629
630 " characterwise select mode: delete middle two lines
631 call deletebufline('', 1, '$')
632 call append('$', ['a', 'b', 'c'])
633 exe "normal Gkkgh\<Down>\<End>\<Del>"
634 call assert_equal(['', 'c'], getline(1, '$'))
635
636 " characterwise select mode: delete last line
637 call deletebufline('', 1, '$')
638 call append('$', ['a', 'b', 'c'])
639 exe "normal Ggh\<End>\<Del>"
640 call assert_equal(['', 'a', 'b', ''], getline(1, '$'))
641
642 " characterwise select mode: delete last two lines
643 call deletebufline('', 1, '$')
644 call append('$', ['a', 'b', 'c'])
645 exe "normal Gkgh\<Down>\<End>\<Del>"
646 call assert_equal(['', 'a', ''], getline(1, '$'))
647
648 sunmap <lt>End>
649 sunmap <lt>Down>
650 sunmap <lt>Del>
651 bwipe!
652endfunc
653
654func Test_linewise_select_mode()
655 new
656
657 " linewise select mode: delete middle line
658 call append('$', ['a', 'b', 'c'])
659 exe "normal GkkgH\<Del>"
660 call assert_equal(['', 'b', 'c'], getline(1, '$'))
661
662
663 " linewise select mode: delete middle two lines
664 call deletebufline('', 1, '$')
665 call append('$', ['a', 'b', 'c'])
666 exe "normal GkkgH\<Down>\<Del>"
667 call assert_equal(['', 'c'], getline(1, '$'))
668
669 " linewise select mode: delete last line
670 call deletebufline('', 1, '$')
671 call append('$', ['a', 'b', 'c'])
672 exe "normal GgH\<Del>"
673 call assert_equal(['', 'a', 'b'], getline(1, '$'))
674
675 " linewise select mode: delete last two lines
676 call deletebufline('', 1, '$')
677 call append('$', ['a', 'b', 'c'])
678 exe "normal GkgH\<Down>\<Del>"
679 call assert_equal(['', 'a'], getline(1, '$'))
680
681 bwipe!
682endfunc
683
684func Test_visual_mode_put()
685 new
686
687 " v_p: replace last character with line register at middle line
688 call append('$', ['aaa', 'bbb', 'ccc'])
689 normal G
690 -2yank
691 normal k$vp
692 call assert_equal(['', 'aaa', 'bb', 'aaa', '', 'ccc'], getline(1, '$'))
693
694 " v_p: replace last character with line register at middle line selecting
695 " newline
696 call deletebufline('', 1, '$')
697 call append('$', ['aaa', 'bbb', 'ccc'])
698 normal G
699 -2yank
700 normal k$v$p
701 call assert_equal(['', 'aaa', 'bb', 'aaa', 'ccc'], getline(1, '$'))
702
703 " v_p: replace last character with line register at last line
704 call deletebufline('', 1, '$')
705 call append('$', ['aaa', 'bbb', 'ccc'])
706 normal G
707 -2yank
708 normal $vp
709 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$'))
710
711 " v_p: replace last character with line register at last line selecting
712 " newline
713 call deletebufline('', 1, '$')
714 call append('$', ['aaa', 'bbb', 'ccc'])
715 normal G
716 -2yank
717 normal $v$p
718 call assert_equal(['', 'aaa', 'bbb', 'cc', 'aaa', ''], getline(1, '$'))
719
720 bwipe!
721endfunc
722
723func Test_select_mode_gv()
724 new
725
726 " gv in exclusive select mode after operation
727 call append('$', ['zzz ', 'äà '])
728 set selection=exclusive
729 normal Gkv3lyjv3lpgvcxxx
730 call assert_equal(['', 'zzz ', 'xxx '], getline(1, '$'))
731
732 " gv in exclusive select mode without operation
733 call deletebufline('', 1, '$')
734 call append('$', 'zzz ')
735 set selection=exclusive
736 exe "normal G0v3l\<Esc>gvcxxx"
737 call assert_equal(['', 'xxx '], getline(1, '$'))
738
739 set selection&vim
740 bwipe!
741endfunc
742
Bram Moolenaar6f1f0ca2019-12-01 18:16:18 +0100743" vim: shiftwidth=2 sts=2 expandtab