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
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
|
" Test for various Normal mode commands
source shared.vim
source check.vim
source view_util.vim
func Setup_NewWindow()
10new
call setline(1, range(1,100))
endfunc
func MyFormatExpr()
" Adds '->$' at lines having numbers followed by trailing whitespace
for ln in range(v:lnum, v:lnum+v:count-1)
let line = getline(ln)
if getline(ln) =~# '\d\s\+$'
call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
endif
endfor
endfunc
func CountSpaces(type, ...)
" for testing operatorfunc
" will count the number of spaces
" and return the result in g:a
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
let &selection = sel_save
let @@ = reg_save
endfunc
func OpfuncDummy(type, ...)
" for testing operatorfunc
let g:opt=&linebreak
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
" Create a new dummy window
new
let g:bufnr=bufnr('%')
endfunc
func Test_normal00_optrans()
new
call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
1
exe "norm! Sfoobar\<esc>"
call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
2
exe "norm! $vbsone"
call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
norm! VS Second line here
call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
%d
call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
1
norm! 2D
call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
set cpo+=#
norm! 4D
call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
" clean up
set cpo-=#
bw!
endfunc
func Test_normal01_keymodel()
call Setup_NewWindow()
" Test 1: depending on 'keymodel' <s-down> does something different
50
call feedkeys("V\<S-Up>y", 'tx')
call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
set keymodel=startsel
50
call feedkeys("V\<S-Up>y", 'tx')
call assert_equal(['49', '50'], getline("'<", "'>"))
" Start visual mode when keymodel = startsel
50
call feedkeys("\<S-Up>y", 'tx')
call assert_equal(['49', '5'], getreg(0, 0, 1))
" Use the different Shift special keys
50
call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
call assert_equal(['50'], getline("'<", "'>"))
call assert_equal(['50', ''], getreg(0, 0, 1))
" Do not start visual mode when keymodel=
set keymodel=
50
call feedkeys("\<S-Up>y$", 'tx')
call assert_equal(['42'], getreg(0, 0, 1))
" Stop visual mode when keymodel=stopsel
set keymodel=stopsel
50
call feedkeys("Vkk\<Up>yy", 'tx')
call assert_equal(['47'], getreg(0, 0, 1))
set keymodel=
50
call feedkeys("Vkk\<Up>yy", 'tx')
call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
" Test for using special keys to start visual selection
%d
call setline(1, ['red fox tail', 'red fox tail', 'red fox tail'])
set keymodel=startsel
" Test for <S-PageUp> and <S-PageDown>
call cursor(1, 1)
call feedkeys("\<S-PageDown>y", 'xt')
call assert_equal([0, 1, 1, 0], getpos("'<"))
call assert_equal([0, 3, 1, 0], getpos("'>"))
call feedkeys("Gz\<CR>8|\<S-PageUp>y", 'xt')
call assert_equal([0, 2, 1, 0], getpos("'<"))
call assert_equal([0, 3, 8, 0], getpos("'>"))
" Test for <S-C-Home> and <S-C-End>
call cursor(2, 12)
call feedkeys("\<S-C-Home>y", 'xt')
call assert_equal([0, 1, 1, 0], getpos("'<"))
call assert_equal([0, 2, 12, 0], getpos("'>"))
call cursor(1, 4)
call feedkeys("\<S-C-End>y", 'xt')
call assert_equal([0, 1, 4, 0], getpos("'<"))
call assert_equal([0, 3, 13, 0], getpos("'>"))
" Test for <S-C-Left> and <S-C-Right>
call cursor(2, 5)
call feedkeys("\<S-C-Right>y", 'xt')
call assert_equal([0, 2, 5, 0], getpos("'<"))
call assert_equal([0, 2, 9, 0], getpos("'>"))
call cursor(2, 9)
call feedkeys("\<S-C-Left>y", 'xt')
call assert_equal([0, 2, 5, 0], getpos("'<"))
call assert_equal([0, 2, 9, 0], getpos("'>"))
set keymodel&
" clean up
bw!
endfunc
func Test_normal03_join()
" basic join test
call Setup_NewWindow()
50
norm! VJ
call assert_equal('50 51', getline('.'))
$
norm! J
call assert_equal('100', getline('.'))
$
norm! V9-gJ
call assert_equal('919293949596979899100', getline('.'))
call setline(1, range(1,100))
$
:j 10
call assert_equal('100', getline('.'))
call assert_beeps('normal GVJ')
" clean up
bw!
endfunc
" basic filter test
func Test_normal04_filter()
" only test on non windows platform
CheckNotMSWindows
call Setup_NewWindow()
1
call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
call assert_equal('| 1', getline('.'))
90
:sil :!echo one
call feedkeys('.', 'tx')
call assert_equal('| 90', getline('.'))
95
set cpo+=!
" 2 <CR>, 1: for executing the command,
" 2: clear hit-enter-prompt
call feedkeys("!!\n", 'tx')
call feedkeys(":!echo one\n\n", 'tx')
call feedkeys(".", 'tx')
call assert_equal('one', getline('.'))
set cpo-=!
bw!
endfunc
func Test_normal05_formatexpr()
" basic formatexpr test
call Setup_NewWindow()
%d_
call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
1
set formatexpr=MyFormatExpr()
norm! gqG
call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
set formatexpr=
bw!
endfunc
func Test_normal05_formatexpr_newbuf()
" Edit another buffer in the 'formatexpr' function
new
func! Format()
edit another
endfunc
set formatexpr=Format()
norm gqG
bw!
set formatexpr=
endfunc
func Test_normal05_formatexpr_setopt()
" Change the 'formatexpr' value in the function
new
func! Format()
set formatexpr=
endfunc
set formatexpr=Format()
norm gqG
bw!
set formatexpr=
endfunc
" When 'formatexpr' returns non-zero, internal formatting is used.
func Test_normal_formatexpr_returns_nonzero()
new
call setline(1, ['one', 'two'])
func! Format()
return 1
endfunc
setlocal formatexpr=Format()
normal VGgq
call assert_equal(['one two'], getline(1, '$'))
setlocal formatexpr=
delfunc Format
close!
endfunc
" basic test for formatprg
func Test_normal06_formatprg()
" only test on non windows platform
CheckNotMSWindows
" uses sed to number non-empty lines
call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
call system('chmod +x ./Xsed_format.sh')
let text = ['a', '', 'c', '', ' ', 'd', 'e']
let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
10new
call setline(1, text)
set formatprg=./Xsed_format.sh
norm! gggqG
call assert_equal(expected, getline(1, '$'))
%d
call setline(1, text)
set formatprg=donothing
setlocal formatprg=./Xsed_format.sh
norm! gggqG
call assert_equal(expected, getline(1, '$'))
%d
" Check for the command-line ranges added to 'formatprg'
set formatprg=cat
call setline(1, ['one', 'two', 'three', 'four', 'five'])
call feedkeys('gggqG', 'xt')
call assert_equal('.,$!cat', @:)
call feedkeys('2Ggq2j', 'xt')
call assert_equal('.,.+2!cat', @:)
bw!
" clean up
set formatprg=
setlocal formatprg=
call delete('Xsed_format.sh')
endfunc
func Test_normal07_internalfmt()
" basic test for internal formmatter to textwidth of 12
let list=range(1,11)
call map(list, 'v:val." "')
10new
call setline(1, list)
set tw=12
norm! ggVGgq
call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
" clean up
set tw=0
bw!
endfunc
" basic tests for foldopen/folddelete
func Test_normal08_fold()
CheckFeature folding
call Setup_NewWindow()
50
setl foldenable fdm=marker
" First fold
norm! V4jzf
" check that folds have been created
call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
" Second fold
46
norm! V10jzf
" check that folds have been created
call assert_equal('46/*{{{*/', getline(46))
call assert_equal('60/*}}}*/', getline(60))
norm! k
call assert_equal('45', getline('.'))
norm! j
call assert_equal('46/*{{{*/', getline('.'))
norm! j
call assert_equal('61', getline('.'))
norm! k
" open a fold
norm! Vzo
norm! k
call assert_equal('45', getline('.'))
norm! j
call assert_equal('46/*{{{*/', getline('.'))
norm! j
call assert_equal('47', getline('.'))
norm! k
norm! zcVzO
call assert_equal('46/*{{{*/', getline('.'))
norm! j
call assert_equal('47', getline('.'))
norm! j
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51', getline('.'))
" delete folds
:46
" collapse fold
norm! V14jzC
" delete all folds recursively
norm! VzD
call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
" clean up
setl nofoldenable fdm=marker
bw!
endfunc
func Test_normal09_operatorfunc()
" Test operatorfunc
call Setup_NewWindow()
" Add some spaces for counting
50,60s/$/ /
unlet! g:a
let g:a=0
nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
50
norm V2j,,
call assert_equal(6, g:a)
norm V,,
call assert_equal(2, g:a)
norm ,,l
call assert_equal(0, g:a)
50
exe "norm 0\<c-v>10j2l,,"
call assert_equal(11, g:a)
50
norm V10j,,
call assert_equal(22, g:a)
" clean up
unmap <buffer> ,,
set opfunc=
unlet! g:a
bw!
endfunc
func Test_normal09a_operatorfunc()
" Test operatorfunc
call Setup_NewWindow()
" Add some spaces for counting
50,60s/$/ /
unlet! g:opt
set linebreak
nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
50
norm ,,j
exe "bd!" g:bufnr
call assert_true(&linebreak)
call assert_equal(g:opt, &linebreak)
set nolinebreak
norm ,,j
exe "bd!" g:bufnr
call assert_false(&linebreak)
call assert_equal(g:opt, &linebreak)
" clean up
unmap <buffer> ,,
set opfunc=
call assert_fails('normal Vg@', 'E774:')
bw!
unlet! g:opt
endfunc
func Test_normal10_expand()
" Test for expand()
10new
call setline(1, ['1', 'ifooar,,cbar'])
2
norm! $
call assert_equal('cbar', expand('<cword>'))
call assert_equal('ifooar,,cbar', expand('<cWORD>'))
call setline(1, ['prx = list[idx];'])
1
let expected = ['', 'prx', 'prx', 'prx',
\ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
\ 'idx', 'idx', 'idx', 'idx',
\ 'list[idx]',
\ '];',
\ ]
for i in range(1, 16)
exe 'norm ' . i . '|'
call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
endfor
" Test for <cexpr> in state.val and ptr->val
call setline(1, 'x = state.val;')
call cursor(1, 10)
call assert_equal('state.val', expand('<cexpr>'))
call setline(1, 'x = ptr->val;')
call cursor(1, 9)
call assert_equal('ptr->val', expand('<cexpr>'))
if executable('echo')
" Test expand(`...`) i.e. backticks command expansion.
call assert_equal('abcde', expand('`echo abcde`'))
endif
" Test expand(`=...`) i.e. backticks expression expansion
call assert_equal('5', expand('`=2+3`'))
call assert_equal('3.14', expand('`=3.14`'))
" clean up
bw!
endfunc
" Test for expand() in latin1 encoding
func Test_normal_expand_latin1()
new
let save_enc = &encoding
set encoding=latin1
call setline(1, 'val = item->color;')
call cursor(1, 11)
call assert_equal('color', expand("<cword>"))
call assert_equal('item->color', expand("<cexpr>"))
let &encoding = save_enc
bw!
endfunc
func Test_normal11_showcmd()
" test for 'showcmd'
10new
exe "norm! ofoobar\<esc>"
call assert_equal(2, line('$'))
set showcmd
exe "norm! ofoobar2\<esc>"
call assert_equal(3, line('$'))
exe "norm! VAfoobar3\<esc>"
call assert_equal(3, line('$'))
exe "norm! 0d3\<del>2l"
call assert_equal('obar2foobar3', getline('.'))
" test for the visual block size displayed in the status line
call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
call feedkeys("ggl\<C-V>lljj", 'xt')
redraw!
call assert_match('3x3$', Screenline(&lines))
call feedkeys("\<C-V>", 'xt')
" test for visually selecting a multi-byte character
call setline(1, ["\U2206"])
call feedkeys("ggv", 'xt')
redraw!
call assert_match('1-3$', Screenline(&lines))
call feedkeys("v", 'xt')
" test for visually selecting the end of line
call setline(1, ["foobar"])
call feedkeys("$vl", 'xt')
redraw!
call assert_match('2$', Screenline(&lines))
call feedkeys("y", 'xt')
call assert_equal("r\n", @")
bw!
endfunc
" Test for nv_error and normal command errors
func Test_normal12_nv_error()
10new
call setline(1, range(1,5))
" should not do anything, just beep
call assert_beeps('exe "norm! <c-k>"')
call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
call assert_beeps('normal! G2dd')
call assert_beeps("normal! g\<C-A>")
call assert_beeps("normal! g\<C-X>")
call assert_beeps("normal! g\<C-B>")
call assert_beeps("normal! vQ\<Esc>")
call assert_beeps("normal! 2[[")
call assert_beeps("normal! 2]]")
call assert_beeps("normal! 2[]")
call assert_beeps("normal! 2][")
call assert_beeps("normal! 4[z")
call assert_beeps("normal! 4]z")
call assert_beeps("normal! 4[c")
call assert_beeps("normal! 4]c")
call assert_beeps("normal! 200%")
call assert_beeps("normal! %")
call assert_beeps("normal! 2{")
call assert_beeps("normal! 2}")
call assert_beeps("normal! r\<Right>")
call assert_beeps("normal! 8ry")
call assert_beeps('normal! "@')
bw!
endfunc
func Test_normal13_help()
" Test for F1
call assert_equal(1, winnr())
call feedkeys("\<f1>", 'txi')
call assert_match('help\.txt', bufname('%'))
call assert_equal(2, winnr('$'))
bw!
endfunc
func Test_normal14_page()
" basic test for Ctrl-F and Ctrl-B
call Setup_NewWindow()
exe "norm! \<c-f>"
call assert_equal('9', getline('.'))
exe "norm! 2\<c-f>"
call assert_equal('25', getline('.'))
exe "norm! 2\<c-b>"
call assert_equal('18', getline('.'))
1
set scrolloff=5
exe "norm! 2\<c-f>"
call assert_equal('21', getline('.'))
exe "norm! \<c-b>"
call assert_equal('13', getline('.'))
1
set scrolloff=99
exe "norm! \<c-f>"
call assert_equal('13', getline('.'))
set scrolloff=0
100
exe "norm! $\<c-b>"
call assert_equal('92', getline('.'))
call assert_equal([0, 92, 1, 0, 1], getcurpos())
100
set nostartofline
exe "norm! $\<c-b>"
call assert_equal('92', getline('.'))
call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
" cleanup
set startofline
bw!
endfunc
func Test_normal14_page_eol()
10new
norm oxxxxxxx
exe "norm 2\<c-f>"
" check with valgrind that cursor is put back in column 1
exe "norm 2\<c-b>"
bw!
endfunc
" Test for errors with z command
func Test_normal_z_error()
call assert_beeps('normal! z2p')
call assert_beeps('normal! zp')
endfunc
func Test_normal15_z_scroll_vert()
" basic test for z commands that scroll the window
call Setup_NewWindow()
100
norm! >>
" Test for z<cr>
exe "norm! z\<cr>"
call assert_equal(' 100', getline('.'))
call assert_equal(100, winsaveview()['topline'])
call assert_equal([0, 100, 2, 0, 9], getcurpos())
" Test for zt
21
norm! >>0zt
call assert_equal(' 21', getline('.'))
call assert_equal(21, winsaveview()['topline'])
call assert_equal([0, 21, 1, 0, 8], getcurpos())
" Test for zb
30
norm! >>$ztzb
call assert_equal(' 30', getline('.'))
call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
" Test for z-
1
30
norm! 0z-
call assert_equal(' 30', getline('.'))
call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
call assert_equal([0, 30, 2, 0, 9], getcurpos())
" Test for z{height}<cr>
call assert_equal(10, winheight(0))
exe "norm! z12\<cr>"
call assert_equal(12, winheight(0))
exe "norm! z10\<cr>"
call assert_equal(10, winheight(0))
" Test for z.
1
21
norm! 0z.
call assert_equal(' 21', getline('.'))
call assert_equal(17, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" Test for zz
1
21
norm! 0zz
call assert_equal(' 21', getline('.'))
call assert_equal(17, winsaveview()['topline'])
call assert_equal([0, 21, 1, 0, 8], getcurpos())
" Test for z+
11
norm! zt
norm! z+
call assert_equal(' 21', getline('.'))
call assert_equal(21, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" Test for [count]z+
1
norm! 21z+
call assert_equal(' 21', getline('.'))
call assert_equal(21, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" Test for z+ with [count] greater than buffer size
1
norm! 1000z+
call assert_equal(' 100', getline('.'))
call assert_equal(100, winsaveview()['topline'])
call assert_equal([0, 100, 2, 0, 9], getcurpos())
" Test for z+ from the last buffer line
norm! Gz.z+
call assert_equal(' 100', getline('.'))
call assert_equal(100, winsaveview()['topline'])
call assert_equal([0, 100, 2, 0, 9], getcurpos())
" Test for z^
norm! 22z+0
norm! z^
call assert_equal(' 21', getline('.'))
call assert_equal(12, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" Test for z^ from first buffer line
norm! ggz^
call assert_equal('1', getline('.'))
call assert_equal(1, winsaveview()['topline'])
call assert_equal([0, 1, 1, 0, 1], getcurpos())
" Test for [count]z^
1
norm! 30z^
call assert_equal(' 21', getline('.'))
call assert_equal(12, winsaveview()['topline'])
call assert_equal([0, 21, 2, 0, 9], getcurpos())
" cleanup
bw!
endfunc
func Test_normal16_z_scroll_hor()
" basic test for z commands that scroll the window
10new
15vsp
set nowrap listchars=
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
$put =lineA
$put =lineB
1d
" Test for zl and zh with a count
norm! 0z10l
call assert_equal([11, 1], [col('.'), wincol()])
norm! z4h
call assert_equal([11, 5], [col('.'), wincol()])
normal! 2gg
" Test for zl
1
norm! 5zl
call assert_equal(lineA, getline('.'))
call assert_equal(6, col('.'))
call assert_equal(5, winsaveview()['leftcol'])
norm! yl
call assert_equal('f', @0)
" Test for zh
norm! 2zh
call assert_equal(lineA, getline('.'))
call assert_equal(6, col('.'))
norm! yl
call assert_equal('f', @0)
call assert_equal(3, winsaveview()['leftcol'])
" Test for zL
norm! zL
call assert_equal(11, col('.'))
norm! yl
call assert_equal('k', @0)
call assert_equal(10, winsaveview()['leftcol'])
norm! 2zL
call assert_equal(25, col('.'))
norm! yl
call assert_equal('y', @0)
call assert_equal(24, winsaveview()['leftcol'])
" Test for zH
norm! 2zH
call assert_equal(25, col('.'))
call assert_equal(10, winsaveview()['leftcol'])
norm! yl
call assert_equal('y', @0)
" Test for zs
norm! $zs
call assert_equal(26, col('.'))
call assert_equal(25, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" Test for ze
norm! ze
call assert_equal(26, col('.'))
call assert_equal(11, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" Test for zs and ze with folds
%fold
norm! $zs
call assert_equal(26, col('.'))
call assert_equal(0, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
norm! ze
call assert_equal(26, col('.'))
call assert_equal(0, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" cleanup
set wrap listchars=eol:$
bw!
endfunc
func Test_normal17_z_scroll_hor2()
" basic test for z commands that scroll the window
" using 'sidescrolloff' setting
10new
20vsp
set nowrap listchars= sidescrolloff=5
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
$put =lineA
$put =lineB
1d
" Test for zl
1
norm! 5zl
call assert_equal(lineA, getline('.'))
call assert_equal(11, col('.'))
call assert_equal(5, winsaveview()['leftcol'])
norm! yl
call assert_equal('k', @0)
" Test for zh
norm! 2zh
call assert_equal(lineA, getline('.'))
call assert_equal(11, col('.'))
norm! yl
call assert_equal('k', @0)
call assert_equal(3, winsaveview()['leftcol'])
" Test for zL
norm! 0zL
call assert_equal(16, col('.'))
norm! yl
call assert_equal('p', @0)
call assert_equal(10, winsaveview()['leftcol'])
norm! 2zL
call assert_equal(26, col('.'))
norm! yl
call assert_equal('z', @0)
call assert_equal(15, winsaveview()['leftcol'])
" Test for zH
norm! 2zH
call assert_equal(15, col('.'))
call assert_equal(0, winsaveview()['leftcol'])
norm! yl
call assert_equal('o', @0)
" Test for zs
norm! $zs
call assert_equal(26, col('.'))
call assert_equal(20, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" Test for ze
norm! ze
call assert_equal(26, col('.'))
call assert_equal(11, winsaveview()['leftcol'])
norm! yl
call assert_equal('z', @0)
" cleanup
set wrap listchars=eol:$ sidescrolloff=0
bw!
endfunc
" Test for commands that scroll the window horizontally. Test with folds.
" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
func Test_vert_scroll_cmds()
15new
call setline(1, range(1, 100))
exe "normal! 30ggz\<CR>"
set foldenable
33,36fold
40,43fold
46,49fold
let h = winheight(0)
" Test for H, M and L commands
" Top of the screen = 30
" Folded lines = 9
" Bottom of the screen = 30 + h + 9 - 1
normal! 4L
call assert_equal(35 + h, line('.'))
normal! 4H
call assert_equal(33, line('.'))
" Test for using a large count value
%d
call setline(1, range(1, 4))
norm! 6H
call assert_equal(4, line('.'))
" Test for 'M' with folded lines
%d
call setline(1, range(1, 20))
1,5fold
norm! LM
call assert_equal(12, line('.'))
" Test for the CTRL-E and CTRL-Y commands with folds
%d
call setline(1, range(1, 10))
3,5fold
exe "normal 6G3\<C-E>"
call assert_equal(6, line('w0'))
exe "normal 2\<C-Y>"
call assert_equal(2, line('w0'))
" Test for CTRL-Y on a folded line
%d
call setline(1, range(1, 100))
exe (h + 2) .. "," .. (h + 4) .. "fold"
exe h + 5
normal z-
exe "normal \<C-Y>\<C-Y>"
call assert_equal(h + 1, line('w$'))
" Test for CTRL-Y from the first line and CTRL-E from the last line
%d
set scrolloff=2
call setline(1, range(1, 4))
exe "normal gg\<C-Y>"
call assert_equal(1, line('w0'))
call assert_equal(1, line('.'))
exe "normal G4\<C-E>\<C-E>"
call assert_equal(4, line('w$'))
call assert_equal(4, line('.'))
set scrolloff&
" Using <PageUp> and <PageDown> in an empty buffer should beep
%d
call assert_beeps('exe "normal \<PageUp>"')
call assert_beeps('exe "normal \<C-B>"')
call assert_beeps('exe "normal \<PageDown>"')
call assert_beeps('exe "normal \<C-F>"')
" Test for <C-U> and <C-D> with fold
%d
call setline(1, range(1, 100))
10,35fold
set scroll=10
exe "normal \<C-D>"
call assert_equal(36, line('.'))
exe "normal \<C-D>"
call assert_equal(46, line('.'))
exe "normal \<C-U>"
call assert_equal(36, line('.'))
exe "normal \<C-U>"
call assert_equal(10, line('.'))
exe "normal \<C-U>"
call assert_equal(1, line('.'))
set scroll&
" Test for scrolling to the top of the file with <C-U> and a fold
10
normal ztL
exe "normal \<C-U>\<C-U>"
call assert_equal(1, line('w0'))
" Test for CTRL-D on a folded line
%d
call setline(1, range(1, 100))
50,100fold
75
normal z-
exe "normal \<C-D>"
call assert_equal(50, line('.'))
call assert_equal(100, line('w$'))
normal z.
let lnum = winline()
exe "normal \<C-D>"
call assert_equal(lnum, winline())
call assert_equal(50, line('.'))
normal zt
exe "normal \<C-D>"
call assert_equal(50, line('w0'))
" Test for <S-CR>. Page down.
%d
call setline(1, range(1, 100))
call feedkeys("\<S-CR>", 'xt')
call assert_equal(14, line('w0'))
call assert_equal(28, line('w$'))
" Test for <S-->. Page up.
call feedkeys("\<S-->", 'xt')
call assert_equal(1, line('w0'))
call assert_equal(15, line('w$'))
set foldenable&
close!
endfunc
" Test for the 'sidescroll' option
func Test_sidescroll_opt()
new
20vnew
" scroll by 2 characters horizontally
set sidescroll=2 nowrap
call setline(1, repeat('a', 40))
normal g$l
call assert_equal(19, screenpos(0, 1, 21).col)
normal l
call assert_equal(20, screenpos(0, 1, 22).col)
normal g0h
call assert_equal(2, screenpos(0, 1, 2).col)
call assert_equal(20, screenpos(0, 1, 20).col)
" when 'sidescroll' is 0, cursor positioned at the center
set sidescroll=0
normal g$l
call assert_equal(11, screenpos(0, 1, 21).col)
normal g0h
call assert_equal(10, screenpos(0, 1, 10).col)
%bw!
set wrap& sidescroll&
endfunc
" basic tests for foldopen/folddelete
func Test_normal18_z_fold()
CheckFeature folding
call Setup_NewWindow()
50
setl foldenable fdm=marker foldlevel=5
call assert_beeps('normal! zj')
call assert_beeps('normal! zk')
" Test for zF
" First fold
norm! 4zF
" check that folds have been created
call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
" Test for zd
51
norm! 2zF
call assert_equal(2, foldlevel('.'))
norm! kzd
call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
norm! j
call assert_equal(1, foldlevel('.'))
" Test for zD
" also deletes partially selected folds recursively
51
norm! zF
call assert_equal(2, foldlevel('.'))
norm! kV2jzD
call assert_equal(['50', '51', '52', '53'], getline(50,53))
" Test for zE
85
norm! 4zF
86
norm! 2zF
90
norm! 4zF
call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
norm! zE
call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
" Test for zn
50
set foldlevel=0
norm! 2zF
norm! zn
norm! k
call assert_equal('49', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
call assert_equal(0, &foldenable)
" Test for zN
49
norm! zN
call assert_equal('49', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
call assert_equal(1, &foldenable)
" Test for zi
norm! zi
call assert_equal(0, &foldenable)
norm! zi
call assert_equal(1, &foldenable)
norm! zi
call assert_equal(0, &foldenable)
norm! zi
call assert_equal(1, &foldenable)
" Test for za
50
norm! za
norm! k
call assert_equal('49', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
50
norm! za
norm! k
call assert_equal('49', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
49
norm! 5zF
norm! k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
49
norm! za
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
set nofoldenable
" close fold and set foldenable
norm! za
call assert_equal(1, &foldenable)
50
" have to use {count}za to open all folds and make the cursor visible
norm! 2za
norm! 2k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
" Test for zA
49
set foldlevel=0
50
norm! zA
norm! 2k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
" zA on a opened fold when foldenable is not set
50
set nofoldenable
norm! zA
call assert_equal(1, &foldenable)
norm! k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zc
norm! zE
50
norm! 2zF
49
norm! 5zF
set nofoldenable
50
" There most likely is a bug somewhere:
" https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
" TODO: Should this only close the inner most fold or both folds?
norm! zc
call assert_equal(1, &foldenable)
norm! k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
set nofoldenable
50
norm! Vjzc
norm! k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zC
set nofoldenable
50
norm! zCk
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zx
" 1) close folds at line 49-54
set nofoldenable
48
norm! zx
call assert_equal(1, &foldenable)
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" 2) do not close fold under cursor
51
set nofoldenable
norm! zx
call assert_equal(1, &foldenable)
norm! 3k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
norm! j
call assert_equal('53', getline('.'))
norm! j
call assert_equal('54/*}}}*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" 3) close one level of folds
48
set nofoldenable
set foldlevel=1
norm! zx
call assert_equal(1, &foldenable)
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
norm! j
call assert_equal('53', getline('.'))
norm! j
call assert_equal('54/*}}}*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zX
" Close all folds
set foldlevel=0 nofoldenable
50
norm! zX
call assert_equal(1, &foldenable)
norm! k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zm
50
set nofoldenable foldlevel=2
norm! zm
call assert_equal(1, &foldenable)
call assert_equal(1, &foldlevel)
norm! zm
call assert_equal(0, &foldlevel)
norm! zm
call assert_equal(0, &foldlevel)
norm! k
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zm with a count
50
set foldlevel=2
norm! 3zm
call assert_equal(0, &foldlevel)
call assert_equal(49, foldclosed(line('.')))
" Test for zM
48
set nofoldenable foldlevel=99
norm! zM
call assert_equal(1, &foldenable)
call assert_equal(0, &foldlevel)
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('55', getline('.'))
" Test for zr
48
set nofoldenable foldlevel=0
norm! zr
call assert_equal(0, &foldenable)
call assert_equal(1, &foldlevel)
set foldlevel=0 foldenable
norm! zr
call assert_equal(1, &foldenable)
call assert_equal(1, &foldlevel)
norm! zr
call assert_equal(2, &foldlevel)
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
" Test for zR
48
set nofoldenable foldlevel=0
norm! zR
call assert_equal(0, &foldenable)
call assert_equal(2, &foldlevel)
set foldenable foldlevel=0
norm! zR
call assert_equal(1, &foldenable)
call assert_equal(2, &foldlevel)
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
call append(50, ['a /*{{{*/', 'b /*}}}*/'])
48
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('a /*{{{*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
48
norm! zR
call assert_equal(1, &foldenable)
call assert_equal(3, &foldlevel)
call assert_equal('48', getline('.'))
norm! j
call assert_equal('49/*{{{*/', getline('.'))
norm! j
call assert_equal('50/*{{{*/', getline('.'))
norm! j
call assert_equal('a /*{{{*/', getline('.'))
norm! j
call assert_equal('b /*}}}*/', getline('.'))
norm! j
call assert_equal('51/*}}}*/', getline('.'))
norm! j
call assert_equal('52', getline('.'))
" clean up
setl nofoldenable fdm=marker foldlevel=0
bw!
endfunc
func Test_normal20_exmode()
" Reading from redirected file doesn't work on MS-Windows
CheckNotMSWindows
call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
call writefile(['1', '2'], 'Xfile')
call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
let a=readfile('Xfile2')
call assert_equal(['1', 'foo', 'bar', '2'], a)
" clean up
for file in ['Xfile', 'Xfile2', 'Xscript']
call delete(file)
endfor
bw!
endfunc
func Test_normal21_nv_hat()
" Edit a fresh file and wipe the buffer list so that there is no alternate
" file present. Next, check for the expected command failures.
edit Xfoo | %bw
call assert_fails(':buffer #', 'E86:')
call assert_fails(':execute "normal! \<C-^>"', 'E23:')
call assert_fails("normal i\<C-R>#", 'E23:')
" Test for the expected behavior when switching between two named buffers.
edit Xfoo | edit Xbar
call feedkeys("\<C-^>", 'tx')
call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
call feedkeys("\<C-^>", 'tx')
call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
" Test for the expected behavior when only one buffer is named.
enew | let l:nr = bufnr('%')
call feedkeys("\<C-^>", 'tx')
call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
call feedkeys("\<C-^>", 'tx')
call assert_equal('', bufname('%'))
call assert_equal(l:nr, bufnr('%'))
" Test that no action is taken by "<C-^>" when an operator is pending.
edit Xfoo
call feedkeys("ci\<C-^>", 'tx')
call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
%bw!
endfunc
func Test_normal22_zet()
" Test for ZZ
" let shell = &shell
" let &shell = 'sh'
call writefile(['1', '2'], 'Xfile')
let args = ' -N -i NONE --noplugins -X --not-a-term'
call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
let a = readfile('Xfile')
call assert_equal([], a)
" Test for ZQ
call writefile(['1', '2'], 'Xfile')
call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
let a = readfile('Xfile')
call assert_equal(['1', '2'], a)
" Unsupported Z command
call assert_beeps('normal! ZW')
" clean up
for file in ['Xfile']
call delete(file)
endfor
" let &shell = shell
endfunc
func Test_normal23_K()
" Test for K command
new
call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
let k = &keywordprg
set keywordprg=:help
1
norm! VK
call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
call assert_equal('help', &ft)
call assert_match('\*version8.txt\*', getline('.'))
helpclose
norm! 0K
call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
call assert_equal('help', &ft)
call assert_match('\*version8\.\d\*', getline('.'))
helpclose
set keywordprg=:new
set iskeyword+=%
set iskeyword+=\|
2
norm! K
call assert_equal('man', fnamemodify(bufname('%'), ':t'))
bwipe!
3
norm! K
call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
bwipe!
if !has('win32')
4
norm! K
call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
bwipe!
endif
set iskeyword-=%
set iskeyword-=\|
" Test for specifying a count to K
1
com! -nargs=* Kprog let g:Kprog_Args = <q-args>
set keywordprg=:Kprog
norm! 3K
call assert_equal('3 version8', g:Kprog_Args)
delcom Kprog
" Only expect "man" to work on Unix
if !has("unix")
let &keywordprg = k
bw!
return
endif
let not_gnu_man = has('mac') || has('bsd')
if not_gnu_man
" In MacOS and BSD, the option for specifying a pager is different
set keywordprg=man\ -P\ cat
else
set keywordprg=man\ --pager=cat
endif
" Test for using man
2
let a = execute('unsilent norm! K')
if not_gnu_man
call assert_match("man -P cat 'man'", a)
else
call assert_match("man --pager=cat 'man'", a)
endif
" Error cases
call setline(1, '#$#')
call assert_fails('normal! ggK', 'E349:')
call setline(1, '---')
call assert_fails('normal! ggv2lK', 'E349:')
call setline(1, ['abc', 'xyz'])
call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
call assert_beeps("normal! ggVjK")
norm! V
call assert_beeps("norm! cK")
" clean up
let &keywordprg = k
bw!
endfunc
func Test_normal24_rot13()
" Testing for g?? g?g?
new
call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1
norm! g??
call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
norm! g?g?
call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
" clean up
bw!
endfunc
func Test_normal25_tag()
CheckFeature quickfix
" Testing for CTRL-] g CTRL-] g]
" CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
h
" Test for CTRL-]
call search('\<x\>$')
exe "norm! \<c-]>"
call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
norm! yiW
call assert_equal("*x*", @0)
exe ":norm \<c-o>"
" Test for g_CTRL-]
call search('\<v_u\>$')
exe "norm! g\<c-]>"
call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
norm! yiW
call assert_equal("*v_u*", @0)
exe ":norm \<c-o>"
" Test for g]
call search('\<i_<Esc>$')
let a = execute(":norm! g]")
call assert_match('i_<Esc>.*insert.txt', a)
if !empty(exepath('cscope')) && has('cscope')
" setting cscopetag changes how g] works
set cst
exe "norm! g]"
call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
norm! yiW
call assert_equal("*i_<Esc>*", @0)
exe ":norm \<c-o>"
" Test for CTRL-W g]
exe "norm! \<C-W>g]"
call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
norm! yiW
call assert_equal("*i_<Esc>*", @0)
call assert_equal(3, winnr('$'))
helpclose
set nocst
endif
" Test for CTRL-W g]
let a = execute("norm! \<C-W>g]")
call assert_match('i_<Esc>.*insert.txt', a)
" Test for CTRL-W CTRL-]
exe "norm! \<C-W>\<C-]>"
call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
norm! yiW
call assert_equal("*i_<Esc>*", @0)
call assert_equal(3, winnr('$'))
helpclose
" Test for CTRL-W g CTRL-]
exe "norm! \<C-W>g\<C-]>"
call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
norm! yiW
call assert_equal("*i_<Esc>*", @0)
call assert_equal(3, winnr('$'))
helpclose
" clean up
helpclose
endfunc
func Test_normal26_put()
" Test for ]p ]P [p and [P
new
call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1
/Error/y a
2
norm! "a]pj"a[p
call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1
/^\s\{4}/
exe "norm! \"a]P3Eldt'"
exe "norm! j\"a[P2Eldt'"
call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
" clean up
bw!
endfunc
func Test_normal27_bracket()
" Test for [' [` ]' ]`
call Setup_NewWindow()
1,21s/.\+/ & b/
1
norm! $ma
5
norm! $mb
10
norm! $mc
15
norm! $md
20
norm! $me
" Test for ['
9
norm! 2['
call assert_equal(' 1 b', getline('.'))
call assert_equal(1, line('.'))
call assert_equal(3, col('.'))
" Test for ]'
norm! ]'
call assert_equal(' 5 b', getline('.'))
call assert_equal(5, line('.'))
call assert_equal(3, col('.'))
" No mark after line 21, cursor moves to first non blank on current line
21
norm! $]'
call assert_equal(' 21 b', getline('.'))
call assert_equal(21, line('.'))
call assert_equal(3, col('.'))
" Test for [`
norm! 2[`
call assert_equal(' 15 b', getline('.'))
call assert_equal(15, line('.'))
call assert_equal(8, col('.'))
" Test for ]`
norm! ]`
call assert_equal(' 20 b', getline('.'))
call assert_equal(20, line('.'))
call assert_equal(8, col('.'))
" clean up
bw!
endfunc
" Test for ( and ) sentence movements
func Test_normal28_parenthesis()
new
call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
$
norm! d(
call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
norm! 2d(
call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1
norm! 0d)
call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
$
norm! $d(
call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
" Move to the next sentence from a paragraph macro
%d
call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
call cursor(1, 1)
normal )
call assert_equal([2, 1], [line('.'), col('.')])
normal )
call assert_equal([2, 12], [line('.'), col('.')])
normal ((
call assert_equal([1, 1], [line('.'), col('.')])
" It is an error if a next sentence is not found
%d
call setline(1, '.SH')
call assert_beeps('normal )')
" If only dot is present, don't treat that as a sentence
call setline(1, '. This is a sentence.')
normal $((
call assert_equal(3, col('.'))
" Jumping to a fold should open the fold
call setline(1, ['', '', 'one', 'two', 'three'])
set foldenable
2,$fold
call feedkeys(')', 'xt')
call assert_equal(3, line('.'))
call assert_equal(1, foldlevel('.'))
call assert_equal(-1, foldclosed('.'))
set foldenable&
" clean up
bw!
endfunc
" Test for { and } paragraph movements
func Test_normal29_brace()
let text =<< trim [DATA]
A paragraph begins after each empty line, and also at each of a set of
paragraph macros, specified by the pairs of characters in the 'paragraphs'
option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
the first column). A section boundary is also a paragraph boundary.
Note that a blank line (only containing white space) is NOT a paragraph
boundary.
Also note that this does not include a '{' or '}' in the first column. When
the '{' flag is in 'cpoptions' then '{' in the first column is used as a
paragraph boundary |posix|.
{
This is no paragraph
unless the '{' is set
in 'cpoptions'
}
.IP
The nroff macros IP separates a paragraph
That means, it must be a '.'
followed by IP
.LPIt does not matter, if afterwards some
more characters follow.
.SHAlso section boundaries from the nroff
macros terminate a paragraph. That means
a character like this:
.NH
End of text here
[DATA]
new
call append(0, text)
1
norm! 0d2}
let expected =<< trim [DATA]
.IP
The nroff macros IP separates a paragraph
That means, it must be a '.'
followed by IP
.LPIt does not matter, if afterwards some
more characters follow.
.SHAlso section boundaries from the nroff
macros terminate a paragraph. That means
a character like this:
.NH
End of text here
[DATA]
call assert_equal(expected, getline(1, '$'))
norm! 0d}
let expected =<< trim [DATA]
.LPIt does not matter, if afterwards some
more characters follow.
.SHAlso section boundaries from the nroff
macros terminate a paragraph. That means
a character like this:
.NH
End of text here
[DATA]
call assert_equal(expected, getline(1, '$'))
$
norm! d{
let expected =<< trim [DATA]
.LPIt does not matter, if afterwards some
more characters follow.
.SHAlso section boundaries from the nroff
macros terminate a paragraph. That means
a character like this:
[DATA]
call assert_equal(expected, getline(1, '$'))
norm! d{
let expected =<< trim [DATA]
.LPIt does not matter, if afterwards some
more characters follow.
[DATA]
call assert_equal(expected, getline(1, '$'))
" Test with { in cpooptions
%d
call append(0, text)
set cpo+={
1
norm! 0d2}
let expected =<< trim [DATA]
{
This is no paragraph
unless the '{' is set
in 'cpoptions'
}
.IP
The nroff macros IP separates a paragraph
That means, it must be a '.'
followed by IP
.LPIt does not matter, if afterwards some
more characters follow.
.SHAlso section boundaries from the nroff
macros terminate a paragraph. That means
a character like this:
.NH
End of text here
[DATA]
call assert_equal(expected, getline(1, '$'))
$
norm! d}
let expected =<< trim [DATA]
{
This is no paragraph
unless the '{' is set
in 'cpoptions'
}
.IP
The nroff macros IP separates a paragraph
That means, it must be a '.'
followed by IP
.LPIt does not matter, if afterwards some
more characters follow.
.SHAlso section boundaries from the nroff
macros terminate a paragraph. That means
a character like this:
.NH
End of text here
[DATA]
call assert_equal(expected, getline(1, '$'))
norm! gg}
norm! d5}
let expected =<< trim [DATA]
{
This is no paragraph
unless the '{' is set
in 'cpoptions'
}
[DATA]
call assert_equal(expected, getline(1, '$'))
" Jumping to a fold should open the fold
%d
call setline(1, ['', 'one', 'two', ''])
set foldenable
2,$fold
call feedkeys('}', 'xt')
call assert_equal(4, line('.'))
call assert_equal(1, foldlevel('.'))
call assert_equal(-1, foldclosed('.'))
set foldenable&
" clean up
set cpo-={
bw!
endfunc
" Test for section movements
func Test_normal_section()
new
let lines =<< trim [END]
int foo()
{
if (1)
{
a = 1;
}
}
[END]
call setline(1, lines)
" jumping to a folded line using [[ should open the fold
2,3fold
call cursor(5, 1)
call feedkeys("[[", 'xt')
call assert_equal(2, line('.'))
call assert_equal(-1, foldclosedend(line('.')))
close!
endfunc
" Test for changing case using u, U, gu, gU and ~ (tilde) commands
func Test_normal30_changecase()
new
call append(0, 'This is a simple test: äüöß')
norm! 1ggVu
call assert_equal('this is a simple test: äüöß', getline('.'))
norm! VU
call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
norm! guu
call assert_equal('this is a simple test: äüöss', getline('.'))
norm! gUgU
call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
norm! gugu
call assert_equal('this is a simple test: äüöss', getline('.'))
norm! gUU
call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
norm! 010~
call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
norm! V~
call assert_equal('THIS IS A simple test: äüöss', getline('.'))
call assert_beeps('norm! c~')
%d
call assert_beeps('norm! ~')
" Test for changing case across lines using 'whichwrap'
call setline(1, ['aaaaaa', 'aaaaaa'])
normal! gg10~
call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
set whichwrap+=~
normal! gg10~
call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
set whichwrap&
" clean up
bw!
endfunc
" Turkish ASCII turns to multi-byte. On some systems Turkish locale
" is available but toupper()/tolower() don't do the right thing.
func Test_normal_changecase_turkish()
new
try
lang tr_TR.UTF-8
set casemap=
let iupper = toupper('i')
if iupper == "\u0130"
call setline(1, 'iI')
1normal gUU
call assert_equal("\u0130I", getline(1))
call assert_equal("\u0130I", toupper("iI"))
call setline(1, 'iI')
1normal guu
call assert_equal("i\u0131", getline(1))
call assert_equal("i\u0131", tolower("iI"))
elseif iupper == "I"
call setline(1, 'iI')
1normal gUU
call assert_equal("II", getline(1))
call assert_equal("II", toupper("iI"))
call setline(1, 'iI')
1normal guu
call assert_equal("ii", getline(1))
call assert_equal("ii", tolower("iI"))
else
call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
endif
set casemap&
call setline(1, 'iI')
1normal gUU
call assert_equal("II", getline(1))
call assert_equal("II", toupper("iI"))
call setline(1, 'iI')
1normal guu
call assert_equal("ii", getline(1))
call assert_equal("ii", tolower("iI"))
lang en_US.UTF-8
catch /E197:/
" can't use Turkish locale
throw 'Skipped: Turkish locale not available'
endtry
close!
endfunc
" Test for r (replace) command
func Test_normal31_r_cmd()
new
call append(0, 'This is a simple test: abcd')
exe "norm! 1gg$r\<cr>"
call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
exe "norm! 1gg2wlr\<cr>"
call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
exe "norm! 2gg0W5r\<cr>"
call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
set autoindent
call setline(2, ['simple test: abc', ''])
exe "norm! 2gg0W5r\<cr>"
call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
exe "norm! 1ggVr\<cr>"
call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
call setline(1, 'This is a')
exe "norm! 1gg05rf"
call assert_equal('fffffis a', getline(1))
" When replacing characters, copy characters from above and below lines
" using CTRL-Y and CTRL-E.
" Different code paths are used for utf-8 and latin1 encodings
set showmatch
for enc in ['latin1', 'utf-8']
enew!
let &encoding = enc
call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
call assert_equal(' {a}x [b]x', getline(2))
endfor
set showmatch&
" r command should fail in operator pending mode
call assert_beeps('normal! cr')
" replace a tab character in visual mode
%d
call setline(1, ["a\tb", "c\td", "e\tf"])
normal gglvjjrx
call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
" replace with a multibyte character (with multiple composing characters)
%d
new
call setline(1, 'aaa')
exe "normal $ra\u0328\u0301"
call assert_equal("aaa\u0328\u0301", getline(1))
" clean up
set noautoindent
bw!
endfunc
" Test for g*, g#
func Test_normal32_g_cmd1()
new
call append(0, ['abc.x_foo', 'x_foobar.abc'])
1
norm! $g*
call assert_equal('x_foo', @/)
call assert_equal('x_foobar.abc', getline('.'))
norm! $g#
call assert_equal('abc', @/)
call assert_equal('abc.x_foo', getline('.'))
" clean up
bw!
endfunc
" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
" gi and gI commands
func Test_normal33_g_cmd2()
CheckFeature jumplist
call Setup_NewWindow()
" Test for g`
clearjumps
norm! ma10j
let a=execute(':jumps')
" empty jumplist
call assert_equal('>', a[-1:])
norm! g`a
call assert_equal('>', a[-1:])
call assert_equal(1, line('.'))
call assert_equal('1', getline('.'))
call cursor(10, 1)
norm! g'a
call assert_equal('>', a[-1:])
call assert_equal(1, line('.'))
" Test for g; and g,
norm! g;
" there is only one change in the changelist
" currently, when we setup the window
call assert_equal(2, line('.'))
call assert_fails(':norm! g;', 'E662:')
call assert_fails(':norm! g,', 'E663:')
let &ul=&ul
call append('$', ['a', 'b', 'c', 'd'])
let &ul=&ul
call append('$', ['Z', 'Y', 'X', 'W'])
let a = execute(':changes')
call assert_match('2\s\+0\s\+2', a)
call assert_match('101\s\+0\s\+a', a)
call assert_match('105\s\+0\s\+Z', a)
norm! 3g;
call assert_equal(2, line('.'))
norm! 2g,
call assert_equal(105, line('.'))
" Test for g& - global substitute
%d
call setline(1, range(1,10))
call append('$', ['a', 'b', 'c', 'd'])
$s/\w/&&/g
exe "norm! /[1-8]\<cr>"
norm! g&
call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
" Jumping to a fold using gg should open the fold
set foldenable
set foldopen+=jump
5,8fold
call feedkeys('6gg', 'xt')
call assert_equal(1, foldlevel('.'))
call assert_equal(-1, foldclosed('.'))
set foldopen-=jump
set foldenable&
" Test for gv
%d
call append('$', repeat(['abcdefgh'], 8))
exe "norm! 2gg02l\<c-v>2j2ly"
call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
" in visual mode, gv swaps current and last selected region
exe "norm! G0\<c-v>4k4lgvd"
call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
exe "norm! G0\<c-v>4k4ly"
exe "norm! gvood"
call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
" gv cannot be used in operator pending mode
call assert_beeps('normal! cgv')
" gv should beep without a previously selected visual area
new
call assert_beeps('normal! gv')
close
" Test for gk/gj
%d
15vsp
set wrap listchars= sbr=
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
$put =lineA
$put =lineB
norm! 3gg0dgk
call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
set nu
norm! 3gg0gjdgj
call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
" Test for gJ
norm! 2gggJ
call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
call assert_equal(16, col('.'))
" shouldn't do anything
norm! 10gJ
call assert_equal(1, col('.'))
" Test for g0 g^ gm g$
exe "norm! 2gg0gji "
call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
norm! g0yl
call assert_equal(12, col('.'))
call assert_equal(' ', getreg(0))
norm! g$yl
call assert_equal(22, col('.'))
call assert_equal('3', getreg(0))
norm! gmyl
call assert_equal(17, col('.'))
call assert_equal('n', getreg(0))
norm! g^yl
call assert_equal(15, col('.'))
call assert_equal('l', getreg(0))
call assert_beeps('normal 5g$')
" Test for g_
call assert_beeps('normal! 100g_')
call setline(2, [' foo ', ' foobar '])
normal! 2ggg_
call assert_equal(5, col('.'))
normal! 2g_
call assert_equal(8, col('.'))
norm! 2ggdG
$put =lineC
" Test for gM
norm! gMyl
call assert_equal(73, col('.'))
call assert_equal('0', getreg(0))
" Test for 20gM
norm! 20gMyl
call assert_equal(29, col('.'))
call assert_equal('S', getreg(0))
" Test for 60gM
norm! 60gMyl
call assert_equal(87, col('.'))
call assert_equal('E', getreg(0))
" Test for g Ctrl-G
set ff=unix
let a=execute(":norm! g\<c-g>")
call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
" Test for gI
norm! gIfoo
call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
" Test for gi
wincmd c
%d
set tw=0
call setline(1, ['foobar', 'new line'])
norm! A next word
$put ='third line'
norm! gi another word
call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
call setline(1, 'foobar')
normal! Ggifirst line
call assert_equal('foobarfirst line', getline(1))
" Test gi in 'virtualedit' mode with cursor after the end of the line
set virtualedit=all
call setline(1, 'foo')
exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
call setline(1, 'foo')
normal! Ggifirst line
call assert_equal('foo first line', getline(1))
set virtualedit&
" Test for aboring a g command using CTRL-\ CTRL-G
exe "normal! g\<C-\>\<C-G>"
call assert_equal('foo first line', getline('.'))
" clean up
bw!
endfunc
" Test for g CTRL-G
func Test_g_ctrl_g()
new
let a = execute(":norm! g\<c-g>")
call assert_equal("\n--No lines in buffer--", a)
" Test for CTRL-G (same as :file)
let a = execute(":norm! \<c-g>")
call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
call setline(1, ['first line', 'second line'])
" Test g CTRL-g with dos, mac and unix file type.
norm! gojll
set ff=dos
let a = execute(":norm! g\<c-g>")
call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
set ff=mac
let a = execute(":norm! g\<c-g>")
call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
set ff=unix
let a = execute(":norm! g\<c-g>")
call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
" Test g CTRL-g in visual mode (v)
let a = execute(":norm! gojllvlg\<c-g>")
call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
" Test g CTRL-g in visual mode (CTRL-V) with end col > start col
let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
" Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
" Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
" There should be one byte less with noeol
set bin noeol
let a = execute(":norm! \<Esc>gog\<c-g>")
call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
set bin & eol&
call setline(1, ['Français', '日本語'])
let a = execute(":norm! \<Esc>gojlg\<c-g>")
call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
let a = execute(":norm! \<Esc>gojvlg\<c-g>")
call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
set fenc=utf8 bomb
let a = execute(":norm! \<Esc>gojlg\<c-g>")
call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
set fenc=utf16 bomb
let a = execute(":norm! g\<c-g>")
call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
set fenc=utf32 bomb
let a = execute(":norm! g\<c-g>")
call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
set fenc& bomb&
set ff&
bwipe!
endfunc
" Test for g8
func Test_normal34_g_cmd3()
new
let a=execute(':norm! 1G0g8')
call assert_equal("\nNUL", a)
call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
let a=execute(':norm! 1G$g8')
call assert_equal("\nc3 b6 ", a)
call setline(1, "a\u0302")
let a=execute(':norm! 1G0g8')
call assert_equal("\n61 + cc 82 ", a)
" clean up
bw!
endfunc
" Test 8g8 which finds invalid utf8 at or after the cursor.
func Test_normal_8g8()
new
" With invalid byte.
call setline(1, "___\xff___")
norm! 1G08g8g
call assert_equal([0, 1, 4, 0, 1], getcurpos())
" With invalid byte before the cursor.
call setline(1, "___\xff___")
norm! 1G$h8g8g
call assert_equal([0, 1, 6, 0, 9], getcurpos())
" With truncated sequence.
call setline(1, "___\xE2\x82___")
norm! 1G08g8g
call assert_equal([0, 1, 4, 0, 1], getcurpos())
" With overlong sequence.
call setline(1, "___\xF0\x82\x82\xAC___")
norm! 1G08g8g
call assert_equal([0, 1, 4, 0, 1], getcurpos())
" With valid utf8.
call setline(1, "café")
norm! 1G08g8
call assert_equal([0, 1, 1, 0, 1], getcurpos())
bw!
endfunc
" Test for g<
func Test_normal35_g_cmd4()
" Cannot capture its output,
" probably a bug, therefore, test disabled:
throw "Skipped: output of g< can't be tested currently"
echo "a\nb\nc\nd"
let b=execute(':norm! g<')
call assert_true(!empty(b), 'failed `execute(g<)`')
endfunc
" Test for gp gP go
func Test_normal36_g_cmd5()
new
call append(0, 'abcdefghijklmnopqrstuvwxyz')
set ff=unix
" Test for gp gP
call append(1, range(1,10))
1
norm! 1yy
3
norm! gp
call assert_equal([0, 5, 1, 0, 1], getcurpos())
$
norm! gP
call assert_equal([0, 14, 1, 0, 1], getcurpos())
" Test for go
norm! 26go
call assert_equal([0, 1, 26, 0, 26], getcurpos())
norm! 27go
call assert_equal([0, 1, 26, 0, 26], getcurpos())
norm! 28go
call assert_equal([0, 2, 1, 0, 1], getcurpos())
set ff=dos
norm! 29go
call assert_equal([0, 2, 1, 0, 1], getcurpos())
set ff=unix
norm! gg0
norm! 101go
call assert_equal([0, 13, 26, 0, 26], getcurpos())
norm! 103go
call assert_equal([0, 14, 1, 0, 1], getcurpos())
" count > buffer content
norm! 120go
call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
" clean up
bw!
endfunc
" Test for gt and gT
func Test_normal37_g_cmd6()
tabnew 1.txt
tabnew 2.txt
tabnew 3.txt
norm! 1gt
call assert_equal(1, tabpagenr())
norm! 3gt
call assert_equal(3, tabpagenr())
norm! 1gT
" count gT goes not to the absolute tabpagenumber
" but, but goes to the count previous tabpagenumber
call assert_equal(2, tabpagenr())
" wrap around
norm! 3gT
call assert_equal(3, tabpagenr())
" gt does not wrap around
norm! 5gt
call assert_equal(3, tabpagenr())
for i in range(3)
tabclose
endfor
" clean up
call assert_fails(':tabclose', 'E784:')
endfunc
" Test for <Home> and <C-Home> key
func Test_normal38_nvhome()
new
call setline(1, range(10))
$
setl et sw=2
norm! V10>$
" count is ignored
exe "norm! 10\<home>"
call assert_equal(1, col('.'))
exe "norm! \<home>"
call assert_equal([0, 10, 1, 0, 1], getcurpos())
exe "norm! 5\<c-home>"
call assert_equal([0, 5, 1, 0, 1], getcurpos())
exe "norm! \<c-home>"
call assert_equal([0, 1, 1, 0, 1], getcurpos())
exe "norm! G\<c-kHome>"
call assert_equal([0, 1, 1, 0, 1], getcurpos())
" clean up
bw!
endfunc
" Test for <End> and <C-End> keys
func Test_normal_nvend()
new
call setline(1, map(range(1, 10), '"line" .. v:val'))
exe "normal! \<End>"
call assert_equal(5, col('.'))
exe "normal! 4\<End>"
call assert_equal([4, 5], [line('.'), col('.')])
exe "normal! \<C-End>"
call assert_equal([10, 6], [line('.'), col('.')])
close!
endfunc
" Test for cw cW ce
func Test_normal39_cw()
" Test for cw and cW on whitespace
new
set tw=0
call append(0, 'here are some words')
norm! 1gg0elcwZZZ
call assert_equal('hereZZZare some words', getline('.'))
norm! 1gg0elcWYYY
call assert_equal('hereZZZareYYYsome words', getline('.'))
norm! 2gg0cwfoo
call assert_equal('foo', getline('.'))
call setline(1, 'one; two')
call cursor(1, 1)
call feedkeys('cwvim', 'xt')
call assert_equal('vim; two', getline(1))
call feedkeys('0cWone', 'xt')
call assert_equal('one two', getline(1))
"When cursor is at the end of a word 'ce' will change until the end of the
"next word, but 'cw' will change only one character
call setline(1, 'one two')
call feedkeys('0ecwce', 'xt')
call assert_equal('once two', getline(1))
call setline(1, 'one two')
call feedkeys('0ecely', 'xt')
call assert_equal('only', getline(1))
" clean up
bw!
endfunc
" Test for CTRL-\ commands
func Test_normal40_ctrl_bsl()
new
call append(0, 'here are some words')
exe "norm! 1gg0a\<C-\>\<C-N>"
call assert_equal('n', mode())
call assert_equal(1, col('.'))
call assert_equal('', visualmode())
exe "norm! 1gg0viw\<C-\>\<C-N>"
call assert_equal('n', mode())
call assert_equal(4, col('.'))
exe "norm! 1gg0a\<C-\>\<C-G>"
call assert_equal('n', mode())
call assert_equal(1, col('.'))
"imap <buffer> , <c-\><c-n>
set im
exe ":norm! \<c-\>\<c-n>dw"
set noim
call assert_equal('are some words', getline(1))
call assert_false(&insertmode)
call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
" Using CTRL-\ CTRL-N in cmd window should close the window
call feedkeys("q:\<C-\>\<C-N>", 'xt')
call assert_equal('', getcmdwintype())
" clean up
bw!
endfunc
" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
func Test_normal41_insert_reg()
new
set sts=2 sw=2 ts=8 tw=0
call append(0, ["aaa\tbbb\tccc", '', '', ''])
let a=getline(1)
norm! 2gg0
exe "norm! a\<c-r>=a\<cr>"
norm! 3gg0
exe "norm! a\<c-r>\<c-r>=a\<cr>"
norm! 4gg0
exe "norm! a\<c-r>\<c-o>=a\<cr>"
call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
" clean up
set sts=0 sw=8 ts=8
bw!
endfunc
" Test for Ctrl-D and Ctrl-U
func Test_normal42_halfpage()
call Setup_NewWindow()
call assert_equal(5, &scroll)
exe "norm! \<c-d>"
call assert_equal('6', getline('.'))
exe "norm! 2\<c-d>"
call assert_equal('8', getline('.'))
call assert_equal(2, &scroll)
set scroll=5
exe "norm! \<c-u>"
call assert_equal('3', getline('.'))
1
set scrolloff=5
exe "norm! \<c-d>"
call assert_equal('10', getline('.'))
exe "norm! \<c-u>"
call assert_equal('5', getline('.'))
1
set scrolloff=99
exe "norm! \<c-d>"
call assert_equal('10', getline('.'))
set scrolloff=0
100
exe "norm! $\<c-u>"
call assert_equal('95', getline('.'))
call assert_equal([0, 95, 1, 0, 1], getcurpos())
100
set nostartofline
exe "norm! $\<c-u>"
call assert_equal('95', getline('.'))
call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
" cleanup
set startofline
bw!
endfunc
func Test_normal45_drop()
if !has('dnd')
" The ~ register does not exist
call assert_beeps('norm! "~')
return
endif
" basic test for drag-n-drop
" unfortunately, without a gui, we can't really test much here,
" so simply test that ~p fails (which uses the drop register)
new
call assert_fails(':norm! "~p', 'E353:')
call assert_equal([], getreg('~', 1, 1))
" the ~ register is read only
call assert_fails(':let @~="1"', 'E354:')
bw!
endfunc
func Test_normal46_ignore()
new
" How to test this?
" let's just for now test, that the buffer
" does not change
call feedkeys("\<c-s>", 't')
call assert_equal([''], getline(1,'$'))
" no valid commands
exe "norm! \<char-0x100>"
call assert_equal([''], getline(1,'$'))
exe "norm! ä"
call assert_equal([''], getline(1,'$'))
" clean up
bw!
endfunc
func Test_normal47_visual_buf_wipe()
" This was causing a crash or ml_get error.
enew!
call setline(1,'xxx')
normal $
new
call setline(1, range(1,2))
2
exe "norm \<C-V>$"
bw!
norm yp
set nomodified
endfunc
func Test_normal48_wincmd()
new
exe "norm! \<c-w>c"
call assert_equal(1, winnr('$'))
call assert_fails(":norm! \<c-w>c", 'E444:')
endfunc
func Test_normal49_counts()
new
call setline(1, 'one two three four five six seven eight nine ten')
1
norm! 3d2w
call assert_equal('seven eight nine ten', getline(1))
bw!
endfunc
func Test_normal50_commandline()
CheckFeature timers
CheckFeature cmdline_hist
func! DoTimerWork(id)
call assert_equal('[Command Line]', bufname(''))
" should fail, with E11, but does fail with E23?
"call feedkeys("\<c-^>", 'tm')
" should also fail with E11
call assert_fails(":wincmd p", 'E11:')
" return from commandline window
call feedkeys("\<cr>")
endfunc
let oldlang=v:lang
lang C
set updatetime=20
call timer_start(100, 'DoTimerWork')
try
" throws E23, for whatever reason...
call feedkeys('q:', 'x!')
catch /E23/
" no-op
endtry
" clean up
set updatetime=4000
exe "lang" oldlang
bw!
endfunc
func Test_normal51_FileChangedRO()
CheckFeature autocmd
" Don't sleep after the warning message.
call test_settime(1)
call writefile(['foo'], 'Xreadonly.log')
new Xreadonly.log
setl ro
au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
call assert_fails(":norm! Af", 'E788:')
call assert_equal(['foo'], getline(1,'$'))
call assert_equal('Xreadonly.log', bufname(''))
" cleanup
call test_settime(0)
bw!
call delete("Xreadonly.log")
endfunc
func Test_normal52_rl()
CheckFeature rightleft
new
call setline(1, 'abcde fghij klmnopq')
norm! 1gg$
set rl
call assert_equal(19, col('.'))
call feedkeys('l', 'tx')
call assert_equal(18, col('.'))
call feedkeys('h', 'tx')
call assert_equal(19, col('.'))
call feedkeys("\<right>", 'tx')
call assert_equal(18, col('.'))
call feedkeys("\<left>", 'tx')
call assert_equal(19, col('.'))
call feedkeys("\<s-right>", 'tx')
call assert_equal(13, col('.'))
call feedkeys("\<c-right>", 'tx')
call assert_equal(7, col('.'))
call feedkeys("\<c-left>", 'tx')
call assert_equal(13, col('.'))
call feedkeys("\<s-left>", 'tx')
call assert_equal(19, col('.'))
call feedkeys("<<", 'tx')
call assert_equal(' abcde fghij klmnopq',getline(1))
call feedkeys(">>", 'tx')
call assert_equal('abcde fghij klmnopq',getline(1))
" cleanup
set norl
bw!
endfunc
func Test_normal54_Ctrl_bsl()
new
call setline(1, 'abcdefghijklmn')
exe "norm! df\<c-\>\<c-n>"
call assert_equal(['abcdefghijklmn'], getline(1,'$'))
exe "norm! df\<c-\>\<c-g>"
call assert_equal(['abcdefghijklmn'], getline(1,'$'))
exe "norm! df\<c-\>m"
call assert_equal(['abcdefghijklmn'], getline(1,'$'))
call setline(2, 'abcdefghijklmnāf')
norm! 2gg0
exe "norm! df\<Char-0x101>"
call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
norm! 1gg0
exe "norm! df\<esc>"
call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
" clean up
bw!
endfunc
func Test_normal_large_count()
" This may fail with 32bit long, how do we detect that?
new
normal o
normal 6666666666dL
bwipe!
endfunc
func Test_delete_until_paragraph()
new
normal grádv}
call assert_equal('á', getline(1))
normal grád}
call assert_equal('', getline(1))
bwipe!
endfunc
" Test for the gr (virtual replace) command
" Test for the bug fixed by 7.4.387
func Test_gr_command()
enew!
let save_cpo = &cpo
call append(0, ['First line', 'Second line', 'Third line'])
exe "normal i\<C-G>u"
call cursor(2, 1)
set cpo-=X
normal 4gro
call assert_equal('oooond line', getline(2))
undo
set cpo+=X
normal 4gro
call assert_equal('ooooecond line', getline(2))
let &cpo = save_cpo
normal! ggvegrx
call assert_equal('xxxxx line', getline(1))
exe "normal! gggr\<C-V>122"
call assert_equal('zxxxx line', getline(1))
set virtualedit=all
normal! 15|grl
call assert_equal('zxxxx line l', getline(1))
set virtualedit&
set nomodifiable
call assert_fails('normal! grx', 'E21:')
call assert_fails('normal! gRx', 'E21:')
set modifiable&
enew!
endfunc
" When splitting a window the changelist position is wrong.
" Test the changelist position after splitting a window.
" Test for the bug fixed by 7.4.386
func Test_changelist()
let save_ul = &ul
enew!
call append('$', ['1', '2'])
exe "normal i\<C-G>u"
exe "normal Gkylpa\<C-G>u"
set ul=100
exe "normal Gylpa\<C-G>u"
set ul=100
normal gg
vsplit
normal g;
call assert_equal([3, 2], [line('.'), col('.')])
normal g;
call assert_equal([2, 2], [line('.'), col('.')])
call assert_fails('normal g;', 'E662:')
new
call assert_fails('normal g;', 'E664:')
%bwipe!
let &ul = save_ul
endfunc
func Test_nv_hat_count()
%bwipeout!
let l:nr = bufnr('%') + 1
call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
edit Xfoo
let l:foo_nr = bufnr('Xfoo')
edit Xbar
let l:bar_nr = bufnr('Xbar')
" Make sure we are not just using the alternate file.
edit Xbaz
call feedkeys(l:foo_nr . "\<C-^>", 'tx')
call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
call feedkeys(l:bar_nr . "\<C-^>", 'tx')
call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
%bwipeout!
endfunc
func Test_message_when_using_ctrl_c()
" Make sure no buffers are changed.
%bwipe!
exe "normal \<C-C>"
call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
new
cal setline(1, 'hi!')
exe "normal \<C-C>"
call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
bwipe!
endfunc
" Test for '[m', ']m', '[M' and ']M'
" Jumping to beginning and end of methods in Java-like languages
func Test_java_motion()
new
call assert_beeps('normal! [m')
call assert_beeps('normal! ]m')
call assert_beeps('normal! [M')
call assert_beeps('normal! ]M')
let lines =<< trim [CODE]
Piece of Java
{
tt m1 {
t1;
} e1
tt m2 {
t2;
} e2
tt m3 {
if (x)
{
t3;
}
} e3
}
[CODE]
call setline(1, lines)
normal gg
normal 2]maA
call assert_equal("\ttt m1 {A", getline('.'))
call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
normal j]maB
call assert_equal("\ttt m2 {B", getline('.'))
call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
normal ]maC
call assert_equal("\ttt m3 {C", getline('.'))
call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
normal [maD
call assert_equal("\ttt m3 {DC", getline('.'))
call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
normal k2[maE
call assert_equal("\ttt m1 {EA", getline('.'))
call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
normal 3[maF
call assert_equal("{F", getline('.'))
call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
normal ]MaG
call assert_equal("\t}G e1", getline('.'))
call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
normal j2]MaH
call assert_equal("\t}H e3", getline('.'))
call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
normal ]M]M
normal aI
call assert_equal("}I", getline('.'))
call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
normal 2[MaJ
call assert_equal("\t}JH e3", getline('.'))
call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
normal k[MaK
call assert_equal("\t}K e2", getline('.'))
call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
normal 3[MaL
call assert_equal("{LF", getline('.'))
call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
call cursor(2, 1)
call assert_beeps('norm! 5]m')
" jumping to a method in a fold should open the fold
6,10fold
call feedkeys("gg3]m", 'xt')
call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
call assert_equal(-1, foldclosedend(7))
close!
endfunc
" Tests for g cmds
func Test_normal_gdollar_cmd()
CheckFeature jumplist
call Setup_NewWindow()
" Make long lines that will wrap
%s/$/\=repeat(' foobar', 10)/
20vsp
set wrap
" Test for g$ with count
norm! gg
norm! 0vg$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foob', getreg(0))
norm! gg
norm! 0v4g$y
call assert_equal(72, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
norm! gg
norm! 0v6g$y
call assert_equal(40, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '2 foobar foobar foobar foobar foobar foo', getreg(0))
set nowrap
" clean up
norm! gg
norm! 0vg$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foob', getreg(0))
norm! gg
norm! 0v4g$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '4 foobar foobar foob', getreg(0))
norm! gg
norm! 0v6g$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '6 foobar foobar foob', getreg(0))
" Move to last line, also down movement is not possible, should still move
" the cursor to the last visible char
norm! G
norm! 0v6g$y
call assert_equal(20, col("'>"))
call assert_equal('100 foobar foobar fo', getreg(0))
bw!
endfunc
func Test_normal_gk_gj()
" needs 80 column new window
new
vert 80new
call assert_beeps('normal gk')
put =[repeat('x',90)..' {{{1', 'x {{{1']
norm! gk
" In a 80 column wide terminal the window will be only 78 char
" (because Vim will leave space for the other window),
" but if the terminal is larger, it will be 80 chars, so verify the
" cursor column correctly.
call assert_equal(winwidth(0)+1, col('.'))
call assert_equal(winwidth(0)+1, virtcol('.'))
norm! j
call assert_equal(6, col('.'))
call assert_equal(6, virtcol('.'))
norm! gk
call assert_equal(95, col('.'))
call assert_equal(95, virtcol('.'))
%bw!
" needs 80 column new window
new
vert 80new
call assert_beeps('normal gj')
set number
set numberwidth=10
set cpoptions+=n
put =[repeat('0',90), repeat('1',90)]
norm! 075l
call assert_equal(76, col('.'))
norm! gk
call assert_equal(1, col('.'))
norm! gk
call assert_equal(76, col('.'))
norm! gk
call assert_equal(1, col('.'))
norm! gj
call assert_equal(76, col('.'))
norm! gj
call assert_equal(1, col('.'))
norm! gj
call assert_equal(76, col('.'))
" When 'nowrap' is set, gk and gj behave like k and j
set nowrap
normal! gk
call assert_equal([2, 76], [line('.'), col('.')])
normal! gj
call assert_equal([3, 76], [line('.'), col('.')])
%bw!
set cpoptions& number& numberwidth& wrap&
endfunc
" Test for using : to run a multi-line Ex command in operator pending mode
func Test_normal_yank_with_excmd()
new
call setline(1, ['foo', 'bar', 'baz'])
let @a = ''
call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
call assert_equal('f', @a)
close!
endfunc
" Test for supplying a count to a normal-mode command across a cursorhold call
func Test_normal_cursorhold_with_count()
func s:cHold()
let g:cHold_Called += 1
endfunc
new
augroup normalcHoldTest
au!
au CursorHold <buffer> call s:cHold()
augroup END
let g:cHold_Called = 0
call feedkeys("3\<CursorHold>2ix", 'xt')
call assert_equal(1, g:cHold_Called)
call assert_equal(repeat('x', 32), getline(1))
augroup normalcHoldTest
au!
augroup END
au! normalcHoldTest
close!
delfunc s:cHold
endfunc
" Test for using a count and a command with CTRL-W
func Test_wincmd_with_count()
call feedkeys("\<C-W>12n", 'xt')
call assert_equal(12, winheight(0))
endfunc
" Test for 'b', 'B' 'ge' and 'gE' commands
func Test_horiz_motion()
new
normal! gg
call assert_beeps('normal! b')
call assert_beeps('normal! B')
call assert_beeps('normal! gE')
call assert_beeps('normal! ge')
" <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
call setline(1, 'one ,two ,three')
exe "normal! $\<S-BS>"
call assert_equal(11, col('.'))
exe "normal! $\<C-BS>"
call assert_equal(10, col('.'))
close!
endfunc
" Test for using a : command in operator pending mode
func Test_normal_colon_op()
new
call setline(1, ['one', 'two'])
call assert_beeps("normal! Gc:d\<CR>")
close!
endfunc
" Test for d and D commands
func Test_normal_delete_cmd()
new
" D in an empty line
call setline(1, '')
normal D
call assert_equal('', getline(1))
" D in an empty line in virtualedit mode
set virtualedit=all
normal D
call assert_equal('', getline(1))
set virtualedit&
" delete to a readonly register
call setline(1, ['abcd'])
call assert_beeps('normal ":d2l')
close!
endfunc
" Test for deleting or changing characters across lines with 'whichwrap'
" containing 's'. Should count <EOL> as one character.
func Test_normal_op_across_lines()
new
set whichwrap&
call setline(1, ['one two', 'three four'])
exe "norm! $3d\<Space>"
call assert_equal(['one twhree four'], getline(1, '$'))
call setline(1, ['one two', 'three four'])
exe "norm! $3c\<Space>x"
call assert_equal(['one twxhree four'], getline(1, '$'))
set whichwrap+=l
call setline(1, ['one two', 'three four'])
exe "norm! $3x"
call assert_equal(['one twhree four'], getline(1, '$'))
close!
set whichwrap&
endfunc
" Test for 'w' and 'b' commands
func Test_normal_word_move()
new
call setline(1, ['foo bar a', '', 'foo bar b'])
" copy a single character word at the end of a line
normal 1G$yw
call assert_equal('a', @")
" copy a single character word at the end of a file
normal G$yw
call assert_equal('b', @")
" check for a word movement handling an empty line properly
normal 1G$vwy
call assert_equal("a\n\n", @")
" copy using 'b' command
%d
" non-empty blank line at the start of file
call setline(1, [' ', 'foo bar'])
normal 2Gyb
call assert_equal(" \n", @")
" try to copy backwards from the start of the file
call setline(1, ['one two', 'foo bar'])
call assert_beeps('normal ggyb')
" 'b' command should stop at an empty line
call setline(1, ['one two', '', 'foo bar'])
normal 3Gyb
call assert_equal("\n", @")
normal 3Gy2b
call assert_equal("two\n", @")
" 'b' command should not stop at a non-empty blank line
call setline(1, ['one two', ' ', 'foo bar'])
normal 3Gyb
call assert_equal("two\n ", @")
close!
endfunc
" Test for 'scrolloff' with a long line that doesn't fit in the screen
func Test_normal_scroloff()
10new
80vnew
call setline(1, repeat('a', 1000))
set scrolloff=10
normal gg10gj
call assert_equal(8, winline())
normal 10gj
call assert_equal(10, winline())
normal 10gk
call assert_equal(3, winline())
set scrolloff&
close!
endfunc
" Test for vertical scrolling with CTRL-F and CTRL-B with a long line
func Test_normal_vert_scroll_longline()
10new
80vnew
call setline(1, range(1, 10))
call append(5, repeat('a', 1000))
exe "normal gg\<C-F>"
call assert_equal(6, line('.'))
exe "normal \<C-F>\<C-F>"
call assert_equal(11, line('.'))
call assert_equal(1, winline())
exe "normal \<C-B>"
call assert_equal(10, line('.'))
call assert_equal(3, winline())
exe "normal \<C-B>\<C-B>"
call assert_equal(5, line('.'))
call assert_equal(5, winline())
close!
endfunc
" Test for jumping in a file using %
func Test_normal_percent_jump()
new
call setline(1, range(1, 100))
" jumping to a folded line should open the fold
25,75fold
call feedkeys('50%', 'xt')
call assert_equal(50, line('.'))
call assert_equal(-1, foldclosedend(50))
close!
endfunc
" vim: shiftwidth=2 sts=2 expandtab
|