File size: 138,280 Bytes
c3a45c0 | 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 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 | usr\_toc.txt For Vim version 8.0. Last change: 2016 Mar 25 VIM USER MANUAL \- by Bram Moolenaar
Table Of Contents user-manual
\============================================================================== Overview
Getting Started
usr\_01.txt About the manuals
usr\_02.txt The first steps in Vim
usr\_03.txt Moving around
usr\_04.txt Making small changes
usr\_05.txt Set your settings
usr\_06.txt Using syntax highlighting
usr\_07.txt Editing more than one file
usr\_08.txt Splitting windows
usr\_09.txt Using the GUI
usr\_10.txt Making big changes
usr\_11.txt Recovering from a crash
usr\_12.txt Clever tricks
Editing Effectively
usr\_20.txt Typing command-line commands quickly
usr\_21.txt Go away and come back
usr\_22.txt Finding the file to edit
usr\_23.txt Editing other files
usr\_24.txt Inserting quickly
usr\_25.txt Editing formatted text
usr\_26.txt Repeating
usr\_27.txt Search commands and patterns
usr\_28.txt Folding
usr\_29.txt Moving through programs
usr\_30.txt Editing programs
usr\_31.txt Exploiting the GUI
usr\_32.txt The undo tree
Tuning Vim
usr\_40.txt Make new commands
usr\_41.txt Write a Vim script
usr\_42.txt Add new menus
usr\_43.txt Using filetypes
usr\_44.txt Your own syntax highlighted
usr\_45.txt Select your language
Making Vim Run
usr\_90.txt Installing Vim
Reference manual
reference\_toc More detailed information for all commands The user manual is available as a single, ready to print HTML and PDF file
usr\_toc.txt β 33
here:
http\://vimdoc.sf.net
\============================================================================== Getting Started
Read this from start to end to learn the essential commands.
usr\_01.txt About the manuals
01.1 Two manuals
01.2 Vim installed
01.3 Using the Vim tutor
01.4 Copyright
usr\_02.txt The first steps in Vim
02.1 Running Vim for the First Time
02.2 Inserting text
02.3 Moving around
02.4 Deleting characters
02.5 Undo and Redo
02.6 Other editing commands
02.7 Getting out
02.8 Finding help
usr\_03.txt Moving around
03.1 Word movement
03.2 Moving to the start or end of a line
03.3 Moving to a character
03.4 Matching a paren
03.5 Moving to a specific line
03.6 Telling where you are
03.7 Scrolling around
03.8 Simple searches
03.9 Simple search patterns
03.10 Using marks
usr\_04.txt Making small changes
04.1 Operators and motions
04.2 Changing text
04.3 Repeating a change
04.4 Visual mode
04.5 Moving text
04.6 Copying text
04.7 Using the clipboard
04.8 Text objects
04.9 Replace mode
04.10 Conclusion
usr\_05.txt Set your settings
05.1 The vimrc file
05.2 The example vimrc file explained
05.3 Simple mappings
05.4 Adding a package
05.5 Adding a plugin
usr\_toc.txt β 34
05.6 Adding a help file
05.7 The option window
05.8 Often used options
usr\_06.txt Using syntax highlighting
06.1 Switching it on
06.2 No or wrong colors?
06.3 Different colors
06.4 With colors or without colors
06.5 Printing with colors
06.6 Further reading
usr\_07.txt Editing more than one file
07.1 Edit another file
07.2 A list of files
07.3 Jumping from file to file
07.4 Backup files
07.5 Copy text between files
07.6 Viewing a file
07.7 Changing the file name
usr\_08.txt Splitting windows
08.1 Split a window
08.2 Split a window on another file
08.3 Window size
08.4 Vertical splits
08.5 Moving windows
08.6 Commands for all windows
08.7 Viewing differences with vimdiff
08.8 Various
usr\_09.txt Using the GUI
09.1 Parts of the GUI
09.2 Using the mouse
09.3 The clipboard
09.4 Select mode
usr\_10.txt Making big changes
10.1 Record and playback commands
10.2 Substitution
10.3 Command ranges
10.4 The global command
10.5 Visual block mode
10.6 Reading and writing part of a file
10.7 Formatting text
10.8 Changing case
10.9 Using an external program
usr\_11.txt Recovering from a crash
11.1 Basic recovery
11.2 Where is the swap file?
11.3 Crashed or not?
11.4 Further reading
usr\_toc.txt β 35
usr\_12.txt Clever tricks
12.1 Replace a word
12.2 Change "Last, First" to "First Last"
12.3 Sort a list
12.4 Reverse line order
12.5 Count words
12.6 Find a man page
12.7 Trim blanks
12.8 Find where a word is used
\============================================================================== Editing Effectively
Subjects that can be read independently.
usr\_20.txt Typing command-line commands quickly
20.1 Command line editing
20.2 Command line abbreviations
20.3 Command line completion
20.4 Command line history
20.5 Command line window
usr\_21.txt Go away and come back
21.1 Suspend and resume
21.2 Executing shell commands
21.3 Remembering information; viminfo
21.4 Sessions
21.5 Views
21.6 Modelines
usr\_22.txt Finding the file to edit
22.1 The file explorer
22.2 The current directory
22.3 Finding a file
22.4 The buffer list
usr\_23.txt Editing other files
23.1 DOS, Mac and Unix files
23.2 Files on the internet
23.3 Encryption
23.4 Binary files
23.5 Compressed files
usr\_24.txt Inserting quickly
24.1 Making corrections
24.2 Showing matches
24.3 Completion
24.4 Repeating an insert
24.5 Copying from another line
24.6 Inserting a register
24.7 Abbreviations
24.8 Entering special characters
24.9 Digraphs
24.10 Normal mode commands
usr\_toc.txt β 36
usr\_25.txt Editing formatted text
25.1 Breaking lines
25.2 Aligning text
25.3 Indents and tabs
25.4 Dealing with long lines
25.5 Editing tables
usr\_26.txt Repeating
26.1 Repeating with Visual mode
26.2 Add and subtract
26.3 Making a change in many files
26.4 Using Vim from a shell script
usr\_27.txt Search commands and patterns 27.1 Ignoring case
27.2 Wrapping around the file end
27.3 Offsets
27.4 Matching multiple times
27.5 Alternatives
27.6 Character ranges
27.7 Character classes
27.8 Matching a line break
27.9 Examples
usr\_28.txt Folding
28.1 What is folding?
28.2 Manual folding
28.3 Working with folds
28.4 Saving and restoring folds
28.5 Folding by indent
28.6 Folding with markers
28.7 Folding by syntax
28.8 Folding by expression
28.9 Folding unchanged lines
28.10 Which fold method to use?
usr\_29.txt Moving through programs
29.1 Using tags
29.2 The preview window
29.3 Moving through a program
29.4 Finding global identifiers
29.5 Finding local identifiers
usr\_30.txt Editing programs
30.1 Compiling
30.2 Indenting C files
30.3 Automatic indenting
30.4 Other indenting
30.5 Tabs and spaces
30.6 Formatting comments
usr\_31.txt Exploiting the GUI
31.1 The file browser
usr\_toc.txt β 37
31.2 Confirmation
31.3 Menu shortcuts
31.4 Vim window position and size
31.5 Various
usr\_32.txt The undo tree
32.1 Undo up to a file write
32.2 Numbering changes
32.3 Jumping around the tree
32.4 Time travelling
\============================================================================== Tuning Vim
Make Vim work as you like it.
usr\_40.txt Make new commands
40.1 Key mapping
40.2 Defining command-line commands
40.3 Autocommands
usr\_41.txt Write a Vim script
41.1 Introduction
41.2 Variables
41.3 Expressions
41.4 Conditionals
41.5 Executing an expression
41.6 Using functions
41.7 Defining a function
41.8 Lists and Dictionaries
41.9 Exceptions
41.10 Various remarks
41.11 Writing a plugin
41.12 Writing a filetype plugin
41.13 Writing a compiler plugin
41.14 Writing a plugin that loads quickly
41.15 Writing library scripts
41.16 Distributing Vim scripts
usr\_42.txt Add new menus
42.1 Introduction
42.2 Menu commands
42.3 Various
42.4 Toolbar and popup menus
usr\_43.txt Using filetypes
43.1 Plugins for a filetype
43.2 Adding a filetype
usr\_44.txt Your own syntax highlighted
44.1 Basic syntax commands
44.2 Keywords
44.3 Matches
44.4 Regions
usr\_toc.txt β 38
44.5 Nested items
44.6 Following groups
44.7 Other arguments
44.8 Clusters
44.9 Including another syntax file
44.10 Synchronizing
44.11 Installing a syntax file
44.12 Portable syntax file layout
usr\_45.txt Select your language
45.1 Language for Messages
45.2 Language for Menus
45.3 Using another encoding
45.4 Editing files with a different encoding
45.5 Entering language text
\============================================================================== Making Vim Run
Before you can use Vim.
usr\_90.txt Installing Vim
90.1 Unix
90.2 MS-Windows
90.3 Upgrading
90.4 Common installation issues
90.5 Uninstalling Vim
\============================================================================== Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl:
usr\_toc.txt β 39
usr\_01.txt For Vim version 8.0. Last change: 2017 Jul 15 VIM USER MANUAL \- by Bram Moolenaar
About the manuals
This chapter introduces the manuals available with Vim. Read this to know the conditions under which the commands are explained.
01.1 Two manuals
01.2 Vim installed
01.3 Using the Vim tutor
01.4 Copyright
Next chapter: usr\_02.txt The first steps in Vim
Table of contents: usr\_toc.txt
\============================================================================== 01.1 Two manuals
The Vim documentation consists of two parts:
1\. The User manual
Task oriented explanations, from simple to complex. Reads from start to end like a book.
2\. The Reference manual
Precise description of how everything in Vim works.
The notation used in these manuals is explained here: notation
JUMPING AROUND
The text contains hyperlinks between the two parts, allowing you to quickly jump between the description of an editing task and a precise explanation of the commands and options used for it. Use these two commands:
Press CTRL-\] to jump to a subject under the cursor.
Press CTRL-O to jump back (repeat to go further back).
Many links are in vertical bars, like this: bars . The bars themselves may be hidden or invisible, see below. An option name, like 'number', a command in double quotes like ":write" and any other word can also be used as a link. Try it out: Move the cursor to CTRL-\] and press CTRL-\] on it.
Other subjects can be found with the ":help" command, see help.txt .
The bars and stars are usually hidden with the conceal feature. They also use hl-Ignore , using the same color for the text as the background. You can make them visible with:
:set conceallevel=0
:hi link HelpBar Normal
usr\_01.txt β 40
:hi link HelpStar Normal
\============================================================================== 01.2 Vim installed
Most of the manuals assume that Vim has been properly installed. If you didn't do that yet, or if Vim doesn't run properly (e.g., files can't be found or in the GUI the menus do not show up) first read the chapter on installation: usr\_90.txt .
not-compatible
The manuals often assume you are using Vim with Vi-compatibility switched off. For most commands this doesn't matter, but sometimes it is important, e.g., for multi-level undo. An easy way to make sure you are using a nice setup is to copy the example vimrc file. By doing this inside Vim you don't have to check out where it is located. How to do this depends on the system you are using:
Unix:
:\!cp \-i \$VIMRUNTIME/vimrc\_example.vim \~/.vimrc
MS-DOS, MS-Windows, OS/2:
:\!copy \$VIMRUNTIME/vimrc\_example.vim \$VIM/\_vimrc
Amiga:
:\!copy \$VIMRUNTIME/vimrc\_example.vim \$VIM/.vimrc
If the file already exists you probably want to keep it.
If you start Vim now, the 'compatible' option should be off. You can check it with this command:
:set compatible?
If it responds with "nocompatible" you are doing well. If the response is "compatible" you are in trouble. You will have to find out why the option is still set. Perhaps the file you wrote above is not found. Use this command to find out:
:scriptnames
If your file is not in the list, check its location and name. If it is in the list, there must be some other place where the 'compatible' option is switched back on.
For more info see vimrc and compatible-default .
Note:
This manual is about using Vim in the normal way. There is an alternative called "evim" (easy Vim). This is still Vim, but used in a way that resembles a click-and-type editor like Notepad. It always stays in Insert mode, thus it feels very different. It is not explained in the user manual, since it should be mostly self explanatory. See evim-keys for details.
\============================================================================== 01.3 Using the Vim tutor tutor vimtutor
usr\_01.txt β 41
Instead of reading the text (boring\!) you can use the vimtutor to learn your first Vim commands. This is a 30 minute tutorial that teaches the most basic Vim functionality hands-on.
On Unix, if Vim has been properly installed, you can start it from the shell: vimtutor
On MS-Windows you can find it in the Program/Vim menu. Or execute vimtutor.bat in the \$VIMRUNTIME directory.
This will make a copy of the tutor file, so that you can edit it without the risk of damaging the original.
There are a few translated versions of the tutor. To find out if yours is available, use the two-letter language code. For French:
vimtutor fr
On Unix, if you prefer using the GUI version of Vim, use "gvimtutor" or "vimtutor \-g" instead of "vimtutor".
For OpenVMS, if Vim has been properly installed, you can start vimtutor from a VMS prompt with:
@VIM:vimtutor
Optionally add the two-letter language code as above.
On other systems, you have to do a little work:
1\. Copy the tutor file. You can do this with Vim (it knows where to find it): vim \--clean \-c 'e \$VIMRUNTIME/tutor/tutor' \-c 'w\! TUTORCOPY' \-c 'q'
This will write the file "TUTORCOPY" in the current directory. To use a translated version of the tutor, append the two-letter language code to the filename. For French:
vim \--clean \-c 'e \$VIMRUNTIME/tutor/tutor.fr' \-c 'w\! TUTORCOPY' \-c 'q' 2\. Edit the copied file with Vim:
vim \--clean TUTORCOPY
The \--clean argument makes sure Vim is started with nice defaults. 3\. Delete the copied file when you are finished with it:
del TUTORCOPY
\============================================================================== 01.4 Copyright manual-copyright
usr\_01.txt β 42
The Vim user manual and reference manual are Copyright (c) 1988-2003 by Bram Moolenaar. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later. The latest version is presently available at:
http\://www\.opencontent.org/openpub/
People who contribute to the manuals must agree with the above copyright notice.
frombook
Parts of the user manual come from the book "Vi IMproved \- Vim" by Steve Oualline (published by New Riders Publishing, ISBN: 0735710015). The Open Publication License applies to this book. Only selected parts are included and these have been modified (e.g., by removing the pictures, updating the text for Vim 6.0 and later, fixing mistakes). The omission of the frombook tag does not mean that the text does not come from the book.
Many thanks to Steve Oualline and New Riders for creating this book and publishing it under the OPL\! It has been a great help while writing the user manual. Not only by providing literal text, but also by setting the tone and style.
If you make money through selling the manuals, you are strongly encouraged to donate part of the profit to help AIDS victims in Uganda. See iccf .
\============================================================================== Next chapter: usr\_02.txt The first steps in Vim
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_01.txt β 43
usr\_02.txt For Vim version 8.0. Last change: 2017 Mar 14 VIM USER MANUAL \- by Bram Moolenaar
The first steps in Vim
This chapter provides just enough information to edit a file with Vim. Not well or fast, but you can edit. Take some time to practice with these commands, they form the base for what follows.
02.1 Running Vim for the First Time
02.2 Inserting text
02.3 Moving around
02.4 Deleting characters
02.5 Undo and Redo
02.6 Other editing commands
02.7 Getting out
02.8 Finding help
Next chapter: usr\_03.txt Moving around
Previous chapter: usr\_01.txt About the manuals
Table of contents: usr\_toc.txt
\============================================================================== 02.1 Running Vim for the First Time
To start Vim, enter this command:
gvim file.txt
In UNIX you can type this at any command prompt. If you are running Microsoft Windows, open an MS-DOS prompt window and enter the command. In either case, Vim starts editing a file called file.txt. Because this is a new file, you get a blank window. This is what your screen will look like:
\+---------------------------------------+
\|\# \|
\|\~ \|
\|\~ \|
\|\~ \|
\|\~ \|
\|"file.txt" \[New file\] \|
\+---------------------------------------+
('\#" is the cursor position.)
The tilde (\~) lines indicate lines not in the file. In other words, when Vim runs out of file to display, it displays tilde lines. At the bottom of the screen, a message line indicates the file is named file.txt and shows that you are creating a new file. The message information is temporary and other information overwrites it.
usr\_02.txt β 44
THE VIM COMMAND
The gvim command causes the editor to create a new window for editing. If you use this command:
vim file.txt
the editing occurs inside your command window. In other words, if you are running inside an xterm, the editor uses your xterm window. If you are using an MS-DOS command prompt window under Microsoft Windows, the editing occurs inside this window. The text in the window will look the same for both versions, but with gvim you have extra features, like a menu bar. More about that later.
\============================================================================== 02.2 Inserting text
The Vim editor is a modal editor. That means that the editor behaves differently, depending on which mode you are in. The two basic modes are called Normal mode and Insert mode. In Normal mode the characters you type are commands. In Insert mode the characters are inserted as text.
Since you have just started Vim it will be in Normal mode. To start Insert mode you type the "i" command (i for Insert). Then you can enter the text. It will be inserted into the file. Do not worry if you make mistakes; you can correct them later. To enter the following programmer's limerick, this is what you type:
iA very intelligent turtle
Found programming UNIX a hurdle
After typing "turtle" you press the \<Enter\> key to start a new line. Finally you press the \<Esc\> key to stop Insert mode and go back to Normal mode. You now have two lines of text in your Vim window:
\+---------------------------------------+
\|A very intelligent turtle \|
\|Found programming UNIX a hurdle \|
\|\~ \|
\|\~ \|
\| \|
\+---------------------------------------+
WHAT IS THE MODE?
To be able to see what mode you are in, type this command:
:set showmode
You will notice that when typing the colon Vim moves the cursor to the last line of the window. That's where you type colon commands (commands that start with a colon). Finish this command by pressing the \<Enter\> key (all commands that start with a colon are finished this way).
Now, if you type the "i" command Vim will display \--INSERT-- at the bottom usr\_02.txt β 45
of the window. This indicates you are in Insert mode.
\+---------------------------------------+
\|A very intelligent turtle \|
\|Found programming UNIX a hurdle \|
\|\~ \|
\|\~ \|
\|-- INSERT \-- \|
\+---------------------------------------+
If you press \<Esc\> to go back to Normal mode the last line will be made blank.
GETTING OUT OF TROUBLE
One of the problems for Vim novices is mode confusion, which is caused by forgetting which mode you are in or by accidentally typing a command that switches modes. To get back to Normal mode, no matter what mode you are in, press the \<Esc\> key. Sometimes you have to press it twice. If Vim beeps back at you, you already are in Normal mode.
\============================================================================== 02.3 Moving around
After you return to Normal mode, you can move around by using these keys:
h left hjkl j down
k up
l right
At first, it may appear that these commands were chosen at random. After all, who ever heard of using l for right? But actually, there is a very good reason for these choices: Moving the cursor is the most common thing you do in an editor, and these keys are on the home row of your right hand. In other words, these commands are placed where you can type them the fastest (especially when you type with ten fingers).
Note:
You can also move the cursor by using the arrow keys. If you do, however, you greatly slow down your editing because to press the arrow keys, you must move your hand from the text keys to the arrow keys. Considering that you might be doing it hundreds of times an hour, this can take a significant amount of time.
Also, there are keyboards which do not have arrow keys, or which locate them in unusual places; therefore, knowing the use of the hjkl keys helps in those situations.
One way to remember these commands is that h is on the left, l is on the right and j points down. In a picture:
k
h l
j
usr\_02.txt β 46
The best way to learn these commands is by using them. Use the "i" command to insert some more lines of text. Then use the hjkl keys to move around and insert a word somewhere. Don't forget to press \<Esc\> to go back to Normal mode. The vimtutor is also a nice way to learn by doing.
For Japanese users, Hiroshi Iwatani suggested using this:
Komsomolsk
^
\|
Huan Ho \<--- \---\> Los Angeles
(Yellow river) \|
v
Java (the island, not the programming language)
\============================================================================== 02.4 Deleting characters
To delete a character, move the cursor over it and type "x". (This is a throwback to the old days of the typewriter, when you deleted things by typing xxxx over them.) Move the cursor to the beginning of the first line, for example, and type xxxxxxx (seven x's) to delete "A very ". The result should look like this:
\+---------------------------------------+
\|intelligent turtle \|
\|Found programming UNIX a hurdle \|
\|\~ \|
\|\~ \|
\| \|
\+---------------------------------------+
Now you can insert new text, for example by typing:
iA young \<Esc\>
This begins an insert (the i), inserts the words "A young", and then exits insert mode (the final \<Esc\>). The result:
\+---------------------------------------+
\|A young intelligent turtle \|
\|Found programming UNIX a hurdle \|
\|\~ \|
\|\~ \|
\| \|
\+---------------------------------------+
DELETING A LINE
To delete a whole line use the "dd" command. The following line will then move up to fill the gap:
usr\_02.txt β 47
\+---------------------------------------+
\|Found programming UNIX a hurdle \|
\|\~ \|
\|\~ \|
\|\~ \|
\| \|
\+---------------------------------------+
DELETING A LINE BREAK
In Vim you can join two lines together, which means that the line break between them is deleted. The "J" command does this.
Take these two lines:
A young intelligent
turtle
Move the cursor to the first line and press "J":
A young intelligent turtle
\============================================================================== 02.5 Undo and Redo
Suppose you delete too much. Well, you can type it in again, but an easier way exists. The "u" command undoes the last edit. Take a look at this in action: After using "dd" to delete the first line, "u" brings it back. Another one: Move the cursor to the A in the first line:
A young intelligent turtle
Now type xxxxxxx to delete "A young". The result is as follows: intelligent turtle
Type "u" to undo the last delete. That delete removed the g, so the undo restores the character.
g intelligent turtle
The next u command restores the next-to-last character deleted: ng intelligent turtle
The next u command gives you the u, and so on:
ung intelligent turtle
oung intelligent turtle
young intelligent turtle
young intelligent turtle
A young intelligent turtle
Note:
usr\_02.txt β 48
If you type "u" twice, and the result is that you get the same text back, you have Vim configured to work Vi compatible. Look here to fix this: not-compatible .
This text assumes you work "The Vim Way". You might prefer to use the good old Vi way, but you will have to watch out for small differences in the text then.
REDO
If you undo too many times, you can press CTRL-R (redo) to reverse the preceding command. In other words, it undoes the undo. To see this in action, press CTRL-R twice. The character A and the space after it disappear:
young intelligent turtle
There's a special version of the undo command, the "U" (undo line) command. The undo line command undoes all the changes made on the last line that was edited. Typing this command twice cancels the preceding "U".
A very intelligent turtle
xxxx Delete very
A intelligent turtle
xxxxxx Delete turtle
A intelligent
Restore line with "U"
A very intelligent turtle
Undo "U" with "u"
A intelligent
The "U" command is a change by itself, which the "u" command undoes and CTRL-R redoes. This might be a bit confusing. Don't worry, with "u" and CTRL-R you can go to any of the situations you had. More about that in section 32.2 .
\============================================================================== 02.6 Other editing commands
Vim has a large number of commands to change the text. See Q\_in and below. Here are a few often used ones.
APPENDING
The "i" command inserts a character before the character under the cursor. That works fine; but what happens if you want to add stuff to the end of the line? For that you need to insert text after the cursor. This is done with the "a" (append) command.
For example, to change the line
and that's not saying much for the turtle.
to
and that's not saying much for the turtle\!\!\!
usr\_02.txt β 49
move the cursor over to the dot at the end of the line. Then type "x" to delete the period. The cursor is now positioned at the end of the line on the e in turtle. Now type
a\!\!\!\<Esc\>
to append three exclamation points after the e in turtle:
and that's not saying much for the turtle\!\!\!
OPENING UP A NEW LINE
The "o" command creates a new, empty line below the cursor and puts Vim in Insert mode. Then you can type the text for the new line.
Suppose the cursor is somewhere in the first of these two lines:
A very intelligent turtle
Found programming UNIX a hurdle
If you now use the "o" command and type new text:
oThat liked using Vim\<Esc\>
The result is:
A very intelligent turtle
That liked using Vim
Found programming UNIX a hurdle
The "O" command (uppercase) opens a line above the cursor.
USING A COUNT
Suppose you want to move up nine lines. You can type "kkkkkkkkk" or you can enter the command "9k". In fact, you can precede many commands with a number. Earlier in this chapter, for instance, you added three exclamation points to the end of a line by typing "a\!\!\!\<Esc\>". Another way to do this is to use the command "3a\!\<Esc\>". The count of 3 tells the command that follows to triple its effect. Similarly, to delete three characters, use the command "3x". The count always comes before the command it applies to.
\============================================================================== 02.7 Getting out
To exit, use the "ZZ" command. This command writes the file and exits.
Note:
Unlike many other editors, Vim does not automatically make a backup file. If you type "ZZ", your changes are committed and there's no turning back. You can configure the Vim editor to produce backup files, see 07.4 .
usr\_02.txt β 50
DISCARDING CHANGES
Sometimes you will make a sequence of changes and suddenly realize you were better off before you started. Not to worry; Vim has a
quit-and-throw-things-away command. It is:
:q\!
Don't forget to press \<Enter\> to finish the command.
For those of you interested in the details, the three parts of this command are the colon (:), which enters Command-line mode; the q command, which tells the editor to quit; and the override command modifier (\!).
The override command modifier is needed because Vim is reluctant to throw away changes. If you were to just type ":q", Vim would display an error message and refuse to exit:
E37: No write since last change (use \! to override)
By specifying the override, you are in effect telling Vim, "I know that what I'm doing looks stupid, but I'm a big boy and really want to do this."
If you want to continue editing with Vim: The ":e\!" command reloads the original version of the file.
\============================================================================== 02.8 Finding help
Everything you always wanted to know can be found in the Vim help files. Don't be afraid to ask\!
If you know what you are looking for, it is usually easier to search for it using the help system, instead of using Google. Because the subjects follow a certain style guide.
Also the help has the advantage of belonging to your particular Vim version. You won't see help for commands added later. These would not work for you.
To get generic help use this command:
:help
You could also use the first function key \<F1\>. If your keyboard has a \<Help\> key it might work as well.
If you don't supply a subject, ":help" displays the general help window. The creators of Vim did something very clever (or very lazy) with the help system: They made the help window a normal editing window. You can use all the normal Vim commands to move through the help information. Therefore h, j, k, and l move left, down, up and right.
To get out of the help window, use the same command you use to get out of the editor: "ZZ". This will only close the help window, not exit Vim.
usr\_02.txt β 51
As you read the help text, you will notice some text enclosed in vertical bars (for example, help ). This indicates a hyperlink. If you position the cursor anywhere between the bars and press CTRL-\] (jump to tag), the help system takes you to the indicated subject. (For reasons not discussed here, the Vim terminology for a hyperlink is tag. So CTRL-\] jumps to the location of the tag given by the word under the cursor.)
After a few jumps, you might want to go back. CTRL-T (pop tag) takes you back to the preceding position. CTRL-O (jump to older position) also works nicely here.
At the top of the help screen, there is the notation \*help.txt\*. This name between "\*" characters is used by the help system to define a tag (hyperlink destination).
See 29.1 for details about using tags.
To get help on a given subject, use the following command:
:help {subject}
To get help on the "x" command, for example, enter the following: :help x
To find out how to delete text, use this command:
:help deleting
To get a complete index of all Vim commands, use the following command: :help index
When you need to get help for a control character command (for example, CTRL-A), you need to spell it with the prefix "CTRL-".
:help CTRL-A
The Vim editor has many different modes. By default, the help system displays the normal-mode commands. For example, the following command displays help for the normal-mode CTRL-H command:
:help CTRL-H
To identify other modes, use a mode prefix. If you want the help for the insert-mode version of a command, use "i\_". For CTRL-H this gives you the following command:
:help i\_CTRL-H
When you start the Vim editor, you can use several command-line arguments. These all begin with a dash (-). To find what the \-t argument does, for example, use the command:
:help \-t
The Vim editor has a number of options that enable you to configure and usr\_02.txt β 52
customize the editor. If you want help for an option, you need to enclose it in single quotation marks. To find out what the 'number' option does, for example, use the following command:
:help 'number'
The table with all mode prefixes can be found below: help-summary .
Special keys are enclosed in angle brackets. To find help on the up-arrow key in Insert mode, for instance, use this command:
:help i\_\<Up\>
If you see an error message that you don't understand, for example: E37: No write since last change (use \! to override)
You can use the error ID at the start to find help about it: :help E37
Summary: help-summary
1\) Use Ctrl-D after typing a topic and let Vim show all available topics. Or press Tab to complete:
:help some\<Tab\>
More information on how to use the help:
:help helphelp
2\) Follow the links in bars to related help. You can go from the detailed help to the user documentation, which describes certain commands more from a user perspective and less detailed. E.g. after:
:help pattern.txt
You can see the user guide topics 03.9 and usr\_27.txt in the introduction.
3\) Options are enclosed in single apostrophes. To go to the help topic for the list option:
:help 'list'
If you only know you are looking for a certain option, you can also do: :help options.txt
to open the help page which describes all option handling and then search using regular expressions, e.g. textwidth.
Certain options have their own namespace, e.g.:
:help cpo-\<letter\>
for the corresponding flag of the 'cpoptions' settings, substitute \<letter\> by a specific flag, e.g.:
:help cpo-;
And for the guioption flags:
:help go-\<letter\>
4\) Normal mode commands do not have a prefix. To go to the help page for the "gt" command:
usr\_02.txt β 53
:help gt
5\) Insert mode commands start with i\_. Help for deleting a word: :help i\_CTRL-W
6\) Visual mode commands start with v\_. Help for jumping to the other side of the Visual area:
:help v\_o
7\) Command line editing and arguments start with c\_. Help for using the command argument %:
:help c\_%
8\) Ex-commands always start with ":", so to go to the :s command help: :help :s
9\) Commands specifically for debugging start with "\>". To go to the help for the "cont" debug command:
:help \>cont
10\) Key combinations. They usually start with a single letter indicating the mode for which they can be used. E.g.:
:help i\_CTRL-X
takes you to the family of Ctrl-X commands for insert mode which can be used to auto complete different things. Note, that certain keys will always be written the same, e.g. Control will always be CTRL. For normal mode commands there is no prefix and the topic is available at :h CTRL-\<Letter\>. E.g.
:help CTRL-W
In contrast
:help c\_CTRL-R
will describe what the Ctrl-R does when entering commands in the Command line and
:help v\_Ctrl-A
talks about incrementing numbers in visual mode and
:help g\_CTRL-A
talks about the g\<C-A\> command (e.g. you have to press "g" then \<Ctrl-A\>). Here the "g" stand for the normal command "g" which always expects a second key before doing something similar to the commands starting with "z"
11\) Regexp items always start with /. So to get help for the "\\+" quantifier in Vim regexes:
:help /\\+
If you need to know everything about regular expressions, start reading at:
:help pattern.txt
12\) Registers always start with "quote". To find out about the special ":" register:
:help quote:
13\) Vim script is available at
:help eval.txt
Certain aspects of the language are available at :h expr-X where "X" is a usr\_02.txt β 54
single letter. E.g.
:help expr-\!
will take you to the topic describing the "\!" (Not) operator for VimScript.
Also important is
:help function-list
to find a short description of all functions available. Help topics for Vim script functions always include the "()", so:
:help append()
talks about the append Vim script function rather than how to append text in the current buffer.
14\) Mappings are talked about in the help page :h map.txt . Use :help mapmode-i
to find out about the :imap command. Also use :map-topic to find out about certain subtopics particular for mappings. e.g: :help :map-local
for buffer-local mappings or
:help map-bar
for how the '\|' is handled in mappings.
15\) Command definitions are talked about :h command-topic, so use :help command-bar
to find out about the '\!' argument for custom commands.
16\) Window management commands always start with CTRL-W, so you find the corresponding help at :h CTRL-W\_letter. E.g.
:help CTRL-W\_p
for moving the previous accessed window. You can also access :help windows.txt
and read your way through if you are looking for window handling commands.
17\) Use :helpgrep to search in all help pages (and also of any installed plugins). See :helpgrep for how to use it.
To search for a topic:
:helpgrep topic
This takes you to the first match. To go to the next one:
:cnext
All matches are available in the quickfix window which can be opened with:
:copen
Move around to the match you like and press Enter to jump to that help.
18\) The user manual. This describes help topics for beginners in a rather friendly way. Start at usr\_toc.txt to find the table of content (as you might have guessed):
:help usr\_toc.txt
Skim over the contents to find interesting topics. The "Digraphs" and "Entering special characters" items are in chapter 24, so to go to that particular help page:
:help usr\_24.txt
Also if you want to access a certain chapter in the help, the chapter number can be accessed directly like this:
usr\_02.txt β 55
:help 10.1
goes to chapter 10.1 in usr\_10.txt and talks about recording macros.
19\) Highlighting groups. Always start with hl-groupname. E.g. :help hl-WarningMsg
talks about the WarningMsg highlighting group.
20\) Syntax highlighting is namespaced to :syn-topic e.g.
:help :syn-conceal
talks about the conceal argument for the :syn command.
21\) Quickfix commands usually start with :c while location list commands usually start with :l
22\) Autocommand events can be found by their name:
:help BufWinLeave
To see all possible events:
:help autocommand-events
23\) Command-line switches always start with "-". So for the help of the \-f command switch of Vim use:
:help \-f
24\) Optional features always start with "+". To find out about the conceal feature use:
:help \+conceal
25\) Documentation for included filetype specific functionality is usually available in the form ft-\<filetype\>-\<functionality\>. So
:help ft-c-syntax
talks about the C syntax file and the option it provides. Sometimes, additional sections for omni completion
:help ft-php-omni
or filetype plugins
:help ft-tex-plugin
are available.
26\) Error and Warning codes can be looked up directly in the help. So :help E297
takes you exactly to the description of the swap error message and :help W10
talks about the warning "Changing a readonly file".
Sometimes however, those error codes are not described, but rather are listed at the Vim command that usually causes this. So:
:help E128
takes you to the :function command
\============================================================================== Next chapter: usr\_03.txt Moving around
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_02.txt β 56
usr\_02.txt β 57
usr\_03.txt For Vim version 8.0. Last change: 2017 Jul 21 VIM USER MANUAL \- by Bram Moolenaar
Moving around
Before you can insert or delete text the cursor has to be moved to the right place. Vim has a large number of commands to position the cursor. This chapter shows you how to use the most important ones. You can find a list of these commands below Q\_lr .
03.1 Word movement
03.2 Moving to the start or end of a line
03.3 Moving to a character
03.4 Matching a parenthesis
03.5 Moving to a specific line
03.6 Telling where you are
03.7 Scrolling around
03.8 Simple searches
03.9 Simple search patterns
03.10 Using marks
Next chapter: usr\_04.txt Making small changes
Previous chapter: usr\_02.txt The first steps in Vim
Table of contents: usr\_toc.txt
\============================================================================== 03.1 Word movement
To move the cursor forward one word, use the "w" command. Like most Vim commands, you can use a numeric prefix to move past multiple words. For example, "3w" moves three words. This figure shows how it works:
This is a line with example text
\---\>--\>-\>-----------------\>
w w w 3w
Notice that "w" moves to the start of the next word if it already is at the start of a word.
The "b" command moves backward to the start of the previous word:
This is a line with example text
\<----\<--\<-\<---------\<---
b b b 2b b
There is also the "e" command that moves to the next end of a word and "ge", which moves to the previous end of a word:
This is a line with example text
\<- \<--- \-----\> \----\>
ge ge e e
If you are at the last word of a line, the "w" command will take you to the usr\_03.txt β 58
first word in the next line. Thus you can use this to move through a paragraph, much faster than using "l". "b" does the same in the other direction.
A word ends at a non-word character, such as a ".", "-" or ")". To change what Vim considers to be a word, see the 'iskeyword' option. If you try this out in the help directly, 'iskeyword' needs to be reset for the examples to work:
:set iskeyword&
It is also possible to move by white-space separated WORDs. This is not a word in the normal sense, that's why the uppercase is used. The commands for moving by WORDs are also uppercase, as this figure shows:
ge b w e
\<- \<- \---\> \---\>
This is-a line, with special/separated/words (and some more). \<----- \<----- \--------------------\> \-----\>
gE B W E
With this mix of lowercase and uppercase commands, you can quickly move forward and backward through a paragraph.
\============================================================================== 03.2 Moving to the start or end of a line
The "\$" command moves the cursor to the end of a line. If your keyboard has an \<End\> key it will do the same thing.
The "^" command moves to the first non-blank character of the line. The "0" command (zero) moves to the very first character of the line. The \<Home\> key does the same thing. In a picture:
^
\<------------
.....This is a line with example text
\<----------------- \---------------\>
0 \$
(the "....." indicates blanks here)
The "\$" command takes a count, like most movement commands. But moving to the end of the line several times doesn't make sense. Therefore it causes the editor to move to the end of another line. For example, "1\$" moves you to the end of the first line (the one you're on), "2\$" to the end of the next line, and so on.
The "0" command doesn't take a count argument, because the "0" would be part of the count. Unexpectedly, using a count with "^" doesn't have any effect.
\============================================================================== 03.3 Moving to a character
One of the most useful movement commands is the single-character search command. The command "fx" searches forward in the line for the single
usr\_03.txt β 59
character x. Hint: "f" stands for "Find".
For example, you are at the beginning of the following line. Suppose you want to go to the h of human. Just execute the command "fh" and the cursor will be positioned over the h:
To err is human. To really foul up you need a computer.
\----------\>---------------\>
fh fy
This also shows that the command "fy" moves to the end of the word really. You can specify a count; therefore, you can go to the "l" of "foul" with "3fl":
To err is human. To really foul up you need a computer.
\---------------------\>
3fl
The "F" command searches to the left:
To err is human. To really foul up you need a computer.
\<---------------------
Fh
The "tx" command works like the "fx" command, except it stops one character before the searched character. Hint: "t" stands for "To". The backward version of this command is "Tx".
To err is human. To really foul up you need a computer.
\<------------ \-------------\>
Th tn
These four commands can be repeated with ";". "," repeats in the other direction. The cursor is never moved to another line. Not even when the sentence continues.
Sometimes you will start a search, only to realize that you have typed the wrong command. You type "f" to search backward, for example, only to realize that you really meant "F". To abort a search, press \<Esc\>. So "f\<Esc\>" is an aborted forward search and doesn't do anything. Note: \<Esc\> cancels most operations, not just searches.
\============================================================================== 03.4 Matching a parenthesis
When writing a program you often end up with nested () constructs. Then the "%" command is very handy: It moves to the matching paren. If the cursor is on a "(" it will move to the matching ")". If it's on a ")" it will move to the matching "(".
%
\<-----\>
if (a \== (b \* c) / d)
\<----------------\>
%
usr\_03.txt β 60
This also works for \[\] and {} pairs. (This can be defined with the 'matchpairs' option.)
When the cursor is not on a useful character, "%" will search forward to find one. Thus if the cursor is at the start of the line of the previous example, "%" will search forward and find the first "(". Then it moves to its match:
if (a \== (b \* c) / d)
\---+----------------\>
%
\============================================================================== 03.5 Moving to a specific line
If you are a C or C++ programmer, you are familiar with error messages such as the following:
prog.c:33: j undeclared (first use in this function)
This tells you that you might want to fix something on line 33\. So how do you find line 33? One way is to do "9999k" to go to the top of the file and "32j" to go down thirty-two lines. It is not a good way, but it works. A much better way of doing things is to use the "G" command. With a count, this command positions you at the given line number. For example, "33G" puts you on line 33\. (For a better way of going through a compiler's error list, see usr\_30.txt , for information on the :make command.)
With no argument, "G" positions you at the end of the file. A quick way to go to the start of a file use "gg". "1G" will do the same, but is a tiny bit more typing.
\| first line of a file ^
\| text text text text \|
\| text text text text \| gg
7G \| text text text text \|
\| text text text text
\| text text text text
V text text text text \|
text text text text \| G
text text text text \|
last line of a file V
Another way to move to a line is using the "%" command with a count. For example "50%" moves you to halfway the file. "90%" goes to near the end.
The previous assumes that you want to move to a line in the file, no matter if it's currently visible or not. What if you want to move to one of the lines you can see? This figure shows the three commands you can use:
\+---------------------------+
H \--\> \| text sample text \|
\| sample text \|
\| text sample text \|
\| sample text \|
usr\_03.txt β 61
M \--\> \| text sample text \|
\| sample text \|
\| text sample text \|
\| sample text \|
L \--\> \| text sample text \|
\+---------------------------+
Hints: "H" stands for Home, "M" for Middle and "L" for Last.
\============================================================================== 03.6 Telling where you are
To see where you are in a file, there are three ways:
1\. Use the CTRL-G command. You get a message like this (assuming the 'ruler' option is off):
"usr\_03.txt" line 233 of 650 \--35%-- col 45-52
This shows the name of the file you are editing, the line number where the cursor is, the total number of lines, the percentage of the way through the file and the column of the cursor.
Sometimes you will see a split column number. For example, "col 2-9". This indicates that the cursor is positioned on the second character, but because character one is a tab, occupying eight spaces worth of columns, the screen column is 9\.
2\. Set the 'number' option. This will display a line number in front of every line:
:set number
To switch this off again:
:set nonumber
Since 'number' is a boolean option, prepending "no" to its name has the effect of switching it off. A boolean option has only these two values, it is either on or off.
Vim has many options. Besides the boolean ones there are options with a numerical value and string options. You will see examples of this where they are used.
3\. Set the 'ruler' option. This will display the cursor position in the lower right corner of the Vim window:
:set ruler
Using the 'ruler' option has the advantage that it doesn't take much room, thus there is more space for your text.
\============================================================================== 03.7 Scrolling around
usr\_03.txt β 62
The CTRL-U command scrolls down half a screen of text. Think of looking through a viewing window at the text and moving this window up by half the height of the window. Thus the window moves up over the text, which is backward in the file. Don't worry if you have a little trouble remembering which end is up. Most users have the same problem.
The CTRL-D command moves the viewing window down half a screen in the file, thus scrolls the text up half a screen.
\+----------------+
\| some text \|
\| some text \|
\| some text \|
\+---------------+ \| some text \|
\| some text \| CTRL-U \--\> \| \|
\| \| \| 123456 \|
\| 123456 \| \+----------------+
\| 7890 \|
\| \| \+----------------+
\| example \| CTRL-D \--\> \| 7890 \|
\+---------------+ \| \|
\| example \|
\| example \|
\| example \|
\| example \|
\+----------------+
To scroll one line at a time use CTRL-E (scroll up) and CTRL-Y (scroll down). Think of CTRL-E to give you one line Extra. (If you use MS-Windows compatible key mappings CTRL-Y will redo a change instead of scroll.)
To scroll forward by a whole screen (except for two lines) use CTRL-F. The other way is backward, CTRL-B is the command to use. Fortunately CTRL-F is Forward and CTRL-B is Backward, that's easy to remember.
A common issue is that after moving down many lines with "j" your cursor is at the bottom of the screen. You would like to see the context of the line with the cursor. That's done with the "zz" command.
\+------------------+ \+------------------+
\| some text \| \| some text \|
\| some text \| \| some text \|
\| some text \| \| some text \|
\| some text \| zz \--\> \| line with cursor \|
\| some text \| \| some text \|
\| some text \| \| some text \|
\| line with cursor \| \| some text \|
\+------------------+ \+------------------+
The "zt" command puts the cursor line at the top, "zb" at the bottom. There are a few more scrolling commands, see Q\_sc . To always keep a few lines of context around the cursor, use the 'scrolloff' option.
\============================================================================== 03.8 Simple searches
usr\_03.txt β 63
To search for a string, use the "/string" command. To find the word include, for example, use the command:
/include
You will notice that when you type the "/" the cursor jumps to the last line of the Vim window, like with colon commands. That is where you type the word. You can press the backspace key (backarrow or \<BS\>) to make corrections. Use the \<Left\> and \<Right\> cursor keys when necessary.
Pressing \<Enter\> executes the command.
Note:
The characters .\*\[\]^%/\\?\~\$ have special meanings. If you want to use them in a search you must put a \\ in front of them. See below.
To find the next occurrence of the same string use the "n" command. Use this to find the first \#include after the cursor:
/\#include
And then type "n" several times. You will move to each \#include in the text. You can also use a count if you know which match you want. Thus "3n" finds the third match. Using a count with "/" doesn't work.
The "?" command works like "/" but searches backwards:
?word
The "N" command repeats the last search the opposite direction. Thus using "N" after a "/" command searches backwards, using "N" after "?" searches forward.
IGNORING CASE
Normally you have to type exactly what you want to find. If you don't care about upper or lowercase in a word, set the 'ignorecase' option:
:set ignorecase
If you now search for "word", it will also match "Word" and "WORD". To match case again:
:set noignorecase
HISTORY
Suppose you do three searches:
/one
/two
/three
usr\_03.txt β 64
Now let's start searching by typing a simple "/" without pressing \<Enter\>. If you press \<Up\> (the cursor key), Vim puts "/three" on the command line. Pressing \<Enter\> at this point searches for three. If you do not press \<Enter\>, but press \<Up\> instead, Vim changes the prompt to "/two". Another press of \<Up\> moves you to "/one".
You can also use the \<Down\> cursor key to move through the history of search commands in the other direction.
If you know what a previously used pattern starts with, and you want to use it again, type that character before pressing \<Up\>. With the previous example, you can type "/o\<Up\>" and Vim will put "/one" on the command line.
The commands starting with ":" also have a history. That allows you to recall a previous command and execute it again. These two histories are separate.
SEARCHING FOR A WORD IN THE TEXT
Suppose you see the word "TheLongFunctionName" in the text and you want to find the next occurrence of it. You could type "/TheLongFunctionName", but that's a lot of typing. And when you make a mistake Vim won't find it.
There is an easier way: Position the cursor on the word and use the "\*" command. Vim will grab the word under the cursor and use it as the search string.
The "\#" command does the same in the other direction. You can prepend a count: "3\*" searches for the third occurrence of the word under the cursor.
SEARCHING FOR WHOLE WORDS
If you type "/the" it will also match "there". To only find words that end in "the" use:
/the\\\>
The "\\\>" item is a special marker that only matches at the end of a word. Similarly "\\\<" only matches at the beginning of a word. Thus to search for the word "the" only:
/\\\<the\\\>
This does not match "there" or "soothe". Notice that the "\*" and "\#" commands use these start-of-word and end-of-word markers to only find whole words (you can use "g\*" and "g\#" to match partial words).
HIGHLIGHTING MATCHES
While editing a program you see a variable called "nr". You want to check where it's used. You could move the cursor to "nr" and use the "\*" command and press "n" to go along all the matches.
There is another way. Type this command:
usr\_03.txt β 65
:set hlsearch
If you now search for "nr", Vim will highlight all matches. That is a very good way to see where the variable is used, without the need to type commands. To switch this off:
:set nohlsearch
Then you need to switch it on again if you want to use it for the next search command. If you only want to remove the highlighting, use this command:
:nohlsearch
This doesn't reset the option. Instead, it disables the highlighting. As soon as you execute a search command, the highlighting will be used again. Also for the "n" and "N" commands.
TUNING SEARCHES
There are a few options that change how searching works. These are the essential ones:
:set incsearch
This makes Vim display the match for the string while you are still typing it. Use this to check if the right match will be found. Then press \<Enter\> to really jump to that location. Or type more to change the search string.
:set nowrapscan
This stops the search at the end of the file. Or, when you are searching backwards, at the start of the file. The 'wrapscan' option is on by default, thus searching wraps around the end of the file.
INTERMEZZO
If you like one of the options mentioned before, and set it each time you use Vim, you can put the command in your Vim startup file.
Edit the file, as mentioned at not-compatible . Or use this command to find out where it is:
:scriptnames
Edit the file, for example with:
:edit \~/.vimrc
Then add a line with the command to set the option, just like you typed it in Vim. Example:
Go:set hlsearch\<Esc\>
usr\_03.txt β 66
"G" moves to the end of the file. "o" starts a new line, where you type the ":set" command. You end insert mode with \<Esc\>. Then write the file:
ZZ
If you now start Vim again, the 'hlsearch' option will already be set.
\============================================================================== 03.9 Simple search patterns
The Vim editor uses regular expressions to specify what to search for. Regular expressions are an extremely powerful and compact way to specify a search pattern. Unfortunately, this power comes at a price, because regular expressions are a bit tricky to specify.
In this section we mention only a few essential ones. More about search patterns and commands in chapter 27 usr\_27.txt . You can find the full explanation here: pattern .
BEGINNING AND END OF A LINE
The ^ character matches the beginning of a line. On an English-US keyboard you find it above the 6\. The pattern "include" matches the word include anywhere on the line. But the pattern "^include" matches the word include only if it is at the beginning of a line.
The \$ character matches the end of a line. Therefore, "was\$" matches the word was only if it is at the end of a line.
Let's mark the places where "/the" matches in this example line with "x"s:
the solder holding one of the chips melted and the
xxx xxx xxx
Using "/the\$" we find this match:
the solder holding one of the chips melted and the
xxx
And with "/^the" we find this one:
the solder holding one of the chips melted and the
xxx
You can try searching with "/^the\$", it will only match a single line consisting of "the". White space does matter here, thus if a line contains a space after the word, like "the ", the pattern will not match.
MATCHING ANY SINGLE CHARACTER
The . (dot) character matches any existing character. For example, the pattern "c.m" matches a string whose first character is a c, whose second character is anything, and whose third character is m. Example:
We use a computer that became the cummin winter.
usr\_03.txt β 67
xxx xxx xxx
MATCHING SPECIAL CHARACTERS
If you really want to match a dot, you must avoid its special meaning by putting a backslash before it.
If you search for "ter.", you will find these matches:
We use a computer that became the cummin winter.
xxxx xxxx
Searching for "ter\\." only finds the second match.
\============================================================================== 03.10 Using marks
When you make a jump to a position with the "G" command, Vim remembers the position from before this jump. This position is called a mark. To go back where you came from, use this command:
\`\`
This \` is a backtick or open single-quote character.
If you use the same command a second time you will jump back again. That's because the \` command is a jump itself, and the position from before this jump is remembered.
Generally, every time you do a command that can move the cursor further than within the same line, this is called a jump. This includes the search commands "/" and "n" (it doesn't matter how far away the match is). But not the character searches with "fx" and "tx" or the word movements "w" and "e".
Also, "j" and "k" are not considered to be a jump. Even when you use a count to make them move the cursor quite a long way away.
The \`\` command jumps back and forth, between two points. The CTRL-O command jumps to older positions (Hint: O for older). CTRL-I then jumps back to newer positions (Hint: I is just next to O on the keyboard). Consider this sequence of commands:
33G
/^The
CTRL-O
You first jump to line 33, then search for a line that starts with "The". Then with CTRL-O you jump back to line 33\. Another CTRL-O takes you back to where you started. If you now use CTRL-I you jump to line 33 again. And to the match for "The" with another CTRL-I.
\| example text ^ \|
33G \| example text \| CTRL-O \| CTRL-I
\| example text \| \|
V line 33 text ^ V
usr\_03.txt β 68
\| example text \| \|
/^The \| example text \| CTRL-O \| CTRL-I
V There you are \| V
example text
Note:
CTRL-I is the same as \<Tab\>.
The ":jumps" command gives a list of positions you jumped to. The entry which you used last is marked with a "\>".
NAMED MARKS bookmark
Vim enables you to place your own marks in the text. The command "ma" marks the place under the cursor as mark a. You can place 26 marks (a through z) in your text. You can't see them, it's just a position that Vim remembers.
To go to a mark, use the command \`{mark}, where {mark} is the mark letter. Thus to move to the a mark:
\`a
The command 'mark (single quotation mark, or apostrophe) moves you to the beginning of the line containing the mark. This differs from the \`mark command, which moves you to marked column.
The marks can be very useful when working on two related parts in a file. Suppose you have some text near the start of the file you need to look at, while working on some text near the end of the file.
Move to the text at the start and place the s (start) mark there: ms
Then move to the text you want to work on and put the e (end) mark there: me
Now you can move around, and when you want to look at the start of the file, you use this to jump there:
's
Then you can use '' to jump back to where you were, or 'e to jump to the text you were working on at the end.
There is nothing special about using s for start and e for end, they are just easy to remember.
You can use this command to get a list of marks:
:marks
You will notice a few special marks. These include:
' The cursor position before doing a jump
usr\_03.txt β 69
" The cursor position when last editing the file
\[ Start of the last change
\] End of the last change
\============================================================================== Next chapter: usr\_04.txt Making small changes
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_03.txt β 70
usr\_04.txt For Vim version 8.0. Last change: 2014 Aug 29 VIM USER MANUAL \- by Bram Moolenaar
Making small changes
This chapter shows you several ways of making corrections and moving text around. It teaches you the three basic ways to change text: operator-motion, Visual mode and text objects.
04.1 Operators and motions
04.2 Changing text
04.3 Repeating a change
04.4 Visual mode
04.5 Moving text
04.6 Copying text
04.7 Using the clipboard
04.8 Text objects
04.9 Replace mode
04.10 Conclusion
Next chapter: usr\_05.txt Set your settings
Previous chapter: usr\_03.txt Moving around
Table of contents: usr\_toc.txt
\============================================================================== 04.1 Operators and motions
In chapter 2 you learned the "x" command to delete a single character. And using a count: "4x" deletes four characters.
The "dw" command deletes a word. You may recognize the "w" command as the move word command. In fact, the "d" command may be followed by any motion command, and it deletes from the current location to the place where the cursor winds up.
The "4w" command, for example, moves the cursor over four words. The d4w command deletes four words.
To err is human. To really foul up you need a computer.
\------------------\>
d4w
To err is human. you need a computer.
Vim only deletes up to the position where the motion takes the cursor. That's because Vim knows that you probably don't want to delete the first character of a word. If you use the "e" command to move to the end of a word, Vim guesses that you do want to include that last character:
To err is human. you need a computer.
\--------\>
d2e
To err is human. a computer.
usr\_04.txt β 71
Whether the character under the cursor is included depends on the command you used to move to that character. The reference manual calls this "exclusive" when the character isn't included and "inclusive" when it is.
The "\$" command moves to the end of a line. The "d\$" command deletes from the cursor to the end of the line. This is an inclusive motion, thus the last character of the line is included in the delete operation:
To err is human. a computer.
\------------\>
d\$
To err is human
There is a pattern here: operator-motion. You first type an operator command. For example, "d" is the delete operator. Then you type a motion command like "4l" or "w". This way you can operate on any text you can move over.
\============================================================================== 04.2 Changing text
Another operator is "c", change. It acts just like the "d" operator, except it leaves you in Insert mode. For example, "cw" changes a word. Or more specifically, it deletes a word and then puts you in Insert mode.
To err is human
\-------\>
c2wbe\<Esc\>
To be human
This "c2wbe\<Esc\>" contains these bits:
c the change operator
2w move two words (they are deleted and Insert mode started) be insert this text
\<Esc\> back to Normal mode
If you have paid attention, you will have noticed something strange: The space before "human" isn't deleted. There is a saying that for every problem there is an answer that is simple, clear, and wrong. That is the case with the example used here for the "cw" command. The c operator works just like the d operator, with one exception: "cw". It actually works like "ce", change to end of word. Thus the space after the word isn't included. This is an exception that dates back to the old Vi. Since many people are used to it now, the inconsistency has remained in Vim.
MORE CHANGES
Like "dd" deletes a whole line, "cc" changes a whole line. It keeps the existing indent (leading white space) though.
usr\_04.txt β 72
Just like "d\$" deletes until the end of the line, "c\$" changes until the end of the line. It's like doing "d\$" to delete the text and then "a" to start Insert mode and append new text.
SHORTCUTS
Some operator-motion commands are used so often that they have been given a single letter command:
x stands for dl (delete character under the cursor)
X stands for dh (delete character left of the cursor)
D stands for d\$ (delete to end of the line)
C stands for c\$ (change to end of the line)
s stands for cl (change one character)
S stands for cc (change a whole line)
WHERE TO PUT THE COUNT
The commands "3dw" and "d3w" delete three words. If you want to get really picky about things, the first command, "3dw", deletes one word three times; the command "d3w" deletes three words once. This is a difference without a distinction. You can actually put in two counts, however. For example,
"3d2w" deletes two words, repeated three times, for a total of six words.
REPLACING WITH ONE CHARACTER
The "r" command is not an operator. It waits for you to type a character, and will replace the character under the cursor with it. You could do the same with "cl" or with the "s" command, but with "r" you don't have to press \<Esc\>
there is somerhing grong here
rT rt rw
There is something wrong here
Using a count with "r" causes that many characters to be replaced with the same character. Example:
There is something wrong here
5rx
There is something xxxxx here
To replace a character with a line break use "r\<Enter\>". This deletes one character and inserts a line break. Using a count here only applies to the number of characters deleted: "4r\<Enter\>" replaces four characters with one line break.
\============================================================================== 04.3 Repeating a change
usr\_04.txt β 73
The "." command is one of the most simple yet powerful commands in Vim. It repeats the last change. For instance, suppose you are editing an HTML file and want to delete all the \<B\> tags. You position the cursor on the first \< and delete the \<B\> with the command "df\>". You then go to the \< of the next \</B\> and kill it using the "." command. The "." command executes the last change command (in this case, "df\>"). To delete another tag, position the cursor on the \< and use the "." command.
To \<B\>generate\</B\> a table of \<B\>contents
f\< find first \< \---\>
df\> delete to \> \--\>
f\< find next \< \---------\>
. repeat df\> \---\>
f\< find next \< \-------------\>
. repeat df\> \--\>
The "." command works for all changes you make, except for the "u" (undo), CTRL-R (redo) and commands that start with a colon (:).
Another example: You want to change the word "four" to "five". It appears several times in your text. You can do this quickly with this sequence of commands:
/four\<Enter\> find the first string "four"
cwfive\<Esc\> change the word to "five"
n find the next "four"
. repeat the change to "five"
n find the next "four"
. repeat the change
etc.
\============================================================================== 04.4 Visual mode
To delete simple items the operator-motion changes work quite well. But often it's not so easy to decide which command will move over the text you want to change. Then you can use Visual mode.
You start Visual mode by pressing "v". You move the cursor over the text you want to work on. While you do this, the text is highlighted. Finally type the operator command.
For example, to delete from halfway one word to halfway another word:
This is an examination sample of visual mode
\----------\>
velllld
This is an example of visual mode
When doing this you don't really have to count how many times you have to press "l" to end up in the right position. You can immediately see what text will be deleted when you press "d".
If at any time you decide you don't want to do anything with the highlighted usr\_04.txt β 74
text, just press \<Esc\> and Visual mode will stop without doing anything.
SELECTING LINES
If you want to work on whole lines, use "V" to start Visual mode. You will see right away that the whole line is highlighted, without moving around. When you move left or right nothing changes. When you move up or down the selection is extended whole lines at a time.
For example, select three lines with "Vjj":
\+------------------------+
\| text more text \|
\>\> \| more text more text \| \|
selected lines \>\> \| text text text \| \| Vjj
\>\> \| text more \| V
\| more text more \|
\+------------------------+
SELECTING BLOCKS
If you want to work on a rectangular block of characters, use CTRL-V to start Visual mode. This is very useful when working on tables.
name Q1 Q2 Q3
pierre 123 455 234
john 0 90 39
steve 392 63 334
To delete the middle "Q2" column, move the cursor to the "Q" of "Q2". Press CTRL-V to start blockwise Visual mode. Now move the cursor three lines down with "3j" and to the next word with "w". You can see the first character of the last column is included. To exclude it, use "h". Now press "d" and the middle column is gone.
GOING TO THE OTHER SIDE
If you have selected some text in Visual mode, and discover that you need to change the other end of the selection, use the "o" command (Hint: o for other end). The cursor will go to the other end, and you can move the cursor to change where the selection starts. Pressing "o" again brings you back to the other end.
When using blockwise selection, you have four corners. "o" only takes you to one of the other corners, diagonally. Use "O" to move to the other corner in the same line.
Note that "o" and "O" in Visual mode work very differently from Normal mode, where they open a new line below or above the cursor.
\============================================================================== 04.5 Moving text
usr\_04.txt β 75
When you delete something with the "d", "x", or another command, the text is saved. You can paste it back by using the p command. (The Vim name for this is put).
Take a look at how this works. First you will delete an entire line, by putting the cursor on the line you want to delete and typing "dd". Now you move the cursor to where you want to put the line and use the "p" (put) command. The line is inserted on the line below the cursor.
a line a line a line
line 2 dd line 3 p line 3
line 3 line 2
Because you deleted an entire line, the "p" command placed the text line below the cursor. If you delete part of a line (a word, for instance), the "p" command puts it just after the cursor.
Some more boring try text to out commands.
\----\>
dw
Some more boring text to out commands.
\-------\>
welp
Some more boring text to try out commands.
MORE ON PUTTING
The "P" command puts text like "p", but before the cursor. When you deleted a whole line with "dd", "P" will put it back above the cursor. When you deleted a word with "dw", "P" will put it back just before the cursor.
You can repeat putting as many times as you like. The same text will be used.
You can use a count with "p" and "P". The text will be repeated as many times as specified with the count. Thus "dd" and then "3p" puts three copies of the same deleted line.
SWAPPING TWO CHARACTERS
Frequently when you are typing, your fingers get ahead of your brain (or the other way around?). The result is a typo such as "teh" for "the". Vim makes it easy to correct such problems. Just put the cursor on the e of "teh" and execute the command "xp". This works as follows: "x" deletes the character e and places it in a register. "p" puts the text after the cursor, which is after the h.
teh th the
x p
\============================================================================== usr\_04.txt β 76
04.6 Copying text
To copy text from one place to another, you could delete it, use "u" to undo the deletion and then "p" to put it somewhere else. There is an easier way: yanking. The "y" operator copies text into a register. Then a "p" command can be used to put it.
Yanking is just a Vim name for copying. The "c" letter was already used for the change operator, and "y" was still available. Calling this operator "yank" made it easier to remember to use the "y" key.
Since "y" is an operator, you use "yw" to yank a word. A count is possible as usual. To yank two words use "y2w". Example:
let sqr \= LongVariable \*
\--------------\>
y2w
let sqr \= LongVariable \*
p
let sqr \= LongVariable \* LongVariable
Notice that "yw" includes the white space after a word. If you don't want this, use "ye".
The "yy" command yanks a whole line, just like "dd" deletes a whole line. Unexpectedly, while "D" deletes from the cursor to the end of the line, "Y" works like "yy", it yanks the whole line. Watch out for this inconsistency\! Use "y\$" to yank to the end of the line.
a text line yy a text line a text line
line 2 line 2 p line 2
last line last line a text line
last line
\============================================================================== 04.7 Using the clipboard
If you are using the GUI version of Vim (gvim), you can find the "Copy" item in the "Edit" menu. First select some text with Visual mode, then use the Edit/Copy menu. The selected text is now copied to the clipboard. You can paste the text in other programs. In Vim itself too.
If you have copied text to the clipboard in another application, you can paste it in Vim with the Edit/Paste menu. This works in Normal mode and Insert mode. In Visual mode the selected text is replaced with the pasted text.
The "Cut" menu item deletes the text before it's put on the clipboard. The "Copy", "Cut" and "Paste" items are also available in the popup menu (only when there is a popup menu, of course). If your Vim has a toolbar, you can also find these items there.
If you are not using the GUI, or if you don't like using a menu, you have to use another way. You use the normal "y" (yank) and "p" (put) commands, but
usr\_04.txt β 77
prepend "\* (double-quote star) before it. To copy a line to the clipboard: "\*yy
To put text from the clipboard back into the text:
"\*p
This only works on versions of Vim that include clipboard support. More about the clipboard in section 09.3 and here: clipboard .
\============================================================================== 04.8 Text objects
If the cursor is in the middle of a word and you want to delete that word, you need to move back to its start before you can do "dw". There is a simpler way to do this: "daw".
this is some example text.
daw
this is some text.
The "d" of "daw" is the delete operator. "aw" is a text object. Hint: "aw" stands for "A Word". Thus "daw" is "Delete A Word". To be precise, the white space after the word is also deleted (the white space before the word at the end of the line).
Using text objects is the third way to make changes in Vim. We already had operator-motion and Visual mode. Now we add operator-text object. It is very similar to operator-motion, but instead of operating on the text between the cursor position before and after a movement command, the text object is used as a whole. It doesn't matter where in the object the cursor was.
To change a whole sentence use "cis". Take this text:
Hello there. This
is an example. Just
some text.
Move to the start of the second line, on "is an". Now use "cis":
Hello there. Just
some text.
The cursor is in between the blanks in the first line. Now you type the new sentence "Another line.":
Hello there. Another line. Just
some text.
"cis" consists of the "c" (change) operator and the "is" text object. This stands for "Inner Sentence". There is also the "as" (a sentence) object. The
usr\_04.txt β 78
difference is that "as" includes the white space after the sentence and "is" doesn't. If you would delete a sentence, you want to delete the white space at the same time, thus use "das". If you want to type new text the white space can remain, thus you use "cis".
You can also use text objects in Visual mode. It will include the text object in the Visual selection. Visual mode continues, thus you can do this several times. For example, start Visual mode with "v" and select a sentence with "as". Now you can repeat "as" to include more sentences. Finally you use an operator to do something with the selected sentences.
You can find a long list of text objects here: text-objects .
\============================================================================== 04.9 Replace mode
The "R" command causes Vim to enter replace mode. In this mode, each character you type replaces the one under the cursor. This continues until you type \<Esc\>.
In this example you start Replace mode on the first "t" of "text":
This is text.
Rinteresting.\<Esc\>
This is interesting.
You may have noticed that this command replaced 5 characters in the line with twelve others. The "R" command automatically extends the line if it runs out of characters to replace. It will not continue on the next line.
You can switch between Insert mode and Replace mode with the \<Insert\> key.
When you use \<BS\> (backspace) to make correction, you will notice that the old text is put back. Thus it works like an undo command for the last typed character.
\============================================================================== 04.10 Conclusion
The operators, movement commands and text objects give you the possibility to make lots of combinations. Now that you know how it works, you can use N operators with M movement commands to make N \* M commands\!
You can find a list of operators here: operator
For example, there are many other ways to delete pieces of text. Here are a few often used ones:
x delete character under the cursor (short for "dl")
X delete character before the cursor (short for "dh") D delete from cursor to end of line (short for "d\$")
dw delete from cursor to next start of word
db delete from cursor to previous start of word
diw delete word under the cursor (excluding white space) usr\_04.txt β 79
daw delete word under the cursor (including white space) dG delete until the end of the file
dgg delete until the start of the file
If you use "c" instead of "d" they become change commands. And with "y" you yank the text. And so forth.
There are a few often used commands to make changes that didn't fit somewhere else:
\~ change case of the character under the cursor, and move the cursor to the next character. This is not an operator (unless 'tildeop' is set), thus you can't use it with a motion
command. It does work in Visual mode and changes case for
all the selected text then.
I Start Insert mode after moving the cursor to the first non-blank in the line.
A Start Insert mode after moving the cursor to the end of the line.
\============================================================================== Next chapter: usr\_05.txt Set your settings
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_04.txt β 80
usr\_05.txt For Vim version 8.0. Last change: 2016 Mar 28 VIM USER MANUAL \- by Bram Moolenaar
Set your settings
Vim can be tuned to work like you want it to. This chapter shows you how to make Vim start with options set to different values. Add plugins to extend Vim's capabilities. Or define your own macros.
05.1 The vimrc file
05.2 The example vimrc file explained
05.3 Simple mappings
05.4 Adding a package
05.5 Adding a plugin
05.6 Adding a help file
05.7 The option window
05.8 Often used options
Next chapter: usr\_06.txt Using syntax highlighting
Previous chapter: usr\_04.txt Making small changes
Table of contents: usr\_toc.txt
\============================================================================== 05.1 The vimrc file vimrc-intro
You probably got tired of typing commands that you use very often. To start Vim with all your favorite option settings and mappings, you write them in what is called the vimrc file. Vim executes the commands in this file when it starts up.
If you already have a vimrc file (e.g., when your sysadmin has one setup for you), you can edit it this way:
:edit \$MYVIMRC
If you don't have a vimrc file yet, see vimrc to find out where you can create a vimrc file. Also, the ":version" command mentions the name of the "user vimrc file" Vim looks for.
For Unix and Macintosh this file is always used and is recommended: \~/.vimrc
For MS-DOS and MS-Windows you can use one of these:
\$HOME/\_vimrc
\$VIM/\_vimrc
The vimrc file can contain all the commands that you type after a colon. The most simple ones are for setting options. For example, if you want Vim to always start with the 'incsearch' option on, add this line your vimrc file:
usr\_05.txt β 81
set incsearch
For this new line to take effect you need to exit Vim and start it again. Later you will learn how to do this without exiting Vim.
This chapter only explains the most basic items. For more information on how to write a Vim script file: usr\_41.txt .
\============================================================================== 05.2 The example vimrc file explained vimrc\_example.vim
In the first chapter was explained how the example vimrc (included in the Vim distribution) file can be used to make Vim startup in not-compatible mode (see not-compatible ). The file can be found here:
\$VIMRUNTIME/vimrc\_example.vim
In this section we will explain the various commands used in this file. This will give you hints about how to set up your own preferences. Not everything will be explained though. Use the ":help" command to find out more.
set nocompatible
As mentioned in the first chapter, these manuals explain Vim working in an improved way, thus not completely Vi compatible. Setting the 'compatible' option off, thus 'nocompatible' takes care of this.
set backspace=indent,eol,start
This specifies where in Insert mode the \<BS\> is allowed to delete the character in front of the cursor. The three items, separated by commas, tell Vim to delete the white space at the start of the line, a line break and the character before where Insert mode started.
set autoindent
This makes Vim use the indent of the previous line for a newly created line. Thus there is the same amount of white space before the new line. For example when pressing \<Enter\> in Insert mode, and when using the "o" command to open a new line.
if has("vms")
set nobackup
else
set backup
endif
This tells Vim to keep a backup copy of a file when overwriting it. But not on the VMS system, since it keeps old versions of files already. The backup file will have the same name as the original file with "\~" added. See 07.4
usr\_05.txt β 82
set history=50
Keep 50 commands and 50 search patterns in the history. Use another number if you want to remember fewer or more lines.
set ruler
Always display the current cursor position in the lower right corner of the Vim window.
set showcmd
Display an incomplete command in the lower right corner of the Vim window, left of the ruler. For example, when you type "2f", Vim is waiting for you to type the character to find and "2f" is displayed. When you press "w" next, the "2fw" command is executed and the displayed "2f" is removed.
\+-------------------------------------------------+
\|text in the Vim window \|
\|\~ \|
\|\~ \|
\|-- VISUAL \-- 2f 43,8 17% \|
\+-------------------------------------------------+
^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^
'showmode' 'showcmd' 'ruler'
set incsearch
Display the match for a search pattern when halfway typing it.
map Q gq
This defines a key mapping. More about that in the next section. This defines the "Q" command to do formatting with the "gq" operator. This is how it worked before Vim 5.0. Otherwise the "Q" command starts Ex mode, but you will not need it.
vnoremap \_g y:exe "grep /" . escape(@", '\\\\/') . "/ \*.c \*.h"\<CR\>
This mapping yanks the visually selected text and searches for it in C files. This is a complicated mapping. You can see that mappings can be used to do quite complicated things. Still, it is just a sequence of commands that are executed like you typed them.
if \&t\_Co \> 2 \|\| has("gui\_running")
syntax on
usr\_05.txt β 83
set hlsearch
endif
This switches on syntax highlighting, but only if colors are available. And the 'hlsearch' option tells Vim to highlight matches with the last used search pattern. The "if" command is very useful to set options only when some condition is met. More about that in usr\_41.txt .
vimrc-filetype
filetype plugin indent on
This switches on three very clever mechanisms:
1\. Filetype detection.
Whenever you start editing a file, Vim will try to figure out what kind of file this is. When you edit "main.c", Vim will see the ".c" extension and recognize this as a "c" filetype. When you edit a file that starts with "\#\!/bin/sh", Vim will recognize it as a "sh" filetype.
The filetype detection is used for syntax highlighting and the other two items below.
See filetypes .
2\. Using filetype plugin files
Many different filetypes are edited with different options. For example, when you edit a "c" file, it's very useful to set the 'cindent' option to automatically indent the lines. These commonly useful option settings are included with Vim in filetype plugins. You can also add your own, see write-filetype-plugin .
3\. Using indent files
When editing programs, the indent of a line can often be computed automatically. Vim comes with these indent rules for a number of filetypes. See :filetype-indent-on and 'indentexpr'.
autocmd FileType text setlocal textwidth=78
This makes Vim break text to avoid lines getting longer than 78 characters. But only for files that have been detected to be plain text. There are actually two parts here. "autocmd FileType text" is an autocommand. This defines that when the file type is set to "text" the following command is automatically executed. "setlocal textwidth=78" sets the 'textwidth' option to 78, but only locally in one file.
restore-cursor
autocmd BufReadPost \*
\\ if line("'\\"") \> 1 && line("'\\"") \<= line("\$") \|
\\ exe "normal\! g\`\\"" \|
\\ endif
Another autocommand. This time it is used after reading any file. The complicated stuff after it checks if the '" mark is defined, and jumps to it if so. The backslash at the start of a line is used to continue the command from the previous line. That avoids a line getting very long. See line-continuation . This only works in a Vim script file, not when
usr\_05.txt β 84
typing commands at the command-line.
\============================================================================== 05.3 Simple mappings
A mapping enables you to bind a set of Vim commands to a single key. Suppose, for example, that you need to surround certain words with curly braces. In other words, you need to change a word such as "amount" into "{amount}". With the :map command, you can tell Vim that the F5 key does this job. The command is as follows:
:map \<F5\> i{\<Esc\>ea}\<Esc\>
Note:
When entering this command, you must enter \<F5\> by typing four characters. Similarly, \<Esc\> is not entered by pressing the \<Esc\> key, but by typing five characters. Watch out for this difference when reading the manual\!
Let's break this down:
\<F5\> The F5 function key. This is the trigger key that causes the command to be executed as the key is pressed.
i{\<Esc\> Insert the { character. The \<Esc\> key ends Insert mode. e Move to the end of the word.
a}\<Esc\> Append the } to the word.
After you execute the ":map" command, all you have to do to put {} around a word is to put the cursor on the first character and press F5.
In this example, the trigger is a single key; it can be any string. But when you use an existing Vim command, that command will no longer be available. You better avoid that.
One key that can be used with mappings is the backslash. Since you probably want to define more than one mapping, add another character. You could map "\\p" to add parentheses around a word, and "\\c" to add curly braces, for example:
:map \\p i(\<Esc\>ea)\<Esc\>
:map \\c i{\<Esc\>ea}\<Esc\>
You need to type the \\ and the p quickly after another, so that Vim knows they belong together.
The ":map" command (with no arguments) lists your current mappings. At least the ones for Normal mode. More about mappings in section 40.1 .
\============================================================================== 05.4 Adding a package add-package matchit-install
A package is a set of files that you can add to Vim. There are two kinds of packages: optional and automatically loaded on startup.
usr\_05.txt β 85
The Vim distribution comes with a few packages that you can optionally use. For example, the matchit plugin. This plugin makes the "%" command jump to matching HTML tags, if/else/endif in Vim scripts, etc. Very useful, although it's not backwards compatible (that's why it is not enabled by default).
To start using the matchit plugin, add one line to your vimrc file: packadd\! matchit
That's all\! After restarting Vim you can find help about this plugin: :help matchit
This works, because when \`:packadd\` loaded the plugin it also added the package directory in 'runtimepath', so that the help file can be found.
You can find packages on the Internet in various places. It usually comes as an archive or as a repository. For an archive you can follow these steps: 1\. create the package directory:
mkdir \-p \~/.vim/pack/fancy
"fancy" can be any name of your liking. Use one that describes the package.
2\. unpack the archive in that directory. This assumes the top directory in the archive is "start":
cd \~/.vim/pack/fancy
unzip /tmp/fancy.zip
If the archive layout is different make sure that you end up with a path like this:
\~/.vim/pack/fancy/start/fancytext/plugin/fancy.vim
Here "fancytext" is the name of the package, it can be anything else.
More information about packages can be found here: packages .
\============================================================================== 05.5 Adding a plugin add-plugin plugin
Vim's functionality can be extended by adding plugins. A plugin is nothing more than a Vim script file that is loaded automatically when Vim starts. You can add a plugin very easily by dropping it in your plugin directory. {not available when Vim was compiled without the \|+eval\| feature}
There are two types of plugins:
global plugin: Used for all kinds of files
filetype plugin: Only used for a specific type of file
The global plugins will be discussed first, then the filetype ones add-filetype-plugin .
GLOBAL PLUGINS standard-plugin
When you start Vim, it will automatically load a number of global plugins. You don't have to do anything for this. They add functionality that most
usr\_05.txt β 86
people will want to use, but which was implemented as a Vim script instead of being compiled into Vim. You can find them listed in the help index standard-plugin-list . Also see load-plugins .
add-global-plugin
You can add a global plugin to add functionality that will always be present when you use Vim. There are only two steps for adding a global plugin: 1\. Get a copy of the plugin.
2\. Drop it in the right directory.
GETTING A GLOBAL PLUGIN
Where can you find plugins?
\- Some come with Vim. You can find them in the directory \$VIMRUNTIME/macros and its sub-directories.
\- Download from the net. There is a large collection on http\://www\.vim.org. \- They are sometimes posted in a Vim maillist .
\- You could write one yourself, see write-plugin .
Some plugins come as a vimball archive, see vimball .
Some plugins can be updated automatically, see getscript .
USING A GLOBAL PLUGIN
First read the text in the plugin itself to check for any special conditions. Then copy the file to your plugin directory:
system plugin directory
Unix \~/.vim/plugin/
PC and OS/2 \$HOME/vimfiles/plugin or \$VIM/vimfiles/plugin Amiga s:vimfiles/plugin
Macintosh \$VIM:vimfiles:plugin
Mac OS X \~/.vim/plugin/
RISC-OS Choices:vimfiles.plugin
Example for Unix (assuming you didn't have a plugin directory yet):
mkdir \~/.vim
mkdir \~/.vim/plugin
cp /tmp/yourplugin.vim \~/.vim/plugin
That's all\! Now you can use the commands defined in this plugin.
Instead of putting plugins directly into the plugin/ directory, you may better organize them by putting them into subdirectories under plugin/. As an example, consider using "\~/.vim/plugin/perl/\*.vim" for all your Perl plugins.
FILETYPE PLUGINS add-filetype-plugin ftplugins The Vim distribution comes with a set of plugins for different filetypes that
usr\_05.txt β 87
you can start using with this command:
:filetype plugin on
That's all\! See vimrc-filetype .
If you are missing a plugin for a filetype you are using, or you found a better one, you can add it. There are two steps for adding a filetype plugin: 1\. Get a copy of the plugin.
2\. Drop it in the right directory.
GETTING A FILETYPE PLUGIN
You can find them in the same places as the global plugins. Watch out if the type of file is mentioned, then you know if the plugin is a global or a filetype one. The scripts in \$VIMRUNTIME/macros are global ones, the filetype plugins are in \$VIMRUNTIME/ftplugin.
USING A FILETYPE PLUGIN ftplugin-name
You can add a filetype plugin by dropping it in the right directory. The name of this directory is in the same directory mentioned above for global plugins, but the last part is "ftplugin". Suppose you have found a plugin for the "stuff" filetype, and you are on Unix. Then you can move this file to the ftplugin directory:
mv thefile \~/.vim/ftplugin/stuff.vim
If that file already exists you already have a plugin for "stuff". You might want to check if the existing plugin doesn't conflict with the one you are adding. If it's OK, you can give the new one another name:
mv thefile \~/.vim/ftplugin/stuff\_too.vim
The underscore is used to separate the name of the filetype from the rest, which can be anything. If you use "otherstuff.vim" it wouldn't work, it would be loaded for the "otherstuff" filetype.
On MS-DOS you cannot use long filenames. You would run into trouble if you add a second plugin and the filetype has more than six characters. You can use an extra directory to get around this:
mkdir \$VIM/vimfiles/ftplugin/fortran
copy thefile \$VIM/vimfiles/ftplugin/fortran/too.vim
The generic names for the filetype plugins are:
ftplugin/\<filetype\>.vim
ftplugin/\<filetype\>\_\<name\>.vim
ftplugin/\<filetype\>/\<name\>.vim
Here "\<name\>" can be any name that you prefer.
usr\_05.txt β 88
Examples for the "stuff" filetype on Unix:
\~/.vim/ftplugin/stuff.vim
\~/.vim/ftplugin/stuff\_def.vim
\~/.vim/ftplugin/stuff/header.vim
The \<filetype\> part is the name of the filetype the plugin is to be used for. Only files of this filetype will use the settings from the plugin. The \<name\> part of the plugin file doesn't matter, you can use it to have several plugins for the same filetype. Note that it must end in ".vim".
Further reading:
filetype-plugins Documentation for the filetype plugins and information about how to avoid that mappings cause problems.
load-plugins When the global plugins are loaded during startup. ftplugin-overrule Overruling the settings from a global plugin. write-plugin How to write a plugin script.
plugin-details For more information about using plugins or when your plugin doesn't work.
new-filetype How to detect a new file type.
\============================================================================== 05.6 Adding a help file add-local-help
If you are lucky, the plugin you installed also comes with a help file. We will explain how to install the help file, so that you can easily find help for your new plugin.
Let us use the "doit.vim" plugin as an example. This plugin comes with documentation: "doit.txt". Let's first copy the plugin to the right directory. This time we will do it from inside Vim. (You may skip some of the "mkdir" commands if you already have the directory.)
:\!mkdir \~/.vim
:\!mkdir \~/.vim/plugin
:\!cp /tmp/doit.vim \~/.vim/plugin
The "cp" command is for Unix, on MS-DOS you can use "copy". Now create a "doc" directory in one of the directories in 'runtimepath'. :\!mkdir \~/.vim/doc
Copy the help file to the "doc" directory.
:\!cp /tmp/doit.txt \~/.vim/doc
Now comes the trick, which allows you to jump to the subjects in the new help file: Generate the local tags file with the :helptags command.
:helptags \~/.vim/doc
Now you can use the
usr\_05.txt β 89
:help doit
command to find help for "doit" in the help file you just added. You can see an entry for the local help file when you do:
:help local-additions
The title lines from the local help files are automagically added to this section. There you can see which local help files have been added and jump to them through the tag.
For writing a local help file, see write-local-help .
\============================================================================== 05.7 The option window
If you are looking for an option that does what you want, you can search in the help files here: options . Another way is by using this command:
:options
This opens a new window, with a list of options with a one-line explanation. The options are grouped by subject. Move the cursor to a subject and press \<Enter\> to jump there. Press \<Enter\> again to jump back. Or use CTRL-O.
You can change the value of an option. For example, move to the "displaying text" subject. Then move the cursor down to this line:
set wrap nowrap
When you hit \<Enter\>, the line will change to:
set nowrap wrap
The option has now been switched off.
Just above this line is a short description of the 'wrap' option. Move the cursor one line up to place it in this line. Now hit \<Enter\> and you jump to the full help on the 'wrap' option.
For options that take a number or string argument you can edit the value. Then press \<Enter\> to apply the new value. For example, move the cursor a few lines up to this line:
set so=0
Position the cursor on the zero with "\$". Change it into a five with "r5". Then press \<Enter\> to apply the new value. When you now move the cursor around you will notice that the text starts scrolling before you reach the border. This is what the 'scrolloff' option does, it specifies an offset from the window border where scrolling starts.
\============================================================================== 05.8 Often used options
usr\_05.txt β 90
There are an awful lot of options. Most of them you will hardly ever use. Some of the more useful ones will be mentioned here. Don't forget you can find more help on these options with the ":help" command, with single quotes before and after the option name. For example:
:help 'wrap'
In case you have messed up an option value, you can set it back to the default by putting an ampersand (&) after the option name. Example:
:set iskeyword&
NOT WRAPPING LINES
Vim normally wraps long lines, so that you can see all of the text. Sometimes it's better to let the text continue right of the window. Then you need to scroll the text left-right to see all of a long line. Switch wrapping off with this command:
:set nowrap
Vim will automatically scroll the text when you move to text that is not displayed. To see a context of ten characters, do this:
:set sidescroll=10
This doesn't change the text in the file, only the way it is displayed.
WRAPPING MOVEMENT COMMANDS
Most commands for moving around will stop moving at the start and end of a line. You can change that with the 'whichwrap' option. This sets it to the default value:
:set whichwrap=b,s
This allows the \<BS\> key, when used in the first position of a line, to move the cursor to the end of the previous line. And the \<Space\> key moves from the end of a line to the start of the next one.
To allow the cursor keys \<Left\> and \<Right\> to also wrap, use this command: :set whichwrap=b,s,\<,\>
This is still only for Normal mode. To let \<Left\> and \<Right\> do this in Insert mode as well:
:set whichwrap=b,s,\<,\>,\[,\]
There are a few other flags that can be added, see 'whichwrap'. usr\_05.txt β 91
VIEWING TABS
When there are tabs in a file, you cannot see where they are. To make them visible:
:set list
Now every tab is displayed as ^I. And a \$ is displayed at the end of each line, so that you can spot trailing spaces that would otherwise go unnoticed. A disadvantage is that this looks ugly when there are many Tabs in a file. If you have a color terminal, or are using the GUI, Vim can show the spaces and tabs as highlighted characters. Use the 'listchars' option:
:set listchars=tab:\>-,trail:-
Now every tab will be displayed as "\>---" (with more or less "-") and trailing white space as "-". Looks a lot better, doesn't it?
KEYWORDS
The 'iskeyword' option specifies which characters can appear in a word:
:set iskeyword
iskeyword=@,48-57,\_,192-255
The "@" stands for all alphabetic letters. "48-57" stands for ASCII characters 48 to 57, which are the numbers 0 to 9\. "192-255" are the printable latin characters.
Sometimes you will want to include a dash in keywords, so that commands like "w" consider "upper-case" to be one word. You can do it like this:
:set iskeyword+=-
:set iskeyword
iskeyword=@,48-57,\_,192-255,-
If you look at the new value, you will see that Vim has added a comma for you. To remove a character use "-=". For example, to remove the underscore:
:set iskeyword-=\_
:set iskeyword
iskeyword=@,48-57,192-255,-
This time a comma is automatically deleted.
ROOM FOR MESSAGES
When Vim starts there is one line at the bottom that is used for messages. When a message is long, it is either truncated, thus you can only see part of it, or the text scrolls and you have to press \<Enter\> to continue.
You can set the 'cmdheight' option to the number of lines used for messages. Example:
usr\_05.txt β 92
:set cmdheight=3
This does mean there is less room to edit text, thus it's a compromise. \============================================================================== Next chapter: usr\_06.txt Using syntax highlighting
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_05.txt β 93
usr\_06.txt For Vim version 8.0. Last change: 2009 Oct 28 VIM USER MANUAL \- by Bram Moolenaar
Using syntax highlighting
Black and white text is boring. With colors your file comes to life. This not only looks nice, it also speeds up your work. Change the colors used for the different sorts of text. Print your text, with the colors you see on the screen.
06.1 Switching it on
06.2 No or wrong colors?
06.3 Different colors
06.4 With colors or without colors
06.5 Printing with colors
06.6 Further reading
Next chapter: usr\_07.txt Editing more than one file
Previous chapter: usr\_05.txt Set your settings
Table of contents: usr\_toc.txt
\============================================================================== 06.1 Switching it on
It all starts with one simple command:
:syntax enable
That should work in most situations to get color in your files. Vim will automagically detect the type of file and load the right syntax highlighting. Suddenly comments are blue, keywords brown and strings red. This makes it easy to overview the file. After a while you will find that black\&white text slows you down\!
If you always want to use syntax highlighting, put the ":syntax enable" command in your vimrc file.
If you want syntax highlighting only when the terminal supports colors, you can put this in your vimrc file:
if \&t\_Co \> 1
syntax enable
endif
If you want syntax highlighting only in the GUI version, put the ":syntax enable" command in your gvimrc file.
\============================================================================== 06.2 No or wrong colors?
There can be a number of reasons why you don't see colors:
usr\_06.txt β 94
\- Your terminal does not support colors.
Vim will use bold, italic and underlined text, but this doesn't look very nice. You probably will want to try to get a terminal with colors. For Unix, I recommend the xterm from the XFree86 project: xfree-xterm .
\- Your terminal does support colors, but Vim doesn't know this. Make sure your \$TERM setting is correct. For example, when using an xterm that supports colors:
setenv TERM xterm-color
or (depending on your shell):
TERM=xterm-color; export TERM
The terminal name must match the terminal you are using. If it still doesn't work, have a look at xterm-color , which shows a few ways to make Vim display colors (not only for an xterm).
\- The file type is not recognized.
Vim doesn't know all file types, and sometimes it's near to impossible to tell what language a file uses. Try this command:
:set filetype
If the result is "filetype=" then the problem is indeed that Vim doesn't know what type of file this is. You can set the type manually:
:set filetype=fortran
To see which types are available, look in the directory
\$VIMRUNTIME/syntax. For the GUI you can use the Syntax menu. Setting the filetype can also be done with a modeline , so that the file will be highlighted each time you edit it. For example, this line can be used in a Makefile (put it near the start or end of the file):
\# vim: syntax=make
You might know how to detect the file type yourself. Often the file name extension (after the dot) can be used.
See new-filetype for how to tell Vim to detect that file type.
\- There is no highlighting for your file type.
You could try using a similar file type by manually setting it as mentioned above. If that isn't good enough, you can write your own syntax file, see mysyntaxfile .
Or the colors could be wrong:
\- The colored text is very hard to read.
usr\_06.txt β 95
Vim guesses the background color that you are using. If it is black (or another dark color) it will use light colors for text. If it is white (or another light color) it will use dark colors for text. If Vim guessed wrong the text will be hard to read. To solve this, set the 'background' option. For a dark background:
:set background=dark
And for a light background:
:set background=light
Make sure you put this \_before\_ the ":syntax enable" command, otherwise the colors will already have been set. You could do ":syntax reset" after setting 'background' to make Vim set the default colors again.
\- The colors are wrong when scrolling bottom to top.
Vim doesn't read the whole file to parse the text. It starts parsing wherever you are viewing the file. That saves a lot of time, but sometimes the colors are wrong. A simple fix is hitting CTRL-L. Or scroll back a bit and then forward again.
For a real fix, see :syn-sync . Some syntax files have a way to make it look further back, see the help for the specific syntax file. For example, tex.vim for the TeX syntax.
\============================================================================== 06.3 Different colors :syn-default-override
If you don't like the default colors, you can select another color scheme. In the GUI use the Edit/Color Scheme menu. You can also type the command:
:colorscheme evening
"evening" is the name of the color scheme. There are several others you might want to try out. Look in the directory \$VIMRUNTIME/colors.
When you found the color scheme that you like, add the ":colorscheme" command to your vimrc file.
You could also write your own color scheme. This is how you do it:
1\. Select a color scheme that comes close. Copy this file to your own Vim directory. For Unix, this should work:
\!mkdir \~/.vim/colors
\!cp \$VIMRUNTIME/colors/morning.vim \~/.vim/colors/mine.vim
This is done from Vim, because it knows the value of \$VIMRUNTIME. 2\. Edit the color scheme file. These entries are useful:
term attributes in a B\&W terminal
cterm attributes in a color terminal
usr\_06.txt β 96
ctermfg foreground color in a color terminal
ctermbg background color in a color terminal
gui attributes in the GUI
guifg foreground color in the GUI
guibg background color in the GUI
For example, to make comments green:
:highlight Comment ctermfg=green guifg=green
Attributes you can use for "cterm" and "gui" are "bold" and "underline". If you want both, use "bold,underline". For details see the :highlight command.
3\. Tell Vim to always use your color scheme. Put this line in your vimrc : colorscheme mine
If you want to see what the most often used color combinations look like, use this command:
:runtime syntax/colortest.vim
You will see text in various color combinations. You can check which ones are readable and look nice.
\============================================================================== 06.4 With colors or without colors
Displaying text in color takes a lot of effort. If you find the displaying too slow, you might want to disable syntax highlighting for a moment:
:syntax clear
When editing another file (or the same one) the colors will come back.
:syn-off
If you want to stop highlighting completely use:
:syntax off
This will completely disable syntax highlighting and remove it immediately for all buffers.
:syn-manual
If you want syntax highlighting only for specific files, use this: :syntax manual
This will enable the syntax highlighting, but not switch it on automatically when starting to edit a buffer. To switch highlighting on for the current buffer, set the 'syntax' option:
:set syntax=ON
usr\_06.txt β 97
\============================================================================== 06.5 Printing with colors syntax-printing
In the MS-Windows version you can print the current file with this command: :hardcopy
You will get the usual printer dialog, where you can select the printer and a few settings. If you have a color printer, the paper output should look the same as what you see inside Vim. But when you use a dark background the colors will be adjusted to look good on white paper.
There are several options that change the way Vim prints:
'printdevice'
'printheader'
'printfont'
'printoptions'
To print only a range of lines, use Visual mode to select the lines and then type the command:
v100j:hardcopy
"v" starts Visual mode. "100j" moves a hundred lines down, they will be highlighted. Then ":hardcopy" will print those lines. You can use other commands to move in Visual mode, of course.
This also works on Unix, if you have a PostScript printer. Otherwise, you will have to do a bit more work. You need to convert the text to HTML first, and then print it from a web browser.
Convert the current file to HTML with this command:
:TOhtml
In case that doesn't work:
:source \$VIMRUNTIME/syntax/2html.vim
You will see it crunching away, this can take quite a while for a large file. Some time later another window shows the HTML code. Now write this somewhere (doesn't matter where, you throw it away later):
:write main.c.html
Open this file in your favorite browser and print it from there. If all goes well, the output should look exactly as it does in Vim. See 2html.vim for details. Don't forget to delete the HTML file when you are done with it.
Instead of printing, you could also put the HTML file on a web server, and let others look at the colored text.
\============================================================================== usr\_06.txt β 98
06.6 Further reading
usr\_44.txt Your own syntax highlighted.
syntax All the details.
\============================================================================== Next chapter: usr\_07.txt Editing more than one file
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_06.txt β 99
usr\_07.txt For Vim version 8.0. Last change: 2017 Sep 18 VIM USER MANUAL \- by Bram Moolenaar
Editing more than one file
No matter how many files you have, you can edit them without leaving Vim. Define a list of files to work on and jump from one to the other. Copy text from one file and put it in another one.
07.1 Edit another file
07.2 A list of files
07.3 Jumping from file to file
07.4 Backup files
07.5 Copy text between files
07.6 Viewing a file
07.7 Changing the file name
Next chapter: usr\_08.txt Splitting windows
Previous chapter: usr\_06.txt Using syntax highlighting
Table of contents: usr\_toc.txt
\============================================================================== 07.1 Edit another file
So far you had to start Vim for every file you wanted to edit. There is a simpler way. To start editing another file, use this command:
:edit foo.txt
You can use any file name instead of "foo.txt". Vim will close the current file and open the new one. If the current file has unsaved changes, however, Vim displays an error message and does not open the new file:
E37: No write since last change (use \! to override)
Note:
Vim puts an error ID at the start of each error message. If you do not understand the message or what caused it, look in the help system for this ID. In this case:
:help E37
At this point, you have a number of alternatives. You can write the file using this command:
:write
Or you can force Vim to discard your changes and edit the new file, using the force (\!) character:
:edit\! foo.txt
usr\_07.txt β 100
If you want to edit another file, but not write the changes in the current file yet, you can make it hidden:
:hide edit foo.txt
The text with changes is still there, but you can't see it. This is further explained in section 22.4 : The buffer list.
\============================================================================== 07.2 A list of files
You can start Vim to edit a sequence of files. For example: vim one.c two.c three.c
This command starts Vim and tells it that you will be editing three files. Vim displays just the first file. After you have done your thing in this file, to edit the next file you use this command:
:next
If you have unsaved changes in the current file, you will get an error message and the ":next" will not work. This is the same problem as with ":edit" mentioned in the previous section. To abandon the changes:
:next\!
But mostly you want to save the changes and move on to the next file. There is a special command for this:
:wnext
This does the same as using two separate commands:
:write
:next
WHERE AM I?
To see which file in the argument list you are editing, look in the window title. It should show something like "(2 of 3)". This means you are editing the second file out of three files.
If you want to see the list of files, use this command:
:args
This is short for "arguments". The output might look like this: one.c \[two.c\] three.c
These are the files you started Vim with. The one you are currently editing, "two.c", is in square brackets.
usr\_07.txt β 101
MOVING TO OTHER ARGUMENTS
To go back one file:
:previous
This is just like the ":next" command, except that it moves in the other direction. Again, there is a shortcut command for when you want to write the file first:
:wprevious
To move to the very last file in the list:
:last
And to move back to the first one again:
:first
There is no ":wlast" or ":wfirst" command though\!
You can use a count for ":next" and ":previous". To skip two files forward: :2next
AUTOMATIC WRITING
When moving around the files and making changes, you have to remember to use ":write". Otherwise you will get an error message. If you are sure you always want to write modified files, you can tell Vim to automatically write them:
:set autowrite
When you are editing a file which you may not want to write, switch it off again:
:set noautowrite
EDITING ANOTHER LIST OF FILES
You can redefine the list of files without the need to exit Vim and start it again. Use this command to edit three other files:
:args five.c six.c seven.h
Or use a wildcard, like it's used in the shell:
:args \*.txt
usr\_07.txt β 102
Vim will take you to the first file in the list. Again, if the current file has changes, you can either write the file first, or use ":args\!" (with \! added) to abandon the changes.
DID YOU EDIT THE LAST FILE?
arglist-quit
When you use a list of files, Vim assumes you want to edit them all. To protect you from exiting too early, you will get this error when you didn't edit the last file in the list yet:
E173: 46 more files to edit
If you really want to exit, just do it again. Then it will work (but not when you did other commands in between).
\============================================================================== 07.3 Jumping from file to file
To quickly jump between two files, press CTRL-^ (on English-US keyboards the ^ is above the 6 key). Example:
:args one.c two.c three.c
You are now in one.c.
:next
Now you are in two.c. Now use CTRL-^ to go back to one.c. Another CTRL-^ and you are back in two.c. Another CTRL-^ and you are in one.c again. If you now do:
:next
You are in three.c. Notice that the CTRL-^ command does not change the idea of where you are in the list of files. Only commands like ":next" and ":previous" do that.
The file you were previously editing is called the "alternate" file. When you just started Vim CTRL-^ will not work, since there isn't a previous file.
PREDEFINED MARKS
After jumping to another file, you can use two predefined marks which are very useful:
\`"
This takes you to the position where the cursor was when you left the file. Another mark that is remembered is the position where you made the last change:
\`.
usr\_07.txt β 103
Suppose you are editing the file "one.txt". Somewhere halfway through the file you use "x" to delete a character. Then you go to the last line with "G" and write the file with ":w". You edit several other files, and then use ":edit one.txt" to come back to "one.txt". If you now use \`" Vim jumps to the last line of the file. Using \`. takes you to the position where you deleted the character. Even when you move around in the file \`" and \`. will take you to the remembered position. At least until you make another change or leave the file.
FILE MARKS
In chapter 4 was explained how you can place a mark in a file with "mx" and jump to that position with "\`x". That works within one file. If you edit another file and place marks there, these are specific for that file. Thus each file has its own set of marks, they are local to the file.
So far we were using marks with a lowercase letter. There are also marks with an uppercase letter. These are global, they can be used from any file. For example suppose that we are editing the file "foo.txt". Go to halfway down the file ("50%") and place the F mark there (F for foo):
50%mF
Now edit the file "bar.txt" and place the B mark (B for bar) at its last line: GmB
Now you can use the "'F" command to jump back to halfway foo.txt. Or edit yet another file, type "'B" and you are at the end of bar.txt again.
The file marks are remembered until they are placed somewhere else. Thus you can place the mark, do hours of editing and still be able to jump back to that mark.
It's often useful to think of a simple connection between the mark letter and where it is placed. For example, use the H mark in a header file, M in a Makefile and C in a C code file.
To see where a specific mark is, give an argument to the ":marks" command: :marks M
You can also give several arguments:
:marks MCP
Don't forget that you can use CTRL-O and CTRL-I to jump to older and newer positions without placing marks there.
\============================================================================== 07.4 Backup files
Usually Vim does not produce a backup file. If you want to have one, all you need to do is execute the following command:
usr\_07.txt β 104
:set backup
The name of the backup file is the original file with a \~ added to the end. If your file is named data.txt, for example, the backup file name is data.txt\~.
If you do not like the fact that the backup files end with \~, you can change the extension:
:set backupext=.bak
This will use data.txt.bak instead of data.txt\~.
Another option that matters here is 'backupdir'. It specifies where the backup file is written. The default, to write the backup in the same directory as the original file, will mostly be the right thing.
Note:
When the 'backup' option isn't set but the 'writebackup' is, Vim will still create a backup file. However, it is deleted as soon as writing the file was completed successfully. This functions as a safety against losing your original file when writing fails in some way (disk full is the most common cause; being hit by lightning might be another, although less common).
KEEPING THE ORIGINAL FILE
If you are editing source files, you might want to keep the file before you make any changes. But the backup file will be overwritten each time you write the file. Thus it only contains the previous version, not the first one.
To make Vim keep the original file, set the 'patchmode' option. This specifies the extension used for the first backup of a changed file. Usually you would do this:
:set patchmode=.orig
When you now edit the file data.txt for the first time, make changes and write the file, Vim will keep a copy of the unchanged file under the name "data.txt.orig".
If you make further changes to the file, Vim will notice that "data.txt.orig" already exists and leave it alone. Further backup files will then be called "data.txt\~" (or whatever you specified with 'backupext').
If you leave 'patchmode' empty (that is the default), the original file will not be kept.
\============================================================================== 07.5 Copy text between files
This explains how to copy text from one file to another. Let's start with a simple example. Edit the file that contains the text you want to copy. Move the cursor to the start of the text and press "v". This starts Visual mode. Now move the cursor to the end of the text and press "y". This yanks (copies) the selected text.
To copy the above paragraph, you would do:
usr\_07.txt β 105
:edit thisfile
/This
vjjjj\$y
Now edit the file you want to put the text in. Move the cursor to the character where you want the text to appear after. Use "p" to put the text there.
:edit otherfile
/There
p
Of course you can use many other commands to yank the text. For example, to select whole lines start Visual mode with "V". Or use CTRL-V to select a rectangular block. Or use "Y" to yank a single line, "yaw" to yank-a-word, etc.
The "p" command puts the text after the cursor. Use "P" to put the text before the cursor. Notice that Vim remembers if you yanked a whole line or a block, and puts it back that way.
USING REGISTERS
When you want to copy several pieces of text from one file to another, having to switch between the files and writing the target file takes a lot of time. To avoid this, copy each piece of text to its own register.
A register is a place where Vim stores text. Here we will use the registers named a to z (later you will find out there are others). Let's copy a sentence to the f register (f for First):
"fyas
The "yas" command yanks a sentence like before. It's the "f that tells Vim the text should be placed in the f register. This must come just before the yank command.
Now yank three whole lines to the l register (l for line):
"l3Y
The count could be before the "l just as well. To yank a block of text to the b (for block) register:
CTRL-Vjjww"by
Notice that the register specification "b is just before the "y" command. This is required. If you would have put it before the "w" command, it would not have worked.
Now you have three pieces of text in the f, l and b registers. Edit another file, move around and place the text where you want it:
"fp
Again, the register specification "f comes before the "p" command. You can put the registers in any order. And the text stays in the register
usr\_07.txt β 106
until you yank something else into it. Thus you can put it as many times as you like.
When you delete text, you can also specify a register. Use this to move several pieces of text around. For example, to delete-a-word and write it in the w register:
"wdaw
Again, the register specification comes before the delete command "d".
APPENDING TO A FILE
When collecting lines of text into one file, you can use this command: :write \>\> logfile
This will write the text of the current file to the end of "logfile". Thus it is appended. This avoids that you have to copy the lines, edit the log file and put them there. Thus you save two steps. But you can only append to the end of a file.
To append only a few lines, select them in Visual mode before typing ":write". In chapter 10 you will learn other ways to select a range of lines.
\============================================================================== 07.6 Viewing a file
Sometimes you only want to see what a file contains, without the intention to ever write it back. There is the risk that you type ":w" without thinking and overwrite the original file anyway. To avoid this, edit the file read-only. To start Vim in readonly mode, use this command:
vim \-R file
On Unix this command should do the same thing:
view file
You are now editing "file" in read-only mode. When you try using ":w" you will get an error message and the file won't be written.
When you try to make a change to the file Vim will give you a warning: W10: Warning: Changing a readonly file
The change will be done though. This allows for formatting the file, for example, to be able to read it easily.
If you make changes to a file and forgot that it was read-only, you can still write it. Add the \! to the write command to force writing.
If you really want to forbid making changes in a file, do this: vim \-M file
usr\_07.txt β 107
Now every attempt to change the text will fail. The help files are like this, for example. If you try to make a change you get this error message:
E21: Cannot make changes, 'modifiable' is off
You could use the \-M argument to setup Vim to work in a viewer mode. This is only voluntary though, since these commands will remove the protection:
:set modifiable
:set write
\============================================================================== 07.7 Changing the file name
A clever way to start editing a new file is by using an existing file that contains most of what you need. For example, you start writing a new program to move a file. You know that you already have a program that copies a file, thus you start with:
:edit copy.c
You can delete the stuff you don't need. Now you need to save the file under a new name. The ":saveas" command can be used for this:
:saveas move.c
Vim will write the file under the given name, and edit that file. Thus the next time you do ":write", it will write "move.c". "copy.c" remains unmodified.
When you want to change the name of the file you are editing, but don't want to write the file, you can use this command:
:file move.c
Vim will mark the file as "not edited". This means that Vim knows this is not the file you started editing. When you try to write the file, you might get this message:
E13: File exists (use \! to override)
This protects you from accidentally overwriting another file. \============================================================================== Next chapter: usr\_08.txt Splitting windows
Copyright: see manual-copyright vim:tw=78:ts=8:ft=help:norl: usr\_07.txt β 108
usr\_08.txt For Vim version 8.0. Last change: 2017 Aug 11 VIM USER MANUAL \- by Bram Moolenaar
Splitting windows
Display two different files above each other. Or view two locations in the file at the same time. See the difference between two files by putting them side by side. All this is possible with split windows.
08.1 Split a window
08.2 Split a window on another file
08.3 Window size
08.4 Vertical splits
08.5 Moving windows
08.6 Commands for all windows
08.7 Viewing differences with vimdiff
08.8 Various
08.9 Tab pages
Next chapter: usr\_09.txt Using the GUI
Previous chapter: usr\_07.txt Editing more than one file
Table of contents: usr\_toc.txt
\============================================================================== 08.1 Split a window
The easiest way to open a new window is to use the following command: :split
This command splits the screen into two windows and leaves the cursor in the top one:
\+----------------------------------+
\|/\* file one.c \*/ \|
\|\~ \|
\|\~ \|
one.c=============================
\|/\* file one.c \*/ \|
\|\~ \|
one.c=============================
\| \|
\+----------------------------------+
What you see here is two windows on the same file. The line with "====" is the status line. It displays information about the window above it. (In practice the status line will be in reverse video.)
The two windows allow you to view two parts of the same file. For example, you could make the top window show the variable declarations of a program, and the bottom one the code that uses these variables.
The CTRL-W w command can be used to jump between the windows. If you are in usr\_08.txt β 109
the top window, CTRL-W w jumps to the window below it. If you are in the bottom window it will jump to the first window. (CTRL-W CTRL-W does the same thing, in case you let go of the CTRL key a bit later.)
CLOSE THE WINDOW
To close a window, use the command:
:close
Actually, any command that quits editing a file works, like ":quit" and "ZZ". But ":close" prevents you from accidentally exiting Vim when you close the last window.
CLOSING ALL OTHER WINDOWS
If you have opened a whole bunch of windows, but now want to concentrate on one of them, this command will be useful:
:only
This closes all windows, except for the current one. If any of the other windows has changes, you will get an error message and that window won't be closed.
\============================================================================== 08.2 Split a window on another file
The following command opens a second window and starts editing the given file: :split two.c
If you were editing one.c, then the result looks like this:
\+----------------------------------+
\|/\* file two.c \*/ \|
\|\~ \|
\|\~ \|
two.c=============================
\|/\* file one.c \*/ \|
\|\~ \|
one.c=============================
\| \|
\+----------------------------------+
To open a window on a new, empty file, use this:
:new
You can repeat the ":split" and ":new" commands to create as many windows as you like.
usr\_08.txt β 110
\============================================================================== 08.3 Window size
The ":split" command can take a number argument. If specified, this will be the height of the new window. For example, the following opens a new window three lines high and starts editing the file alpha.c:
:3split alpha.c
For existing windows you can change the size in several ways. When you have a working mouse, it is easy: Move the mouse pointer to the status line that separates two windows, and drag it up or down.
To increase the size of a window:
CTRL-W \+
To decrease it:
CTRL-W \-
Both of these commands take a count and increase or decrease the window size by that many lines. Thus "4 CTRL-W \+" make the window four lines higher.
To set the window height to a specified number of lines:
{height}CTRL-W \_
That's: a number {height}, CTRL-W and then an underscore (the \- key with Shift on English-US keyboards).
To make a window as high as it can be, use the CTRL-W \_ command without a count.
USING THE MOUSE
In Vim you can do many things very quickly from the keyboard. Unfortunately, the window resizing commands require quite a bit of typing. In this case, using the mouse is faster. Position the mouse pointer on a status line. Now press the left mouse button and drag. The status line will move, thus making the window on one side higher and the other smaller.
OPTIONS
The 'winheight' option can be set to a minimal desired height of a window and 'winminheight' to a hard minimum height.
Likewise, there is 'winwidth' for the minimal desired width and 'winminwidth' for the hard minimum width.
The 'equalalways' option, when set, makes Vim equalize the windows sizes when a window is closed or opened.
\============================================================================== 08.4 Vertical splits
usr\_08.txt β 111
The ":split" command creates the new window above the current one. To make the window appear at the left side, use:
:vsplit
or:
:vsplit two.c
The result looks something like this:
\+--------------------------------------+
\|/\* file two.c \*/ \|/\* file one.c \*/ \|
\|\~ \|\~ \|
\|\~ \|\~ \|
\|\~ \|\~ \|
two.c===============one.c=============
\| \|
\+--------------------------------------+
Actually, the \| lines in the middle will be in reverse video. This is called the vertical separator. It separates the two windows left and right of it.
There is also the ":vnew" command, to open a vertically split window on a new, empty file. Another way to do this:
:vertical new
The ":vertical" command can be inserted before another command that splits a window. This will cause that command to split the window vertically instead of horizontally. (If the command doesn't split a window, it works unmodified.)
MOVING BETWEEN WINDOWS
Since you can split windows horizontally and vertically as much as you like, you can create almost any layout of windows. Then you can use these commands to move between them:
CTRL-W h move to the window on the left
CTRL-W j move to the window below
CTRL-W k move to the window above
CTRL-W l move to the window on the right
CTRL-W t move to the TOP window
CTRL-W b move to the BOTTOM window
You will notice the same letters as used for moving the cursor. And the cursor keys can also be used, if you like.
More commands to move to other windows: Q\_wi .
\============================================================================== 08.5 Moving windows
usr\_08.txt β 112 |