1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
|
" Test for edit functions
"
if exists("+t_kD")
let &t_kD="[3;*~"
endif
" Needed for testing basic rightleft: Test_edit_rightleft
source view_util.vim
" Needs to come first until the bug in getchar() is
" fixed: https://groups.google.com/d/msg/vim_dev/fXL9yme4H4c/bOR-U6_bAQAJ
func Test_edit_00b()
new
call setline(1, ['abc '])
inoreabbr <buffer> h here some more
call cursor(1, 4)
" <c-l> expands the abbreviation and ends insertmode
call feedkeys(":set im\<cr> h\<c-l>:set noim\<cr>", 'tix')
call assert_equal(['abc here some more '], getline(1,'$'))
iunabbr <buffer> h
bw!
endfunc
func Test_edit_01()
" set for Travis CI?
" set nocp noesckeys
new
" 1) empty buffer
call assert_equal([''], getline(1,'$'))
" 2) delete in an empty line
call feedkeys("i\<del>\<esc>", 'tnix')
call assert_equal([''], getline(1,'$'))
%d
" 3) delete one character
call setline(1, 'a')
call feedkeys("i\<del>\<esc>", 'tnix')
call assert_equal([''], getline(1,'$'))
%d
" 4) delete a multibyte character
call setline(1, "\u0401")
call feedkeys("i\<del>\<esc>", 'tnix')
call assert_equal([''], getline(1,'$'))
%d
" 5.1) delete linebreak with 'bs' option containing eol
let _bs=&bs
set bs=eol
call setline(1, ["abc def", "ghi jkl"])
call cursor(1, 1)
call feedkeys("A\<del>\<esc>", 'tnix')
call assert_equal(['abc defghi jkl'], getline(1, 2))
%d
" 5.2) delete linebreak with backspace option w/out eol
set bs=
call setline(1, ["abc def", "ghi jkl"])
call cursor(1, 1)
call feedkeys("A\<del>\<esc>", 'tnix')
call assert_equal(["abc def", "ghi jkl"], getline(1, 2))
let &bs=_bs
bw!
endfunc
func Test_edit_02()
" Change cursor position in InsertCharPre command
new
call setline(1, 'abc')
call cursor(1, 1)
fu! DoIt(...)
call cursor(1, 4)
if len(a:000)
let v:char=a:1
endif
endfu
au InsertCharPre <buffer> :call DoIt('y')
call feedkeys("ix\<esc>", 'tnix')
call assert_equal(['abcy'], getline(1, '$'))
" Setting <Enter> in InsertCharPre
au! InsertCharPre <buffer> :call DoIt("\n")
call setline(1, 'abc')
call cursor(1, 1)
call feedkeys("ix\<esc>", 'tnix')
call assert_equal(['abc', ''], getline(1, '$'))
%d
au! InsertCharPre
" Change cursor position in InsertEnter command
" 1) when setting v:char, keeps changed cursor position
au! InsertEnter <buffer> :call DoIt('y')
call setline(1, 'abc')
call cursor(1, 1)
call feedkeys("ix\<esc>", 'tnix')
call assert_equal(['abxc'], getline(1, '$'))
" 2) when not setting v:char, restores changed cursor position
au! InsertEnter <buffer> :call DoIt()
call setline(1, 'abc')
call cursor(1, 1)
call feedkeys("ix\<esc>", 'tnix')
call assert_equal(['xabc'], getline(1, '$'))
au! InsertEnter
delfu DoIt
bw!
endfunc
func Test_edit_03()
" Change cursor after <c-o> command to end of line
new
call setline(1, 'abc')
call cursor(1, 1)
call feedkeys("i\<c-o>$y\<esc>", 'tnix')
call assert_equal(['abcy'], getline(1, '$'))
%d
call setline(1, 'abc')
call cursor(1, 1)
call feedkeys("i\<c-o>80|y\<esc>", 'tnix')
call assert_equal(['abcy'], getline(1, '$'))
%d
call setline(1, 'abc')
call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix')
call assert_equal(['hijabcdefg'], getline(1, '$'))
bw!
endfunc
func Test_edit_04()
" test for :stopinsert
new
call setline(1, 'abc')
call cursor(1, 1)
call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix')
call feedkeys("aX\<esc>", 'tnix')
call assert_equal(['abcX'], getline(1, '$'))
%d
bw!
endfunc
func Test_edit_05()
" test for folds being opened
new
call setline(1, ['abcX', 'abcX', 'zzzZ'])
call cursor(1, 1)
set foldmethod=manual foldopen+=insert
" create fold for those two lines
norm! Vjzf
call feedkeys("$ay\<esc>", 'tnix')
call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$'))
%d
call setline(1, ['abcX', 'abcX', 'zzzZ'])
call cursor(1, 1)
set foldmethod=manual foldopen-=insert
" create fold for those two lines
norm! Vjzf
call feedkeys("$ay\<esc>", 'tnix')
call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$'))
%d
bw!
endfunc
func Test_edit_06()
" Test in diff mode
if !has("diff") || !executable("diff")
return
endif
new
call setline(1, ['abc', 'xxx', 'yyy'])
vnew
call setline(1, ['abc', 'zzz', 'xxx', 'yyy'])
wincmd p
diffthis
wincmd p
diffthis
wincmd p
call cursor(2, 1)
norm! zt
call feedkeys("Ozzz\<esc>", 'tnix')
call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$'))
bw!
bw!
endfunc
func Test_edit_07()
" 1) Test with completion <c-l> when popupmenu is visible
new
call setline(1, 'J')
func! ListMonths()
call complete(col('.')-1, ['January', 'February', 'March',
\ 'April', 'May', 'June', 'July', 'August', 'September',
\ 'October', 'November', 'December'])
return ''
endfunc
inoremap <buffer> <F5> <C-R>=ListMonths()<CR>
call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx')
call assert_equal(['July'], getline(1,'$'))
" 1) Test completion when InsertCharPre kicks in
%d
call setline(1, 'J')
fu! DoIt()
if v:char=='u'
let v:char='an'
endif
endfu
au InsertCharPre <buffer> :call DoIt()
call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx')
call assert_equal(["Jan\<c-l>",''], getline(1,'$'))
%d
call setline(1, 'J')
call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx')
call assert_equal(["January"], getline(1,'$'))
delfu ListMonths
delfu DoIt
iunmap <buffer> <f5>
bw!
endfunc
func Test_edit_08()
" reset insertmode from i_ctrl-r_=
let g:bufnr = bufnr('%')
new
call setline(1, ['abc'])
call cursor(1, 4)
call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix')
call assert_equal(['abZZZc'], getline(1,'$'))
call assert_equal([0, 1, 1, 0], getpos('.'))
call assert_false(0, '&im')
bw!
unlet g:bufnr
endfunc
func Test_edit_09()
" test i_CTRL-\ combinations
new
call setline(1, ['abc', 'def', 'ghi'])
call cursor(1, 1)
" 1) CTRL-\ CTLR-N
call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin')
call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$'))
call setline(1, ['ABC', 'def', 'ghi'])
" 2) CTRL-\ CTLR-G
call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin')
call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin')
call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$'))
set noinsertmode
" 3) CTRL-\ CTRL-O
call setline(1, ['ABC', 'ZZZ', 'def', 'ghi'])
call cursor(1, 1)
call feedkeys("A\<c-o>ix", 'txin')
call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
call feedkeys("A\<c-\>\<c-o>ix", 'txin')
call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$'))
" 4) CTRL-\ a (should be inserted literally, not special after <c-\>
call setline(1, ['ABC', 'ZZZ', 'def', 'ghi'])
call cursor(1, 1)
call feedkeys("A\<c-\>a", 'txin')
call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$'))
bw!
endfunc
func Test_edit_10()
" Test for starting selectmode
new
set selectmode=key keymodel=startsel
call setline(1, ['abc', 'def', 'ghi'])
call cursor(1, 4)
call feedkeys("A\<s-home>start\<esc>", 'txin')
call assert_equal(['startdef', 'ghi'], getline(1, '$'))
set selectmode= keymodel=
bw!
endfunc
func Test_edit_11()
" Test that indenting kicks in
new
set cindent
call setline(1, ['{', '', ''])
call cursor(2, 1)
call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
call cursor(3, 1)
call feedkeys("i/* comment */", 'tnix')
call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$'))
" added changed cindentkeys slightly
set cindent cinkeys+=*/
call setline(1, ['{', '', ''])
call cursor(2, 1)
call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
call cursor(3, 1)
call feedkeys("i/* comment */", 'tnix')
call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$'))
set cindent cinkeys+==end
call feedkeys("oend\<cr>\<esc>", 'tnix')
call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$'))
set cinkeys-==end
%d
" Use indentexpr instead of cindenting
func! Do_Indent()
if v:lnum == 3
return 3*shiftwidth()
else
return 2*shiftwidth()
endif
endfunc
setl indentexpr=Do_Indent() indentkeys+=*/
call setline(1, ['{', '', ''])
call cursor(2, 1)
call feedkeys("i\<c-f>int c;\<esc>", 'tnix')
call cursor(3, 1)
call feedkeys("i/* comment */", 'tnix')
call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$'))
set cinkeys&vim indentkeys&vim
set nocindent indentexpr=
delfu Do_Indent
bw!
endfunc
func Test_edit_11_indentexpr()
" Test that indenting kicks in
new
" Use indentexpr instead of cindenting
func! Do_Indent()
let pline=prevnonblank(v:lnum)
if empty(getline(v:lnum))
if getline(pline) =~ 'if\|then'
return shiftwidth()
else
return 0
endif
else
return 0
endif
endfunc
setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi
call setline(1, ['if [ $this ]'])
call cursor(1, 1)
call feedkeys("othen\<cr>that\<cr>fi", 'tnix')
call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$'))
set cinkeys&vim indentkeys&vim
set nocindent indentexpr=
delfu Do_Indent
bw!
endfunc
func Test_edit_12()
" Test changing indent in replace mode
new
call setline(1, ["\tabc", "\tdef"])
call cursor(2, 4)
call feedkeys("R^\<c-d>", 'tnix')
call assert_equal(["\tabc", "def"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
%d
call setline(1, ["\tabc", "\t\tdef"])
call cursor(2, 2)
call feedkeys("R^\<c-d>", 'tnix')
call assert_equal(["\tabc", "def"], getline(1, '$'))
call assert_equal([0, 2, 1, 0], getpos('.'))
%d
call setline(1, ["\tabc", "\t\tdef"])
call cursor(2, 2)
call feedkeys("R\<c-t>", 'tnix')
call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
bw!
10vnew
call setline(1, ["\tabc", "\t\tdef"])
call cursor(2, 2)
call feedkeys("R\<c-t>", 'tnix')
call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
%d
set sw=4
call setline(1, ["\tabc", "\t\tdef"])
call cursor(2, 2)
call feedkeys("R\<c-t>\<c-t>", 'tnix')
call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
%d
call setline(1, ["\tabc", "\t\tdef"])
call cursor(2, 2)
call feedkeys("R\<c-t>\<c-t>", 'tnix')
call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$'))
call assert_equal([0, 2, 2, 0], getpos('.'))
set et
set sw& et&
%d
call setline(1, ["\t/*"])
set formatoptions=croql
call cursor(1, 3)
call feedkeys("A\<cr>\<cr>/", 'tnix')
call assert_equal(["\t/*", " *", " */"], getline(1, '$'))
set formatoptions&
bw!
endfunc
func Test_edit_13()
" Test smartindenting
if exists("+smartindent")
new
set smartindent autoindent
call setline(1, ["\tabc"])
call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix')
call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$'))
set smartindent& autoindent&
bw!
endif
endfunc
func Test_edit_CR()
" Test for <CR> in insert mode
" basically only in quickfix mode ist tested, the rest
" has been taken care of by other tests
if !has("quickfix")
return
endif
botright new
call writefile(range(1, 10), 'Xqflist.txt')
call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}])
copen
set modifiable
call feedkeys("A\<cr>", 'tnix')
call assert_equal('Xqflist.txt', bufname(''))
call assert_equal(2, line('.'))
cclose
botright new
call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}])
lopen
set modifiable
call feedkeys("A\<cr>", 'tnix')
call assert_equal('Xqflist.txt', bufname(''))
call assert_equal(10, line('.'))
call feedkeys("A\<Enter>", 'tnix')
call feedkeys("A\<kEnter>", 'tnix')
call feedkeys("A\n", 'tnix')
call feedkeys("A\r", 'tnix')
call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$'))
bw!
lclose
call delete('Xqflist.txt')
endfunc
func Test_edit_CTRL_()
" disabled for Windows builds, why?
if !has("rightleft") || has("win32")
return
endif
let _encoding=&encoding
set encoding=utf-8
" Test for CTRL-_
new
call setline(1, ['abc'])
call cursor(1, 1)
call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
call assert_equal(["\<C-_>xyzabc"], getline(1, '$'))
call assert_false(&revins)
set ari
call setline(1, ['abc'])
call cursor(1, 1)
call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
call assert_equal(["æèñabc"], getline(1, '$'))
call assert_true(&revins)
call setline(1, ['abc'])
call cursor(1, 1)
call feedkeys("i\<c-_>xyz\<esc>", 'tnix')
call assert_equal(["xyzabc"], getline(1, '$'))
call assert_false(&revins)
set noari
let &encoding=_encoding
bw!
endfunc
" needs to come first, to have the @. register empty
func Test_edit_00a_CTRL_A()
" Test pressing CTRL-A
new
call setline(1, repeat([''], 5))
call cursor(1, 1)
try
call feedkeys("A\<NUL>", 'tnix')
catch /^Vim\%((\a\+)\)\=:E29/
call assert_true(1, 'E29 error caught')
endtry
call cursor(1, 1)
call feedkeys("Afoobar \<esc>", 'tnix')
call cursor(2, 1)
call feedkeys("A\<c-a>more\<esc>", 'tnix')
call cursor(3, 1)
call feedkeys("A\<NUL>and more\<esc>", 'tnix')
call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$'))
bw!
endfunc
func Test_edit_CTRL_EY()
" Ctrl-E/ Ctrl-Y in insert mode completion to scroll
10new
call setline(1, range(1, 100))
call cursor(30, 1)
norm! z.
call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix')
call assert_equal(30, winsaveview()['topline'])
call assert_equal([0, 30, 2, 0], getpos('.'))
call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix')
call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix')
call assert_equal(21, winsaveview()['topline'])
call assert_equal([0, 30, 2, 0], getpos('.'))
bw!
endfunc
func Test_edit_CTRL_G()
new
call setline(1, ['foobar', 'foobar', 'foobar'])
call cursor(2, 4)
call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix')
call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$'))
call assert_equal([0, 1, 11, 0], getpos('.'))
call feedkeys("i\<c-g>k\<esc>", 'tnix')
call assert_equal([0, 1, 10, 0], getpos('.'))
call cursor(2, 4)
call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix')
call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$'))
call assert_equal([0, 3, 7, 0], getpos('.'))
call feedkeys("i\<c-g>j\<esc>", 'tnix')
call assert_equal([0, 3, 6, 0], getpos('.'))
bw!
endfunc
func Test_edit_CTRL_I()
" Tab in completion mode
let path=expand("%:p:h")
new
call setline(1, [path. "/", ''])
call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix')
call assert_match('runtest\.vim', getline(1))
%d
call writefile(['one', 'two', 'three'], 'Xinclude.txt')
let include='#include Xinclude.txt'
call setline(1, [include, ''])
call cursor(2, 1)
call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix')
call assert_equal([include, 'one', ''], getline(1, '$'))
call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix')
call assert_equal([include, 'two', ''], getline(1, '$'))
call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix')
call assert_equal([include, 'three', ''], getline(1, '$'))
call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
call assert_equal([include, '', ''], getline(1, '$'))
call delete("Xinclude.txt")
bw!
endfunc
func Test_edit_CTRL_K()
" Test pressing CTRL-K (basically only dictionary completion and digraphs
" the rest is already covered
call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt')
set dictionary=Xdictionary.txt
new
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix')
call assert_equal(['AA', ''], getline(1, '$'))
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix')
call assert_equal(['AAA'], getline(1, '$'))
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix')
call assert_equal(['AAAA'], getline(1, '$'))
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
call assert_equal(['A'], getline(1, '$'))
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
call assert_equal(['AA'], getline(1, '$'))
" press an unexecpted key after dictionary completion
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix')
call assert_equal(['AA', ''], getline(1, '$'))
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix')
call assert_equal(["AA\<c-s>", ''], getline(1, '$'))
%d
call setline(1, 'A')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix')
call assert_equal(["AA\<c-f>", ''], getline(1, '$'))
set dictionary=
%d
call setline(1, 'A')
call cursor(1, 1)
let v:testing = 1
try
call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix')
catch
" error sleeps 2 seconds, when v:testing is not set
let v:testing = 0
endtry
call delete('Xdictionary.txt')
call test_override("char_avail", 1)
set showcmd
%d
call feedkeys("A\<c-k>a:\<esc>", 'tnix')
call assert_equal(['ä'], getline(1, '$'))
call test_override("char_avail", 0)
set noshowcmd
bw!
endfunc
func Test_edit_CTRL_L()
" Test Ctrl-X Ctrl-L (line completion)
new
set complete=.
call setline(1, ['one', 'two', 'three', '', '', '', ''])
call cursor(4, 1)
call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$'))
call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$'))
set complete=
call cursor(5, 1)
call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix')
call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$'))
set complete&
%d
if has("conceal") && has("syntax")
call setline(1, ['foo', 'bar', 'foobar'])
call test_override("char_avail", 1)
set conceallevel=2 concealcursor=n
syn on
syn match ErrorMsg "^bar"
call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'})
func! DoIt()
let g:change=1
endfunc
au! TextChangedI <buffer> :call DoIt()
call cursor(2, 1)
call assert_false(exists("g:change"))
call feedkeys("A \<esc>", 'tnix')
call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$'))
call assert_equal(1, g:change)
call test_override("char_avail", 0)
call clearmatches()
syn off
au! TextChangedI
delfu DoIt
unlet! g:change
endif
bw!
endfunc
func Test_edit_CTRL_N()
" Check keyword completion
new
set complete=.
call setline(1, ['INFER', 'loWER', '', '', ])
call cursor(3, 1)
call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix")
call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$'))
%d
call setline(1, ['INFER', 'loWER', '', '', ])
call cursor(3, 1)
set ignorecase infercase
call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix")
call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$'))
set noignorecase noinfercase complete&
bw!
endfunc
func Test_edit_CTRL_O()
" Check for CTRL-O in insert mode
new
inoreabbr <buffer> h here some more
call setline(1, ['abc', 'def'])
call cursor(1, 1)
" Ctrl-O after an abbreviation
exe "norm A h\<c-o>:set nu\<cr> text"
call assert_equal(['abc here some more text', 'def'], getline(1, '$'))
call assert_true(&nu)
set nonu
iunabbr <buffer> h
" Ctrl-O at end of line with 've'=onemore
call cursor(1, 1)
call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix')
call assert_equal([0, 1, 23, 0], g:a)
call cursor(1, 1)
set ve=onemore
call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix')
call assert_equal([0, 1, 24, 0], g:a)
set ve=
unlet! g:a
bw!
endfunc
func Test_edit_CTRL_R()
" Insert Register
new
call test_override("ALL", 1)
set showcmd
call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix')
call feedkeys("O\<c-r>.", 'tnix')
call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix')
call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix')
call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$'))
call test_override("ALL", 0)
set noshowcmd
bw!
endfunc
func Test_edit_CTRL_S()
" Test pressing CTRL-S (basically only spellfile completion)
" the rest is already covered
new
if !has("spell")
call setline(1, 'vim')
call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix')
call assert_equal(['vims', ''], getline(1, '$'))
bw!
return
endif
call setline(1, 'vim')
" spell option not yet set
try
call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix')
catch /^Vim\%((\a\+)\)\=:E756/
call assert_true(1, 'error caught')
endtry
call assert_equal(['vim', ''], getline(1, '$'))
%d
setl spell spelllang=en
call setline(1, 'vim')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix')
call assert_equal(['Vim', ''], getline(1, '$'))
%d
call setline(1, 'vim')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix')
call assert_equal(['Aim'], getline(1, '$'))
%d
call setline(1, 'vim')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix')
call assert_equal(['vim', ''], getline(1, '$'))
%d
" empty buffer
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix')
call assert_equal(['', ''], getline(1, '$'))
setl nospell
bw!
endfunc
func Test_edit_CTRL_T()
" Check for CTRL-T and CTRL-X CTRL-T in insert mode
" 1) increase indent
new
call setline(1, "abc")
call cursor(1, 1)
call feedkeys("A\<c-t>xyz", 'tnix')
call assert_equal(["\<tab>abcxyz"], getline(1, '$'))
" 2) also when paste option is set
set paste
call setline(1, "abc")
call cursor(1, 1)
call feedkeys("A\<c-t>xyz", 'tnix')
call assert_equal(["\<tab>abcxyz"], getline(1, '$'))
set nopaste
" CTRL-X CTRL-T (thesaurus complete)
call writefile(['angry furious mad enraged'], 'Xthesaurus')
set thesaurus=Xthesaurus
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix')
call assert_equal(['mad', ''], getline(1, '$'))
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['angry', ''], getline(1, '$'))
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['furious', ''], getline(1, '$'))
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['enraged', ''], getline(1, '$'))
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['mad', ''], getline(1, '$'))
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['mad', ''], getline(1, '$'))
" Using <c-p> <c-n> when 'complete' is empty
set complete=
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['angry', ''], getline(1, '$'))
%d
call setline(1, 'mad')
call cursor(1, 1)
call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix')
call assert_equal(['mad', ''], getline(1, '$'))
set complete&
set thesaurus=
%d
call setline(1, 'mad')
call cursor(1, 1)
let v:testing = 1
try
call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix')
catch
" error sleeps 2 seconds, when v:testing is not set
let v:testing = 0
endtry
call assert_equal(['mad'], getline(1, '$'))
call delete('Xthesaurus')
bw!
endfunc
func Test_edit_CTRL_U()
" Test 'completefunc'
new
" -1, -2 and -3 are special return values
let g:special=0
fun! CompleteMonths(findstart, base)
if a:findstart
" locate the start of the word
return g:special
else
" find months matching with "a:base"
let res = []
for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
if m =~ '^\c'.a:base
call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0})
endif
endfor
return {'words': res, 'refresh': 'always'}
endif
endfun
set completefunc=CompleteMonths
call setline(1, ['', ''])
call cursor(1, 1)
call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
call assert_equal(['X', '', ''], getline(1, '$'))
%d
let g:special=-1
call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
call assert_equal(['XJan', ''], getline(1, '$'))
%d
let g:special=-2
call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
call assert_equal(['X', ''], getline(1, '$'))
%d
let g:special=-3
call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
call assert_equal(['X', ''], getline(1, '$'))
%d
let g:special=0
call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix')
call assert_equal(['Mar', ''], getline(1, '$'))
%d
call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['May', ''], getline(1, '$'))
%d
call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix')
call assert_equal(['M', ''], getline(1, '$'))
delfu CompleteMonths
%d
try
call feedkeys("A\<c-x>\<c-u>", 'tnix')
call assert_fails(1, 'unknown completion function')
catch /^Vim\%((\a\+)\)\=:E117/
call assert_true(1, 'E117 error caught')
endtry
set completefunc=
bw!
endfunc
func Test_edit_CTRL_Z()
" Ctrl-Z when insertmode is not set inserts it literally
new
call setline(1, 'abc')
call feedkeys("A\<c-z>\<esc>", 'tnix')
call assert_equal(["abc\<c-z>"], getline(1,'$'))
bw!
" TODO: How to Test Ctrl-Z in insert mode, e.g. suspend?
endfunc
func Test_edit_DROP()
if !has("dnd")
return
endif
new
call setline(1, ['abc def ghi'])
call cursor(1, 1)
try
call feedkeys("i\<Drop>\<Esc>", 'tnix')
call assert_fails(1, 'Invalid register name')
catch /^Vim\%((\a\+)\)\=:E353/
call assert_true(1, 'error caught')
endtry
bw!
endfunc
func Test_edit_CTRL_V()
if has("ebcdic")
return
endif
new
call setline(1, ['abc'])
call cursor(2, 1)
" force some redraws
set showmode showcmd
"call test_override_char_avail(1)
call test_override('ALL', 1)
call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix')
call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$'))
if has("rightleft") && exists("+rl")
set rl
call setline(1, ['abc'])
call cursor(2, 1)
call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix')
call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$'))
set norl
endif
call test_override('ALL', 0)
set noshowmode showcmd
bw!
endfunc
func Test_edit_F1()
" Pressing <f1>
new
call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix')
set noinsertmode
call assert_equal('help', &buftype)
bw
bw
endfunc
func Test_edit_F21()
" Pressing <f21>
" sends a netbeans command
if has("netbeans_intg")
new
" I have no idea what this is supposed to do :)
call feedkeys("A\<F21>\<F1>\<esc>", 'tnix')
bw
endif
endfunc
func Test_edit_HOME_END()
" Test Home/End Keys
new
set foldopen+=hor
call setline(1, ['abc', 'def'])
call cursor(1, 1)
call feedkeys("AX\<Home>Y\<esc>", 'tnix')
call cursor(2, 1)
call feedkeys("iZ\<End>Y\<esc>", 'tnix')
call assert_equal(['YabcX', 'ZdefY'], getline(1, '$'))
set foldopen-=hor
bw!
endfunc
func Test_edit_INS()
" Test for Pressing <Insert>
new
call setline(1, ['abc', 'def'])
call cursor(1, 1)
call feedkeys("i\<Insert>ZYX>", 'tnix')
call assert_equal(['ZYX>', 'def'], getline(1, '$'))
call setline(1, ['abc', 'def'])
call cursor(1, 1)
call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix')
call assert_equal(['ZYX>bc', 'def'], getline(1, '$'))
bw!
endfunc
func Test_edit_LEFT_RIGHT()
" Left, Shift-Left, Right, Shift-Right
new
call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX'])
let _ww=&ww
set ww=
call cursor(2, 1)
call feedkeys("i\<left>\<esc>", 'tnix')
call assert_equal([0, 2, 1, 0], getpos('.'))
" Is this a bug, <s-left> does not respect whichwrap option
call feedkeys("i\<s-left>\<esc>", 'tnix')
call assert_equal([0, 1, 8, 0], getpos('.'))
call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix')
call assert_equal([0, 1, 1, 0], getpos('.'))
call feedkeys("i\<right>\<esc>", 'tnix')
call assert_equal([0, 1, 1, 0], getpos('.'))
call feedkeys("i\<right>\<right>\<esc>", 'tnix')
call assert_equal([0, 1, 2, 0], getpos('.'))
call feedkeys("A\<right>\<esc>", 'tnix')
call assert_equal([0, 1, 11, 0], getpos('.'))
call feedkeys("A\<s-right>\<esc>", 'tnix')
call assert_equal([0, 2, 1, 0], getpos('.'))
call feedkeys("i\<s-right>\<esc>", 'tnix')
call assert_equal([0, 2, 4, 0], getpos('.'))
call cursor(3, 11)
call feedkeys("A\<right>\<esc>", 'tnix')
call feedkeys("A\<s-right>\<esc>", 'tnix')
call assert_equal([0, 3, 11, 0], getpos('.'))
call cursor(2, 11)
" <S-Right> does not respect 'whichwrap' option
call feedkeys("A\<s-right>\<esc>", 'tnix')
call assert_equal([0, 3, 1, 0], getpos('.'))
" Check motion when 'whichwrap' contains cursor keys for insert mode
set ww+=[,]
call cursor(2, 1)
call feedkeys("i\<left>\<esc>", 'tnix')
call assert_equal([0, 1, 11, 0], getpos('.'))
call cursor(2, 11)
call feedkeys("A\<right>\<esc>", 'tnix')
call assert_equal([0, 3, 1, 0], getpos('.'))
call cursor(2, 11)
call feedkeys("A\<s-right>\<esc>", 'tnix')
call assert_equal([0, 3, 1, 0], getpos('.'))
let &ww = _ww
bw!
endfunc
func Test_edit_MOUSE()
" This is a simple test, since we not really using the mouse here
if !has("mouse")
return
endif
10new
call setline(1, range(1, 100))
call cursor(1, 1)
set mouse=a
call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix')
call assert_equal([0, 4, 1, 0], getpos('.'))
" This should move by one pageDown, but only moves
" by one line when the test is run...
call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix')
call assert_equal([0, 5, 1, 0], getpos('.'))
set nostartofline
call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix')
call assert_equal([0, 6, 1, 0], getpos('.'))
call feedkeys("A\<LeftMouse>\<esc>", 'tnix')
call assert_equal([0, 6, 1, 0], getpos('.'))
call feedkeys("A\<RightMouse>\<esc>", 'tnix')
call assert_equal([0, 6, 1, 0], getpos('.'))
call cursor(1, 100)
norm! zt
" this should move by a screen up, but when the test
" is run, it moves up to the top of the buffer...
call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix')
call assert_equal([0, 1, 1, 0], getpos('.'))
call cursor(1, 30)
norm! zt
call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix')
call assert_equal([0, 1, 1, 0], getpos('.'))
call cursor(1, 30)
norm! zt
call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix')
call assert_equal([0, 1, 1, 0], getpos('.'))
%d
call setline(1, repeat(["12345678901234567890"], 100))
call cursor(2, 1)
call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix')
call assert_equal([0, 2, 20, 0], getpos('.'))
call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix')
call assert_equal([0, 2, 20, 0], getpos('.'))
call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix')
call assert_equal([0, 2, 20, 0], getpos('.'))
call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix')
call assert_equal([0, 2, 20, 0], getpos('.'))
call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix')
call assert_equal([0, 2, 20, 0], getpos('.'))
call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix')
call assert_equal([0, 2, 20, 0], getpos('.'))
set mouse& startofline
bw!
endfunc
func Test_edit_PAGEUP_PAGEDOWN()
10new
call setline(1, repeat(['abc def ghi'], 30))
call cursor(1, 1)
call feedkeys("i\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 9, 1, 0], getpos('.'))
call feedkeys("i\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 17, 1, 0], getpos('.'))
call feedkeys("i\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 25, 1, 0], getpos('.'))
call feedkeys("i\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 30, 1, 0], getpos('.'))
call feedkeys("i\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 30, 1, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 29, 1, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 21, 1, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 13, 1, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 5, 1, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 5, 11, 0], getpos('.'))
" <S-Up> is the same as <PageUp>
" <S-Down> is the same as <PageDown>
call cursor(1, 1)
call feedkeys("i\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 9, 1, 0], getpos('.'))
call feedkeys("i\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 17, 1, 0], getpos('.'))
call feedkeys("i\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 25, 1, 0], getpos('.'))
call feedkeys("i\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 30, 1, 0], getpos('.'))
call feedkeys("i\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 30, 1, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 29, 1, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 21, 1, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 13, 1, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 5, 1, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 5, 11, 0], getpos('.'))
set nostartofline
call cursor(30, 11)
norm! zt
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 29, 11, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 21, 11, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 13, 11, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 5, 11, 0], getpos('.'))
call feedkeys("A\<PageUp>\<esc>", 'tnix')
call assert_equal([0, 5, 11, 0], getpos('.'))
call cursor(1, 1)
call feedkeys("A\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 9, 11, 0], getpos('.'))
call feedkeys("A\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 17, 11, 0], getpos('.'))
call feedkeys("A\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 25, 11, 0], getpos('.'))
call feedkeys("A\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 30, 11, 0], getpos('.'))
call feedkeys("A\<PageDown>\<esc>", 'tnix')
call assert_equal([0, 30, 11, 0], getpos('.'))
" <S-Up> is the same as <PageUp>
" <S-Down> is the same as <PageDown>
call cursor(30, 11)
norm! zt
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 29, 11, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 21, 11, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 13, 11, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 5, 11, 0], getpos('.'))
call feedkeys("A\<S-Up>\<esc>", 'tnix')
call assert_equal([0, 5, 11, 0], getpos('.'))
call cursor(1, 1)
call feedkeys("A\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 9, 11, 0], getpos('.'))
call feedkeys("A\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 17, 11, 0], getpos('.'))
call feedkeys("A\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 25, 11, 0], getpos('.'))
call feedkeys("A\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 30, 11, 0], getpos('.'))
call feedkeys("A\<S-Down>\<esc>", 'tnix')
call assert_equal([0, 30, 11, 0], getpos('.'))
bw!
endfunc
func Test_edit_forbidden()
new
" 1) edit in the sandbox is not allowed
call setline(1, 'a')
com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix')
call assert_fails(':Sandbox', 'E48:')
com! Sandbox :sandbox exe "norm! i\<del>"
call assert_fails(':Sandbox', 'E48:')
delcom Sandbox
call assert_equal(['a'], getline(1,'$'))
" 2) edit with textlock set
fu! DoIt()
call feedkeys("i\<del>\<esc>", 'tnix')
endfu
au InsertCharPre <buffer> :call DoIt()
try
call feedkeys("ix\<esc>", 'tnix')
call assert_fails(1, 'textlock')
catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here
endtry
" TODO: Might be a bug: should x really be inserted here
call assert_equal(['xa'], getline(1, '$'))
delfu DoIt
try
call feedkeys("ix\<esc>", 'tnix')
call assert_fails(1, 'unknown function')
catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function
endtry
au! InsertCharPre
" 3) edit when completion is shown
fun! Complete(findstart, base)
if a:findstart
return col('.')
else
call feedkeys("i\<del>\<esc>", 'tnix')
return []
endif
endfun
set completefunc=Complete
try
call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix')
call assert_fails(1, 'change in complete function')
catch /^Vim\%((\a\+)\)\=:E523/ " catch E523
endtry
delfu Complete
set completefunc=
if has("rightleft") && exists("+fkmap")
" 4) 'R' when 'fkmap' and 'revins' is set.
set revins fkmap
try
normal Ri
call assert_fails(1, "R with 'fkmap' and 'ri' set")
catch
finally
set norevins nofkmap
endtry
endif
bw!
endfunc
func Test_edit_rightleft()
" Cursor in rightleft mode moves differently
if !exists("+rightleft")
return
endif
call NewWindow(10, 20)
call setline(1, ['abc', 'def', 'ghi'])
call cursor(1, 2)
set rightleft
" Screen looks as expected
let lines = ScreenLines([1, 4], winwidth(0))
let expect = [
\" cba",
\" fed",
\" ihg",
\" ~"]
call assert_equal(join(expect, "\n"), join(lines, "\n"))
" 2) right moves to the left
call feedkeys("i\<right>\<esc>x", 'txin')
call assert_equal(['bc', 'def', 'ghi'], getline(1,'$'))
call cursor(1, 2)
call feedkeys("i\<s-right>\<esc>", 'txin')
call cursor(1, 2)
call feedkeys("i\<c-right>\<esc>", 'txin')
" Screen looks as expected
let lines = ScreenLines([1, 4], winwidth(0))
let expect = [
\" cb",
\" fed",
\" ihg",
\" ~"]
call assert_equal(join(expect, "\n"), join(lines, "\n"))
" 2) left moves to the right
call setline(1, ['abc', 'def', 'ghi'])
call cursor(1, 2)
call feedkeys("i\<left>\<esc>x", 'txin')
call assert_equal(['ac', 'def', 'ghi'], getline(1,'$'))
call cursor(1, 2)
call feedkeys("i\<s-left>\<esc>", 'txin')
call cursor(1, 2)
call feedkeys("i\<c-left>\<esc>", 'txin')
" Screen looks as expected
let lines = ScreenLines([1, 4], winwidth(0))
let expect = [
\" ca",
\" fed",
\" ihg",
\" ~"]
call assert_equal(join(expect, "\n"), join(lines, "\n"))
set norightleft
bw!
endfunc
func Test_edit_complete_very_long_name()
if !has('unix')
" Long directory names only work on Unix.
return
endif
let dirname = getcwd() . "/Xdir"
let longdirname = dirname . repeat('/' . repeat('d', 255), 4)
try
call mkdir(longdirname, 'p')
catch /E739:/
" Long directory name probably not supported.
call delete(dirname, 'rf')
return
endtry
" Try to get the Vim window position before setting 'columns'.
let winposx = getwinposx()
let winposy = getwinposy()
let save_columns = &columns
" Need at least about 1100 columns to reproduce the problem.
set columns=2000
set noswapfile
let longfilename = longdirname . '/' . repeat('a', 255)
call writefile(['Totum', 'Table'], longfilename)
new
exe "next Xfile " . longfilename
exe "normal iT\<C-N>"
bwipe!
exe 'bwipe! ' . longfilename
call delete(dirname, 'rf')
let &columns = save_columns
if winposx >= 0 && winposy >= 0
exe 'winpos ' . winposx . ' ' . winposy
endif
set swapfile&
endfunc
func Test_edit_backtick()
next a\`b c
call assert_equal('a`b', expand('%'))
next
call assert_equal('c', expand('%'))
call assert_equal('a\`b c', expand('##'))
endfunc
func Test_edit_quit()
edit foo.txt
split
new
call setline(1, 'hello')
3wincmd w
redraw!
call assert_fails('1q', 'E37:')
bwipe! foo.txt
only
endfunc
func Test_edit_alt()
" Keeping the cursor line didn't happen when the first line has indent.
new
call setline(1, [' one', 'two', 'three'])
w XAltFile
$
call assert_equal(3, line('.'))
e Xother
e #
call assert_equal(3, line('.'))
bwipe XAltFile
call delete('XAltFile')
endfunc
func Test_leave_insert_autocmd()
new
au InsertLeave * let g:did_au = 1
let g:did_au = 0
call feedkeys("afoo\<Esc>", 'tx')
call assert_equal(1, g:did_au)
call assert_equal('foo', getline(1))
let g:did_au = 0
call feedkeys("Sbar\<C-C>", 'tx')
call assert_equal(0, g:did_au)
call assert_equal('bar', getline(1))
inoremap x xx<Esc>
let g:did_au = 0
call feedkeys("Saax", 'tx')
call assert_equal(1, g:did_au)
call assert_equal('aaxx', getline(1))
inoremap x xx<C-C>
let g:did_au = 0
call feedkeys("Sbbx", 'tx')
call assert_equal(0, g:did_au)
call assert_equal('bbxx', getline(1))
bwipe!
au! InsertLeave
iunmap x
endfunc
|