/usr/share/doc/vim/html/map.html is in vim-doc 2:8.0.1453-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <HTML>
<HEAD>
<META HTTP-EQUIV="Content-type" content="text/html; charset=ISO-8859-1">
<TITLE>Vim documentation: map</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>Vim documentation: map</H1>
<A NAME="top"></A>
<A HREF="index.html">main help file</A>
<HR>
<PRE>
*<A NAME="map.txt"></A><B>map.txt</B>* For Vim version 8.0. Last change: 2017 Sep 23
VIM REFERENCE MANUAL by <A HREF="intro.html#Bram">Bram</A> <A HREF="intro.html#Moolenaar">Moolenaar</A>
Key <A HREF="#mapping">mapping</A>, <A HREF="#abbreviations">abbreviations</A> and user-defined commands.
This subject is introduced in sections |<A HREF="usr_05.html#05.3">05.3</A>|, |<A HREF="usr_24.html#24.7">24.7</A>| and |<A HREF="usr_40.html#40.1">40.1</A>| of the user
manual.
1. Key mapping |<A HREF="#key-mapping">key-mapping</A>|
1.1 MAP COMMANDS |<A HREF="#:map-commands">:map-commands</A>|
1.2 <A HREF="eval.html#Special">Special</A> arguments |<A HREF="#:map-arguments">:map-arguments</A>|
1.3 Mapping and modes |<A HREF="#:map-modes">:map-modes</A>|
1.4 Listing mappings |<A HREF="#map-listing">map-listing</A>|
1.5 Mapping special keys |<A HREF="#:map-special-keys">:map-special-keys</A>|
1.6 <A HREF="eval.html#Special">Special</A> characters |<A HREF="#:map-special-chars">:map-special-chars</A>|
1.7 What keys to map |<A HREF="#map-which-keys">map-which-keys</A>|
1.8 Examples |<A HREF="#map-examples">map-examples</A>|
1.9 Using mappings |<A HREF="#map-typing">map-typing</A>|
1.10 Mapping alt-keys |<A HREF="#:map-alt-keys">:map-alt-keys</A>|
1.11 Mapping an operator |<A HREF="#:map-operator">:map-operator</A>|
2. <A HREF="#Abbreviations">Abbreviations</A> |<A HREF="#abbreviations">abbreviations</A>|
3. Local mappings and <A HREF="eval.html#functions">functions</A> |<A HREF="#script-local">script-local</A>|
4. User-defined commands |<A HREF="#user-commands">user-commands</A>|
==============================================================================
1. Key <A HREF="#mapping">mapping</A> *<A NAME="key-mapping"></A><B>key-mapping</B>* *<A NAME="mapping"></A><B>mapping</B>* *<A NAME="macro"></A><B>macro</B>*
Key <A HREF="#mapping">mapping</A> is used to change the meaning of typed keys. The most common use
is to define a sequence of commands for a function key. Example:
<B> :map <F2> a<C-R>=strftime("%c")<CR><Esc></B>
This appends the current date and time after the cursor (in <> <A HREF="intro.html#notation">notation</A> |<A HREF="intro.html#<>"><></A>|).
1.1 MAP COMMANDS *<A NAME=":map-commands"></A><B>:map-commands</B>*
There are commands to enter new mappings, remove mappings and <A HREF="eval.html#list">list</A> mappings.
See |<A HREF="#map-overview">map-overview</A>| for the various forms of "map" and their relationships with
modes.
<A HREF="#{lhs}">{lhs}</A> means left-hand-side *<A NAME="{lhs}"></A><B>{lhs}</B>*
<A HREF="#{rhs}">{rhs}</A> means right-hand-side *<A NAME="{rhs}"></A><B>{rhs}</B>*
<A HREF="#:map">:map</A> <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-nvo">mapmode-nvo</A>| *<A NAME=":map"></A><B>:map</B>*
:nm[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-n">mapmode-n</A>| *<A NAME=":nm"></A><B>:nm</B>* *<A NAME=":nmap"></A><B>:nmap</B>*
:vm[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-v">mapmode-v</A>| *<A NAME=":vm"></A><B>:vm</B>* *<A NAME=":vmap"></A><B>:vmap</B>*
:xm[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-x">mapmode-x</A>| *<A NAME=":xm"></A><B>:xm</B>* *<A NAME=":xmap"></A><B>:xmap</B>*
<A HREF="#:smap">:smap</A> <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-s">mapmode-s</A>| *<A NAME=":smap"></A><B>:smap</B>*
:om[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-o">mapmode-o</A>| *<A NAME=":om"></A><B>:om</B>* *<A NAME=":omap"></A><B>:omap</B>*
<A HREF="#:map!">:map!</A> <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-ic">mapmode-ic</A>| *<A NAME=":map!"></A><B>:map!</B>*
:im[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-i">mapmode-i</A>| *<A NAME=":im"></A><B>:im</B>* *<A NAME=":imap"></A><B>:imap</B>*
:lm[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-l">mapmode-l</A>| *<A NAME=":lm"></A><B>:lm</B>* *<A NAME=":lmap"></A><B>:lmap</B>*
:cm[ap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-c">mapmode-c</A>| *<A NAME=":cm"></A><B>:cm</B>* *<A NAME=":cmap"></A><B>:cmap</B>*
:tma[p] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-t">mapmode-t</A>| *<A NAME=":tma"></A><B>:tma</B>* *<A NAME=":tmap"></A><B>:tmap</B>*
Map the key sequence <A HREF="#{lhs}">{lhs}</A> to <A HREF="#{rhs}">{rhs}</A> for the modes
where the map command applies. The result, including
<A HREF="#{rhs}">{rhs}</A>, is then further scanned for mappings. This
allows for nested and recursive use of mappings.
*<A NAME=":nore"></A><B>:nore</B>* *<A NAME=":norem"></A><B>:norem</B>*
:no[remap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-nvo">mapmode-nvo</A>| *<A NAME=":no"></A><B>:no</B>* *<A NAME=":noremap"></A><B>:noremap</B>* *<A NAME=":nor"></A><B>:nor</B>*
:nn[oremap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-n">mapmode-n</A>| *<A NAME=":nn"></A><B>:nn</B>* *<A NAME=":nnoremap"></A><B>:nnoremap</B>*
:vn[oremap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-v">mapmode-v</A>| *<A NAME=":vn"></A><B>:vn</B>* *<A NAME=":vnoremap"></A><B>:vnoremap</B>*
:xn[oremap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-x">mapmode-x</A>| *<A NAME=":xn"></A><B>:xn</B>* *<A NAME=":xnoremap"></A><B>:xnoremap</B>*
:snor[emap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-s">mapmode-s</A>| *<A NAME=":snor"></A><B>:snor</B>* *<A NAME=":snoremap"></A><B>:snoremap</B>*
:ono[remap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-o">mapmode-o</A>| *<A NAME=":ono"></A><B>:ono</B>* *<A NAME=":onoremap"></A><B>:onoremap</B>*
:no[remap]! <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-ic">mapmode-ic</A>| *<A NAME=":no!"></A><B>:no!</B>* *<A NAME=":noremap!"></A><B>:noremap!</B>*
:ino[remap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-i">mapmode-i</A>| *<A NAME=":ino"></A><B>:ino</B>* *<A NAME=":inoremap"></A><B>:inoremap</B>*
:ln[oremap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-l">mapmode-l</A>| *<A NAME=":ln"></A><B>:ln</B>* *<A NAME=":lnoremap"></A><B>:lnoremap</B>*
:cno[remap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-c">mapmode-c</A>| *<A NAME=":cno"></A><B>:cno</B>* *<A NAME=":cnoremap"></A><B>:cnoremap</B>*
:tno[remap] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A> |<A HREF="#mapmode-t">mapmode-t</A>| *<A NAME=":tno"></A><B>:tno</B>* *<A NAME=":tnoremap"></A><B>:tnoremap</B>*
Map the key sequence <A HREF="#{lhs}">{lhs}</A> to <A HREF="#{rhs}">{rhs}</A> for the modes
where the map command applies. Disallow <A HREF="#mapping">mapping</A> of
<A HREF="#{rhs}">{rhs}</A>, to avoid nested and recursive mappings. Often
used to redefine a command. {not in Vi}
:unm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-nvo">mapmode-nvo</A>| *<A NAME=":unm"></A><B>:unm</B>* *<A NAME=":unmap"></A><B>:unmap</B>*
:nun[map] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-n">mapmode-n</A>| *<A NAME=":nun"></A><B>:nun</B>* *<A NAME=":nunmap"></A><B>:nunmap</B>*
:vu[nmap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-v">mapmode-v</A>| *<A NAME=":vu"></A><B>:vu</B>* *<A NAME=":vunmap"></A><B>:vunmap</B>*
:xu[nmap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-x">mapmode-x</A>| *<A NAME=":xu"></A><B>:xu</B>* *<A NAME=":xunmap"></A><B>:xunmap</B>*
:sunm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-s">mapmode-s</A>| *<A NAME=":sunm"></A><B>:sunm</B>* *<A NAME=":sunmap"></A><B>:sunmap</B>*
:ou[nmap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-o">mapmode-o</A>| *<A NAME=":ou"></A><B>:ou</B>* *<A NAME=":ounmap"></A><B>:ounmap</B>*
:unm[ap]! <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-ic">mapmode-ic</A>| *<A NAME=":unm!"></A><B>:unm!</B>* *<A NAME=":unmap!"></A><B>:unmap!</B>*
:iu[nmap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-i">mapmode-i</A>| *<A NAME=":iu"></A><B>:iu</B>* *<A NAME=":iunmap"></A><B>:iunmap</B>*
:lu[nmap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-l">mapmode-l</A>| *<A NAME=":lu"></A><B>:lu</B>* *<A NAME=":lunmap"></A><B>:lunmap</B>*
:cu[nmap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-c">mapmode-c</A>| *<A NAME=":cu"></A><B>:cu</B>* *<A NAME=":cunmap"></A><B>:cunmap</B>*
:tunma[p] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-t">mapmode-t</A>| *<A NAME=":tunma"></A><B>:tunma</B>* *<A NAME=":tunmap"></A><B>:tunmap</B>*
Remove the <A HREF="#mapping">mapping</A> of <A HREF="#{lhs}">{lhs}</A> for the modes where the
map command applies. The <A HREF="#mapping">mapping</A> may remain defined
for other modes where <A HREF="motion.html#it">it</A> applies.
Note: Trailing spaces are included in the <A HREF="#{lhs}">{lhs}</A>. This
unmap does NOT work:
<B> :map @@ foo</B>
<B> :unmap @@ | print</B>
:mapc[lear] |<A HREF="#mapmode-nvo">mapmode-nvo</A>| *<A NAME=":mapc"></A><B>:mapc</B>* *<A NAME=":mapclear"></A><B>:mapclear</B>*
:nmapc[lear] |<A HREF="#mapmode-n">mapmode-n</A>| *<A NAME=":nmapc"></A><B>:nmapc</B>* *<A NAME=":nmapclear"></A><B>:nmapclear</B>*
:vmapc[lear] |<A HREF="#mapmode-v">mapmode-v</A>| *<A NAME=":vmapc"></A><B>:vmapc</B>* *<A NAME=":vmapclear"></A><B>:vmapclear</B>*
:xmapc[lear] |<A HREF="#mapmode-x">mapmode-x</A>| *<A NAME=":xmapc"></A><B>:xmapc</B>* *<A NAME=":xmapclear"></A><B>:xmapclear</B>*
:smapc[lear] |<A HREF="#mapmode-s">mapmode-s</A>| *<A NAME=":smapc"></A><B>:smapc</B>* *<A NAME=":smapclear"></A><B>:smapclear</B>*
:omapc[lear] |<A HREF="#mapmode-o">mapmode-o</A>| *<A NAME=":omapc"></A><B>:omapc</B>* *<A NAME=":omapclear"></A><B>:omapclear</B>*
:mapc[lear]! |<A HREF="#mapmode-ic">mapmode-ic</A>| *<A NAME=":mapc!"></A><B>:mapc!</B>* *<A NAME=":mapclear!"></A><B>:mapclear!</B>*
:imapc[lear] |<A HREF="#mapmode-i">mapmode-i</A>| *<A NAME=":imapc"></A><B>:imapc</B>* *<A NAME=":imapclear"></A><B>:imapclear</B>*
:lmapc[lear] |<A HREF="#mapmode-l">mapmode-l</A>| *<A NAME=":lmapc"></A><B>:lmapc</B>* *<A NAME=":lmapclear"></A><B>:lmapclear</B>*
:cmapc[lear] |<A HREF="#mapmode-c">mapmode-c</A>| *<A NAME=":cmapc"></A><B>:cmapc</B>* *<A NAME=":cmapclear"></A><B>:cmapclear</B>*
:tmapc[lear] |<A HREF="#mapmode-t">mapmode-t</A>| *<A NAME=":tmapc"></A><B>:tmapc</B>* *<A NAME=":tmapclear"></A><B>:tmapclear</B>*
Remove ALL mappings for the modes where the map
command applies. {not in Vi}
Use the <buffer> argument to remove buffer-local
mappings |<A HREF="#:map-<buffer>">:map-<buffer></A>|
Warning: This also removes the default mappings.
<A HREF="#:map">:map</A> |<A HREF="#mapmode-nvo">mapmode-nvo</A>|
:nm[ap] |<A HREF="#mapmode-n">mapmode-n</A>|
:vm[ap] |<A HREF="#mapmode-v">mapmode-v</A>|
:xm[ap] |<A HREF="#mapmode-x">mapmode-x</A>|
:sm[ap] |<A HREF="#mapmode-s">mapmode-s</A>|
:om[ap] |<A HREF="#mapmode-o">mapmode-o</A>|
<A HREF="#:map!">:map!</A> |<A HREF="#mapmode-ic">mapmode-ic</A>|
:im[ap] |<A HREF="#mapmode-i">mapmode-i</A>|
:lm[ap] |<A HREF="#mapmode-l">mapmode-l</A>|
:cm[ap] |<A HREF="#mapmode-c">mapmode-c</A>|
:tma[p] |<A HREF="#mapmode-t">mapmode-t</A>|
<A HREF="eval.html#List">List</A> all key mappings for the modes where the map
command applies. Note that "<A HREF="#:map">:map</A>" and "<A HREF="#:map!">:map!</A>" are
used most often, because they include the other modes.
<A HREF="#:map">:map</A> <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-nvo">mapmode-nvo</A>| *<A NAME=":map_l"></A><B>:map_l</B>*
:nm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-n">mapmode-n</A>| *<A NAME=":nmap_l"></A><B>:nmap_l</B>*
:vm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-v">mapmode-v</A>| *<A NAME=":vmap_l"></A><B>:vmap_l</B>*
:xm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-x">mapmode-x</A>| *<A NAME=":xmap_l"></A><B>:xmap_l</B>*
:sm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-s">mapmode-s</A>| *<A NAME=":smap_l"></A><B>:smap_l</B>*
:om[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-o">mapmode-o</A>| *<A NAME=":omap_l"></A><B>:omap_l</B>*
<A HREF="#:map!">:map!</A> <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-ic">mapmode-ic</A>| *<A NAME=":map_l!"></A><B>:map_l!</B>*
:im[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-i">mapmode-i</A>| *<A NAME=":imap_l"></A><B>:imap_l</B>*
:lm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-l">mapmode-l</A>| *<A NAME=":lmap_l"></A><B>:lmap_l</B>*
:cm[ap] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-c">mapmode-c</A>| *<A NAME=":cmap_l"></A><B>:cmap_l</B>*
:tma[p] <A HREF="#{lhs}">{lhs}</A> |<A HREF="#mapmode-t">mapmode-t</A>| *<A NAME=":tmap_l"></A><B>:tmap_l</B>*
<A HREF="eval.html#List">List</A> the key mappings for the key sequences starting
with <A HREF="#{lhs}">{lhs}</A> in the modes where the map command applies.
{not in Vi}
These commands are used to map a key or key sequence to a <A HREF="eval.html#string">string</A> of
characters. You can use this to put command sequences under function keys,
translate one key into another, etc. See |<A HREF="starting.html#:mkexrc">:mkexrc</A>| for how to save and
restore the current mappings.
*<A NAME="map-ambiguous"></A><B>map-ambiguous</B>*
When two mappings start with the same sequence of characters, they are
ambiguous. Example:
<B> :imap aa foo</B>
<B> :imap aaa bar</B>
When Vim has read "aa", <A HREF="motion.html#it">it</A> will need to get another character to be able to
decide if "aa" or "aaa" should be mapped. This means that after typing "aa"
that <A HREF="#mapping">mapping</A> won't get expanded yet, Vim is waiting for another character.
If you type a space, then "foo" will get inserted, plus the space. If you
type "<A HREF="insert.html#a">a</A>", then "<A HREF="motion.html#bar">bar</A>" will get inserted.
{Vi does not allow ambiguous mappings}
1.2 SPECIAL ARGUMENTS *<A NAME=":map-arguments"></A><B>:map-arguments</B>*
"<buffer>", "<nowait>", "<silent>", "<special>", "<script>", "<expr>" and
"<unique>" can be used in any order. They must appear right after the
command, before any other arguments.
*<A NAME=":map-local"></A><B>:map-local</B>* *<A NAME=":map-<buffer>"></A><B>:map-<buffer></B>* *<A NAME="E224"></A><B>E224</B>* *<A NAME="E225"></A><B>E225</B>*
If the first argument to one of these commands is "<buffer>" the <A HREF="#mapping">mapping</A> will
be effective in the current buffer only. Example:
<B> :map <buffer> ,w /[.,;]<CR></B>
Then you can map ",w" to something else in another buffer:
<B> :map <buffer> ,w /[#&!]<CR></B>
The local buffer mappings are used before the global ones. See <nowait> below
to make a short local <A HREF="#mapping">mapping</A> not taking effect when a longer global one
exists.
The "<buffer>" argument can also be used to clear mappings:
<B> :unmap <buffer> ,w</B>
<B> :mapclear <buffer></B>
Local mappings are also cleared when a buffer is deleted, but not when <A HREF="motion.html#it">it</A> is
unloaded. Just like local option values.
Also see |<A HREF="#map-precedence">map-precedence</A>|.
*<A NAME=":map-<nowait>"></A><B>:map-<nowait></B>* *<A NAME=":map-nowait"></A><B>:map-nowait</B>*
When defining a buffer-local <A HREF="#mapping">mapping</A> for "<A HREF="motion.html#,">,</A>" there may be a global <A HREF="#mapping">mapping</A>
that starts with "<A HREF="motion.html#,">,</A>". Then you need to type another character for Vim to know
whether to use the "<A HREF="motion.html#,">,</A>" <A HREF="#mapping">mapping</A> or the longer one. To avoid this add the
<nowait> argument. Then the <A HREF="#mapping">mapping</A> will be used when <A HREF="motion.html#it">it</A> matches, Vim does
not wait for more characters to be typed. However, if the characters were
already typed they are used.
*<A NAME=":map-<silent>"></A><B>:map-<silent></B>* *<A NAME=":map-silent"></A><B>:map-silent</B>*
To define a <A HREF="#mapping">mapping</A> which will not be echoed on the command line, add
"<silent>" <A HREF="motion.html#as">as</A> the first argument. Example:
<B> :map <silent> ,h /Header<CR></B>
The search <A HREF="eval.html#string">string</A> will not be echoed when using this <A HREF="#mapping">mapping</A>. Messages from
the executed command are still given though. To shut them up too, add a
"<A HREF="various.html#:silent">:silent</A>" in the executed command:
<B> :map <silent> ,h :exe ":silent normal /Header\r"<CR></B>
Prompts will still be given, e.g., for <A HREF="eval.html#inputdialog()">inputdialog()</A>.
Using "<silent>" for an abbreviation is possible, but will cause redrawing of
the command line to fail.
*<A NAME=":map-<special>"></A><B>:map-<special></B>* *<A NAME=":map-special"></A><B>:map-special</B>*
Define a <A HREF="#mapping">mapping</A> with <A HREF="intro.html#<>"><></A> <A HREF="intro.html#notation">notation</A> for special keys, even though the "<A HREF="change.html#<"><</A>" flag
may appear in <A HREF="options.html#'cpoptions'">'cpoptions'</A>. This is useful if the side effect of setting
<A HREF="options.html#'cpoptions'">'cpoptions'</A> is not desired. Example:
<B> :map <special> <F12> /Header<CR></B>
*<A NAME=":map-<script>"></A><B>:map-<script></B>* *<A NAME=":map-script"></A><B>:map-script</B>*
If the first argument to one of these commands is "<script>" and <A HREF="motion.html#it">it</A> is used to
define a new <A HREF="#mapping">mapping</A> or abbreviation, the <A HREF="#mapping">mapping</A> will only remap characters
in the <A HREF="#{rhs}">{rhs}</A> using mappings that were defined local to a <A HREF="usr_41.html#script">script</A>, starting with
"<A HREF="#<SID>"><SID></A>". This can be used to avoid that mappings from outside a <A HREF="usr_41.html#script">script</A>
interfere (e.g., when <A HREF="visual.html#CTRL-V">CTRL-V</A> is remapped in mswin.vim), but <A HREF="diff.html#do">do</A> use other
mappings defined in the <A HREF="usr_41.html#script">script</A>.
Note: "<A HREF="#:map">:map</A> <script>" and "<A HREF="#:noremap">:noremap</A> <script>" <A HREF="diff.html#do">do</A> the same thing. The
"<script>" overrules the command name. Using "<A HREF="#:noremap">:noremap</A> <script>" is
preferred, because it's clearer that remapping is (mostly) disabled.
*<A NAME=":map-<unique>"></A><B>:map-<unique></B>* *<A NAME="E226"></A><B>E226</B>* *<A NAME="E227"></A><B>E227</B>*
If the first argument to one of these commands is "<unique>" and <A HREF="motion.html#it">it</A> is used to
define a new <A HREF="#mapping">mapping</A> or abbreviation, the command will fail if the <A HREF="#mapping">mapping</A> or
abbreviation already exists. Example:
<B> :map <unique> ,w /[#&!]<CR></B>
When defining a local <A HREF="#mapping">mapping</A>, there will also be a check if a global map
already exists which is equal.
Example of what will fail:
<B> :map ,w /[#&!]<CR></B>
<B> :map <buffer> <unique> ,w /[.,;]<CR></B>
If you want to map a key and then have <A HREF="motion.html#it">it</A> <A HREF="diff.html#do">do</A> what <A HREF="motion.html#it">it</A> was originally mapped to,
have a look at |<A HREF="eval.html#maparg()">maparg()</A>|.
*<A NAME=":map-<expr>"></A><B>:map-<expr></B>* *<A NAME=":map-expression"></A><B>:map-expression</B>*
If the first argument to one of these commands is "<expr>" and <A HREF="motion.html#it">it</A> is used to
define a new <A HREF="#mapping">mapping</A> or abbreviation, the argument is an <A HREF="eval.html#expression">expression</A>. The
<A HREF="eval.html#expression">expression</A> is evaluated to obtain the <A HREF="#{rhs}">{rhs}</A> that is used. Example:
<B> :inoremap <expr> . InsertDot()</B>
The result of the InsertDot() function will be inserted. It could check the
text before the cursor and start omni completion when some condition is met.
For <A HREF="#abbreviations">abbreviations</A> |<A HREF="eval.html#v:char">v:char</A>| is set to the character that was typed to trigger
the abbreviation. You can use this to decide how to expand the <A HREF="#{lhs}">{lhs}</A>. You
should not either insert or change the <A HREF="eval.html#v:char">v:char</A>.
Be very careful about side effects! The <A HREF="eval.html#expression">expression</A> is evaluated while
obtaining characters, you may very well make the command dysfunctional.
For this reason the following is blocked:
- Changing the buffer text |<A HREF="eval.html#textlock">textlock</A>|.
- Editing another buffer.
- The |<A HREF="various.html#:normal">:normal</A>| command.
- Moving the cursor is allowed, but <A HREF="motion.html#it">it</A> is restored afterwards.
If you want the <A HREF="#mapping">mapping</A> to <A HREF="diff.html#do">do</A> any of these let the returned characters <A HREF="diff.html#do">do</A>
that.
You can use <A HREF="eval.html#getchar()">getchar()</A>, <A HREF="motion.html#it">it</A> consumes typeahead if there is any. E.g., if you
have these mappings:
<B> inoremap <expr> <C-L> nr2char(getchar())</B>
<B> inoremap <expr> <C-L>x "foo"</B>
If you now type <A HREF="various.html#CTRL-L">CTRL-L</A> nothing happens yet, Vim needs the next character to
decide what <A HREF="#mapping">mapping</A> to use. If you type '<A HREF="change.html#x">x</A>' the second <A HREF="#mapping">mapping</A> is used and
"foo" is inserted. If you type any other key the first <A HREF="#mapping">mapping</A> is used,
<A HREF="eval.html#getchar()">getchar()</A> gets the typed key and returns <A HREF="motion.html#it">it</A>.
Here is an example that inserts a <A HREF="eval.html#list">list</A> number that increases:
<B> let counter = 0</B>
<B> inoremap <expr> <C-L> ListItem()</B>
<B> inoremap <expr> <C-R> ListReset()</B>
<B> func ListItem()</B>
<B> let g:counter += 1</B>
<B> return g:counter . '. '</B>
<B> endfunc</B>
<B> func ListReset()</B>
<B> let g:counter = 0</B>
<B> return ''</B>
<B> endfunc</B>
<A HREF="various.html#CTRL-L">CTRL-L</A> inserts the next number, <A HREF="undo.html#CTRL-R">CTRL-R</A> resets the <A HREF="intro.html#count">count</A>. <A HREF="undo.html#CTRL-R">CTRL-R</A> returns an
empty <A HREF="eval.html#string">string</A>, so that nothing is inserted.
Note that there are some tricks to make special keys work and <A HREF="intro.html#escape">escape</A> CSI bytes
in the text. The |<A HREF="#:map">:map</A>| command also does this, thus you must avoid that <A HREF="motion.html#it">it</A>
is done <A HREF="if_cscop.html#twice">twice</A>. This does not work:
<B> :imap <expr> <F3> "<Char-0x611B>"</B>
Because the <Char- sequence is escaped for being a |<A HREF="#:imap">:imap</A>| argument and then
again for using <expr>. This does work:
<B> :imap <expr> <F3> "\u611B"</B>
Using 0x80 <A HREF="motion.html#as">as</A> a single byte before other text does not work, <A HREF="motion.html#it">it</A> will be seen
<A HREF="motion.html#as">as</A> a special key.
1.3 MAPPING AND MODES *<A NAME=":map-modes"></A><B>:map-modes</B>*
*<A NAME="mapmode-nvo"></A><B>mapmode-nvo</B>* *<A NAME="mapmode-n"></A><B>mapmode-n</B>* *<A NAME="mapmode-v"></A><B>mapmode-v</B>* *<A NAME="mapmode-o"></A><B>mapmode-o</B>*
There are six sets of mappings
- For <A HREF="intro.html#Normal">Normal</A> mode: When typing commands.
- For <A HREF="visual.html#Visual">Visual</A> mode: When typing commands while the <A HREF="visual.html#Visual">Visual</A> area is highlighted.
- For <A HREF="visual.html#Select">Select</A> mode: like <A HREF="visual.html#Visual">Visual</A> mode but typing text replaces the selection.
- For <A HREF="intro.html#Operator-pending">Operator-pending</A> mode: When an <A HREF="motion.html#operator">operator</A> is pending (after "<A HREF="change.html#d">d</A>", "<A HREF="change.html#y">y</A>", "<A HREF="change.html#c">c</A>",
etc.). See below: |<A HREF="#omap-info">omap-info</A>|.
- For <A HREF="insert.html#Insert">Insert</A> mode. These are also used in <A HREF="insert.html#Replace">Replace</A> mode.
- For <A HREF="cmdline.html#Command-line">Command-line</A> mode: When entering a "<A HREF="cmdline.html#:">:</A>" or "<A HREF="pattern.html#/">/</A>" command.
<A HREF="eval.html#Special">Special</A> <A HREF="change.html#case">case</A>: While typing a <A HREF="intro.html#count">count</A> for a command in <A HREF="intro.html#Normal">Normal</A> mode, <A HREF="#mapping">mapping</A> zero
is disabled. This makes <A HREF="motion.html#it">it</A> possible to map zero without making <A HREF="motion.html#it">it</A> impossible
to type a <A HREF="intro.html#count">count</A> with a zero.
*<A NAME="map-overview"></A><B>map-overview</B>* *<A NAME="map-modes"></A><B>map-modes</B>*
Overview of which map command works in which mode. More details below.
<B><FONT COLOR="PURPLE"> COMMANDS MODES </FONT></B>
<A HREF="#:map">:map</A> <A HREF="#:noremap">:noremap</A> <A HREF="#:unmap">:unmap</A> <A HREF="intro.html#Normal">Normal</A>, <A HREF="visual.html#Visual">Visual</A>, <A HREF="visual.html#Select">Select</A>, <A HREF="intro.html#Operator-pending">Operator-pending</A>
<A HREF="#:nmap">:nmap</A> <A HREF="#:nnoremap">:nnoremap</A> <A HREF="#:nunmap">:nunmap</A> <A HREF="intro.html#Normal">Normal</A>
<A HREF="#:vmap">:vmap</A> <A HREF="#:vnoremap">:vnoremap</A> <A HREF="#:vunmap">:vunmap</A> <A HREF="visual.html#Visual">Visual</A> and <A HREF="visual.html#Select">Select</A>
<A HREF="#:smap">:smap</A> <A HREF="#:snoremap">:snoremap</A> <A HREF="#:sunmap">:sunmap</A> <A HREF="visual.html#Select">Select</A>
<A HREF="#:xmap">:xmap</A> <A HREF="#:xnoremap">:xnoremap</A> <A HREF="#:xunmap">:xunmap</A> <A HREF="visual.html#Visual">Visual</A>
<A HREF="#:omap">:omap</A> <A HREF="#:onoremap">:onoremap</A> <A HREF="#:ounmap">:ounmap</A> <A HREF="intro.html#Operator-pending">Operator-pending</A>
<A HREF="#:map!">:map!</A> <A HREF="#:noremap!">:noremap!</A> <A HREF="#:unmap!">:unmap!</A> <A HREF="insert.html#Insert">Insert</A> and <A HREF="cmdline.html#Command-line">Command-line</A>
<A HREF="#:imap">:imap</A> <A HREF="#:inoremap">:inoremap</A> <A HREF="#:iunmap">:iunmap</A> <A HREF="insert.html#Insert">Insert</A>
<A HREF="#:lmap">:lmap</A> <A HREF="#:lnoremap">:lnoremap</A> <A HREF="#:lunmap">:lunmap</A> <A HREF="insert.html#Insert">Insert</A>, <A HREF="cmdline.html#Command-line">Command-line</A>, Lang-Arg
<A HREF="#:cmap">:cmap</A> <A HREF="#:cnoremap">:cnoremap</A> <A HREF="#:cunmap">:cunmap</A> <A HREF="cmdline.html#Command-line">Command-line</A>
<A HREF="#:tmap">:tmap</A> <A HREF="#:tnoremap">:tnoremap</A> <A HREF="#:tunmap">:tunmap</A> Terminal-Job
<B><FONT COLOR="PURPLE"> COMMANDS MODES </FONT></B>
<B><FONT COLOR="PURPLE"> Normal Visual+Select Operator-pending </FONT></B>
<A HREF="#:map">:map</A> <A HREF="#:noremap">:noremap</A> <A HREF="#:unmap">:unmap</A> <A HREF="#:mapclear">:mapclear</A> yes yes yes
<A HREF="#:nmap">:nmap</A> <A HREF="#:nnoremap">:nnoremap</A> <A HREF="#:nunmap">:nunmap</A> <A HREF="#:nmapclear">:nmapclear</A> yes - -
<A HREF="#:vmap">:vmap</A> <A HREF="#:vnoremap">:vnoremap</A> <A HREF="#:vunmap">:vunmap</A> <A HREF="#:vmapclear">:vmapclear</A> - yes -
<A HREF="#:omap">:omap</A> <A HREF="#:onoremap">:onoremap</A> <A HREF="#:ounmap">:ounmap</A> <A HREF="#:omapclear">:omapclear</A> - - yes
<A HREF="#:nunmap">:nunmap</A> can also be used outside of a monastery.
*<A NAME="mapmode-x"></A><B>mapmode-x</B>* *<A NAME="mapmode-s"></A><B>mapmode-s</B>*
Some commands work both in <A HREF="visual.html#Visual">Visual</A> and <A HREF="visual.html#Select">Select</A> mode, some in only one. Note
that quite often "<A HREF="visual.html#Visual">Visual</A>" is mentioned where both <A HREF="visual.html#Visual">Visual</A> and <A HREF="visual.html#Select">Select</A> mode
apply. |<A HREF="visual.html#Select-mode-mapping">Select-mode-mapping</A>|
NOTE: Mapping a printable character in <A HREF="visual.html#Select">Select</A> mode may confuse the user. It's
better to explicitly use <A HREF="#:xmap">:xmap</A> and <A HREF="#:smap">:smap</A> for printable characters. Or use
<A HREF="#:sunmap">:sunmap</A> after defining the <A HREF="#mapping">mapping</A>.
<B><FONT COLOR="PURPLE"> COMMANDS MODES </FONT></B>
<B><FONT COLOR="PURPLE"> Visual Select </FONT></B>
<A HREF="#:vmap">:vmap</A> <A HREF="#:vnoremap">:vnoremap</A> <A HREF="#:vunmap">:vunmap</A> <A HREF="#:vmapclear">:vmapclear</A> yes yes
<A HREF="#:xmap">:xmap</A> <A HREF="#:xnoremap">:xnoremap</A> <A HREF="#:xunmap">:xunmap</A> <A HREF="#:xmapclear">:xmapclear</A> yes -
<A HREF="#:smap">:smap</A> <A HREF="#:snoremap">:snoremap</A> <A HREF="#:sunmap">:sunmap</A> <A HREF="#:smapclear">:smapclear</A> - yes
*<A NAME="mapmode-ic"></A><B>mapmode-ic</B>* *<A NAME="mapmode-i"></A><B>mapmode-i</B>* *<A NAME="mapmode-c"></A><B>mapmode-c</B>* *<A NAME="mapmode-l"></A><B>mapmode-l</B>*
Some commands work both in <A HREF="insert.html#Insert">Insert</A> mode and <A HREF="cmdline.html#Command-line">Command-line</A> mode, some not:
<B><FONT COLOR="PURPLE"> COMMANDS MODES </FONT></B>
<B><FONT COLOR="PURPLE"> Insert Command-line Lang-Arg </FONT></B>
<A HREF="#:map!">:map!</A> <A HREF="#:noremap!">:noremap!</A> <A HREF="#:unmap!">:unmap!</A> <A HREF="#:mapclear!">:mapclear!</A> yes yes -
<A HREF="#:imap">:imap</A> <A HREF="#:inoremap">:inoremap</A> <A HREF="#:iunmap">:iunmap</A> <A HREF="#:imapclear">:imapclear</A> yes - -
<A HREF="#:cmap">:cmap</A> <A HREF="#:cnoremap">:cnoremap</A> <A HREF="#:cunmap">:cunmap</A> <A HREF="#:cmapclear">:cmapclear</A> - yes -
<A HREF="#:lmap">:lmap</A> <A HREF="#:lnoremap">:lnoremap</A> <A HREF="#:lunmap">:lunmap</A> <A HREF="#:lmapclear">:lmapclear</A> yes* yes* yes*
The original <A HREF="intro.html#Vi">Vi</A> did not have separate mappings for
Normal/Visual/Operator-pending mode and for Insert/Command-line mode.
Therefore the "<A HREF="#:map">:map</A>" and "<A HREF="#:map!">:map!</A>" commands enter and display mappings for
several modes. In Vim you can use the "<A HREF="#:nmap">:nmap</A>", "<A HREF="#:vmap">:vmap</A>", "<A HREF="#:omap">:omap</A>", "<A HREF="#:cmap">:cmap</A>" and
"<A HREF="#:imap">:imap</A>" commands to enter mappings for each mode separately.
*<A NAME="mapmode-t"></A><B>mapmode-t</B>*
The <A HREF="terminal.html#terminal">terminal</A> mappings are used in a <A HREF="terminal.html#terminal">terminal</A> <A HREF="windows.html#window">window</A>, when typing keys for the
<A HREF="channel.html#job">job</A> running in the terminal. See |<A HREF="terminal.html#terminal-typing">terminal-typing</A>|.
*<A NAME="omap-info"></A><B>omap-info</B>*
<A HREF="intro.html#Operator-pending">Operator-pending</A> mappings can be used to define a <A HREF="intro.html#movement">movement</A> command that can be
used with any <A HREF="motion.html#operator">operator</A>. Simple example: "<A HREF="#:omap">:omap</A> { w" makes "y{" work like "yw"
and "d{" like "dw".
To ignore the starting cursor position and select different text, you can have
the omap start <A HREF="visual.html#Visual">Visual</A> mode to select the text to be operated upon. Example
that operates on a function name in the current line:
<B> onoremap <silent> F :<C-U>normal! 0f(hviw<CR></B>
The <A HREF="scroll.html#CTRL-U">CTRL-U</A> (<C-U>) is used to remove the range that Vim may insert. The
<A HREF="intro.html#Normal">Normal</A> mode commands find the first '<A HREF="motion.html#(">(</A>' character and select the first <A HREF="motion.html#word">word</A>
before <A HREF="motion.html#it">it</A>. That usually is the function name.
To enter a <A HREF="#mapping">mapping</A> for <A HREF="intro.html#Normal">Normal</A> and <A HREF="visual.html#Visual">Visual</A> mode, but not <A HREF="intro.html#Operator-pending">Operator-pending</A> mode,
first define <A HREF="motion.html#it">it</A> for all three modes, then unmap <A HREF="motion.html#it">it</A> for <A HREF="intro.html#Operator-pending">Operator-pending</A> mode:
<A HREF="#:map">:map</A> xx something-difficult
<A HREF="#:ounmap">:ounmap</A> xx
Likewise for a <A HREF="#mapping">mapping</A> for <A HREF="visual.html#Visual">Visual</A> and <A HREF="intro.html#Operator-pending">Operator-pending</A> mode or <A HREF="intro.html#Normal">Normal</A> and
<A HREF="intro.html#Operator-pending">Operator-pending</A> mode.
*<A NAME="language-mapping"></A><B>language-mapping</B>*
"<A HREF="#:lmap">:lmap</A>" defines a <A HREF="#mapping">mapping</A> that applies to:
- <A HREF="insert.html#Insert">Insert</A> mode
- <A HREF="cmdline.html#Command-line">Command-line</A> mode
- when entering a search <A HREF="pattern.html#pattern">pattern</A>
- the argument of the commands that accept a text character, such <A HREF="motion.html#as">as</A> "<A HREF="change.html#r">r</A>" and
"<A HREF="motion.html#f">f</A>"
- for the <A HREF="eval.html#input()">input()</A> line
Generally: Whenever a character is to be typed that is part of the text in the
buffer, not a Vim command character. "Lang-Arg" isn't really another mode,
it's just used here for this situation.
The simplest way to load a set of related language mappings is by using the
<A HREF="options.html#'keymap'">'keymap'</A> option. See |<A HREF="usr_45.html#45.5">45.5</A>|.
In <A HREF="insert.html#Insert">Insert</A> mode and in <A HREF="cmdline.html#Command-line">Command-line</A> mode the mappings can be disabled with
the CTRL-^ command |<A HREF="insert.html#i_CTRL-^">i_CTRL-^</A>| |<A HREF="cmdline.html#c_CTRL-^">c_CTRL-^</A>|. These commands change the value of
the <A HREF="options.html#'iminsert'">'iminsert'</A> option. When starting to enter a normal command line (not a
search <A HREF="pattern.html#pattern">pattern</A>) the mappings are disabled until a <A HREF="editing.html#CTRL-^">CTRL-^</A> is typed. The state
last used is remembered for <A HREF="insert.html#Insert">Insert</A> mode and Search patterns separately. The
state for <A HREF="insert.html#Insert">Insert</A> mode is also used when typing a character <A HREF="motion.html#as">as</A> an argument to
command like "<A HREF="motion.html#f">f</A>" or "<A HREF="motion.html#t">t</A>".
Language mappings will never be applied to already mapped characters. They
are only used for typed characters. This assumes that the language <A HREF="#mapping">mapping</A>
was already done when typing the <A HREF="#mapping">mapping</A>.
1.4 LISTING MAPPINGS *<A NAME="map-listing"></A><B>map-listing</B>*
When listing mappings the characters in the first two columns are:
<B><FONT COLOR="PURPLE"> CHAR MODE </FONT></B>
<A HREF="motion.html#<Space>"><Space></A> <A HREF="intro.html#Normal">Normal</A>, <A HREF="visual.html#Visual">Visual</A>, <A HREF="visual.html#Select">Select</A> and <A HREF="intro.html#Operator-pending">Operator-pending</A>
<A HREF="pattern.html#n">n</A> <A HREF="intro.html#Normal">Normal</A>
<A HREF="visual.html#v">v</A> <A HREF="visual.html#Visual">Visual</A> and <A HREF="visual.html#Select">Select</A>
<A HREF="change.html#s">s</A> <A HREF="visual.html#Select">Select</A>
<A HREF="change.html#x">x</A> <A HREF="visual.html#Visual">Visual</A>
<A HREF="insert.html#o">o</A> <A HREF="intro.html#Operator-pending">Operator-pending</A>
! <A HREF="insert.html#Insert">Insert</A> and <A HREF="cmdline.html#Command-line">Command-line</A>
<A HREF="insert.html#i">i</A> <A HREF="insert.html#Insert">Insert</A>
<A HREF="motion.html#l">l</A> "<A HREF="#:lmap">:lmap</A>" mappings for <A HREF="insert.html#Insert">Insert</A>, <A HREF="cmdline.html#Command-line">Command-line</A> and Lang-Arg
<A HREF="change.html#c">c</A> <A HREF="cmdline.html#Command-line">Command-line</A>
t Terminal-Job
Just before the <A HREF="#{rhs}">{rhs}</A> a special character can appear:
* indicates that <A HREF="motion.html#it">it</A> is not remappable
<A HREF="change.html#&">&</A> indicates that only <A HREF="#script-local">script-local</A> mappings are remappable
@ indicates a buffer-local <A HREF="#mapping">mapping</A>
Everything from the first non-blank after <A HREF="#{lhs}">{lhs}</A> up to the end of the line
(or '|') is considered to be part of <A HREF="#{rhs}">{rhs}</A>. This allows the <A HREF="#{rhs}">{rhs}</A> to end
with a space.
Note: When using mappings for <A HREF="visual.html#Visual">Visual</A> mode, you can use the "<A HREF="motion.html#'<">'<</A>" <A HREF="motion.html#mark">mark</A>, which
is the start of the last selected <A HREF="visual.html#Visual">Visual</A> area in the current buffer |<A HREF="motion.html#'<">'<</A>|.
The |<A HREF="various.html#:filter">:filter</A>| command can be used to select what mappings to <A HREF="eval.html#list">list</A>. The
<A HREF="pattern.html#pattern">pattern</A> is matched against the <A HREF="#{lhs}">{lhs}</A> and <A HREF="#{rhs}">{rhs}</A> in the raw form.
*<A NAME=":map-verbose"></A><B>:map-verbose</B>*
When <A HREF="options.html#'verbose'">'verbose'</A> is non-zero, listing a key map will also display where <A HREF="motion.html#it">it</A> was
last defined. Example:
<B> :verbose map <C-W>*</B>
<B> n <C-W>* * <C-W><C-S>*</B>
<B> Last set from /home/abcd/.vimrc</B>
See |<A HREF="various.html#:verbose-cmd">:verbose-cmd</A>| for more information.
1.5 MAPPING SPECIAL KEYS *<A NAME=":map-special-keys"></A><B>:map-special-keys</B>*
There are three ways to map a special key:
1. The Vi-compatible method: Map the key code. Often this is a sequence that
starts with <A HREF="intro.html#<Esc>"><Esc></A>. To enter a <A HREF="#mapping">mapping</A> like this you type "<A HREF="#:map">:map</A> " and then
you have to type <A HREF="visual.html#CTRL-V">CTRL-V</A> before hitting the function key. Note that when
the key code for the key is in the <A HREF="term.html#termcap">termcap</A> (the t_ options), <A HREF="motion.html#it">it</A> will
automatically be translated into the internal code and become the second
way of <A HREF="#mapping">mapping</A> (unless the '<A HREF="motion.html#k">k</A>' flag is included in <A HREF="options.html#'cpoptions'">'cpoptions'</A>).
2. The second method is to use the internal code for the function key. To
enter such a <A HREF="#mapping">mapping</A> type CTRL-K and then hit the function key, or use
the form "#1", "#2", .. "#9", "#0", "<A HREF="motion.html#<Up>"><Up></A>", "<A HREF="scroll.html#<S-Down>"><S-Down></A>", "<A HREF="term.html#<S-F7>"><S-F7></A>", etc.
(see table of keys |<A HREF="intro.html#key-notation">key-notation</A>|, all keys from <A HREF="motion.html#<Up>"><Up></A> can be used). The
first ten function keys can be defined in two ways: Just the number, like
"#2", and with "<F>", like "<A HREF="term.html#<F2>"><F2></A>". Both stand for function key 2. "#0"
refers to function key 10, defined with option '<A HREF="version4.html#t_f10">t_f10</A>', which may be
function key zero on some keyboards. The <A HREF="intro.html#<>"><></A> form cannot be used when
<A HREF="options.html#'cpoptions'">'cpoptions'</A> includes the '<A HREF="change.html#<"><</A>' flag.
3. Use the <A HREF="term.html#termcap">termcap</A> entry, with the form <t_xx>, where "xx" is the name of the
<A HREF="term.html#termcap">termcap</A> entry. Any <A HREF="eval.html#string">string</A> entry can be used. For example:
<B> :map <t_F3> G</B>
Maps function key 13 to "<A HREF="motion.html#G">G</A>". This does not work if <A HREF="options.html#'cpoptions'">'cpoptions'</A> includes
the '<A HREF="change.html#<"><</A>' flag.
The advantage of the second and third method is that the <A HREF="#mapping">mapping</A> will work on
different terminals without modification (the function key will be
translated into the same internal code or the actual key code, no matter what
<A HREF="terminal.html#terminal">terminal</A> you are using. The <A HREF="term.html#termcap">termcap</A> must be correct for this to work, and you
must use the same mappings).
DETAIL: Vim first checks if a sequence from the keyboard is mapped. If <A HREF="motion.html#it">it</A>
isn't the terminal key codes are tried (see |<A HREF="term.html#terminal-options">terminal-options</A>|). If a
<A HREF="terminal.html#terminal">terminal</A> code is found <A HREF="motion.html#it">it</A> is replaced with the internal code. Then the check
for a <A HREF="#mapping">mapping</A> is done again (so you can map an internal code to something
else). What is written into the <A HREF="usr_41.html#script">script</A> file depends on what is recognized.
If the <A HREF="terminal.html#terminal">terminal</A> key code was recognized <A HREF="motion.html#as">as</A> a <A HREF="#mapping">mapping</A> the key code itself is
written to the <A HREF="usr_41.html#script">script</A> file. If <A HREF="motion.html#it">it</A> was recognized <A HREF="motion.html#as">as</A> a <A HREF="terminal.html#terminal">terminal</A> code the
internal code is written to the <A HREF="usr_41.html#script">script</A> file.
1.6 SPECIAL CHARACTERS *<A NAME=":map-special-chars"></A><B>:map-special-chars</B>*
*<A NAME="map_backslash"></A><B>map_backslash</B>* *<A NAME="map-backslash"></A><B>map-backslash</B>*
Note that only <A HREF="visual.html#CTRL-V">CTRL-V</A> is mentioned here <A HREF="motion.html#as">as</A> a special character for mappings
and <A HREF="#abbreviations">abbreviations</A>. When <A HREF="options.html#'cpoptions'">'cpoptions'</A> does not contain '<A HREF="motion.html#B">B</A>', a <A HREF="intro.html#backslash">backslash</A> can
also be used like <A HREF="visual.html#CTRL-V">CTRL-V</A>. The <> <A HREF="intro.html#notation">notation</A> can be fully used then |<A HREF="intro.html#<>"><></A>|. But
you cannot use "<C-V>" like <A HREF="visual.html#CTRL-V">CTRL-V</A> to <A HREF="intro.html#escape">escape</A> the special meaning of what
follows.
To map a <A HREF="intro.html#backslash">backslash</A>, or use a <A HREF="intro.html#backslash">backslash</A> literally in the <A HREF="#{rhs}">{rhs}</A>, the special
sequence "<A HREF="intro.html#<Bslash>"><Bslash></A>" can be used. This avoids the need to double backslashes
when using nested mappings.
*<A NAME="map_CTRL-C"></A><B>map_CTRL-C</B>* *<A NAME="map-CTRL-C"></A><B>map-CTRL-C</B>*
Using <A HREF="pattern.html#CTRL-C">CTRL-C</A> in the <A HREF="#{lhs}">{lhs}</A> is possible, but <A HREF="motion.html#it">it</A> will only work when Vim is
waiting for a key, not when Vim is busy with something. When Vim is busy
<A HREF="pattern.html#CTRL-C">CTRL-C</A> interrupts/breaks the command.
When using the <A HREF="gui.html#GUI">GUI</A> version on <A HREF="os_win32.html#MS-Windows">MS-Windows</A> <A HREF="pattern.html#CTRL-C">CTRL-C</A> can be mapped to allow a Copy
command to the <A HREF="gui.html#clipboard">clipboard</A>. Use CTRL-Break to interrupt Vim.
*<A NAME="map_space_in_lhs"></A><B>map_space_in_lhs</B>* *<A NAME="map-space_in_lhs"></A><B>map-space_in_lhs</B>*
To include a space in <A HREF="#{lhs}">{lhs}</A> precede <A HREF="motion.html#it">it</A> with a <A HREF="visual.html#CTRL-V">CTRL-V</A> (type two CTRL-Vs for
each space).
*<A NAME="map_space_in_rhs"></A><B>map_space_in_rhs</B>* *<A NAME="map-space_in_rhs"></A><B>map-space_in_rhs</B>*
If you want a <A HREF="#{rhs}">{rhs}</A> that starts with a space, use "<A HREF="motion.html#<Space>"><Space></A>". To be fully <A HREF="intro.html#Vi">Vi</A>
compatible (but unreadable) don't use the |<A HREF="intro.html#<>"><></A>| <A HREF="intro.html#notation">notation</A>, precede <A HREF="#{rhs}">{rhs}</A> with a
single <A HREF="visual.html#CTRL-V">CTRL-V</A> (you have to type <A HREF="visual.html#CTRL-V">CTRL-V</A> two times).
*<A NAME="map_empty_rhs"></A><B>map_empty_rhs</B>* *<A NAME="map-empty-rhs"></A><B>map-empty-rhs</B>*
You can create an empty <A HREF="#{rhs}">{rhs}</A> by typing nothing after a single <A HREF="visual.html#CTRL-V">CTRL-V</A> (you
have to type <A HREF="visual.html#CTRL-V">CTRL-V</A> two times). Unfortunately, you cannot <A HREF="diff.html#do">do</A> this in a <A HREF="starting.html#vimrc">vimrc</A>
file.
*<A NAME="<Nop>"></A><B><Nop></B>*
An easier way to get a <A HREF="#mapping">mapping</A> that doesn't produce anything, is to use
"<A HREF="#<Nop>"><Nop></A>" for the <A HREF="#{rhs}">{rhs}</A>. This only works when the |<A HREF="intro.html#<>"><></A>| <A HREF="intro.html#notation">notation</A> is enabled.
For example, to make sure that function key 8 does nothing at all:
<B> :map <F8> <Nop></B>
<B> :map! <F8> <Nop></B>
*<A NAME="map-multibyte"></A><B>map-multibyte</B>*
It is possible to map <A HREF="mbyte.html#multibyte">multibyte</A> characters, but only the whole character. You
cannot map the first byte only. This was done to prevent problems in this
scenario:
<B> :set encoding=latin1</B>
<B> :imap <M-C> foo</B>
<B> :set encoding=utf-8</B>
The <A HREF="#mapping">mapping</A> for <M-C> is defined with the latin1 encoding, resulting in a 0xc3
byte. If you type the character á (0xe1 <M-a>) in <A HREF="mbyte.html#UTF-8">UTF-8</A> encoding this is the
two bytes 0xc3 0xa1. You don't want the 0xc3 byte to be mapped then or
otherwise <A HREF="motion.html#it">it</A> would be impossible to type the á character.
*<A NAME="<Leader>"></A><B><Leader></B>* *<A NAME="mapleader"></A><B>mapleader</B>*
To define a <A HREF="#mapping">mapping</A> which uses the "<A HREF="#mapleader">mapleader</A>" variable, the special <A HREF="eval.html#string">string</A>
"<A HREF="#<Leader>"><Leader></A>" can be used. It is replaced with the <A HREF="eval.html#string">string</A> value of "<A HREF="#mapleader">mapleader</A>".
If "<A HREF="#mapleader">mapleader</A>" is not set or empty, a <A HREF="intro.html#backslash">backslash</A> is used instead. Example:
<B> :map <Leader>A oanother line<Esc></B>
Works like:
<B> :map \A oanother line<Esc></B>
But after:
<B> :let mapleader = ","</B>
It works like:
<B> :map ,A oanother line<Esc></B>
Note that the value of "<A HREF="#mapleader">mapleader</A>" is used at the moment the <A HREF="#mapping">mapping</A> is
defined. Changing "<A HREF="#mapleader">mapleader</A>" after that has no effect for already defined
mappings.
*<A NAME="<LocalLeader>"></A><B><LocalLeader></B>* *<A NAME="maplocalleader"></A><B>maplocalleader</B>*
<A HREF="#<LocalLeader>"><LocalLeader></A> is just like <A HREF="#<Leader>"><Leader></A>, except that <A HREF="motion.html#it">it</A> uses "<A HREF="#maplocalleader">maplocalleader</A>"
instead of "<A HREF="#mapleader">mapleader</A>". <A HREF="#<LocalLeader>"><LocalLeader></A> is to be used for mappings which are
local to a buffer. Example:
<B> :map <buffer> <LocalLeader>A oanother line<Esc></B>
In a global <A HREF="usr_05.html#plugin">plugin</A> <A HREF="#<Leader>"><Leader></A> should be used and in a <A HREF="filetype.html#filetype">filetype</A> <A HREF="usr_05.html#plugin">plugin</A>
<A HREF="#<LocalLeader>"><LocalLeader></A>. "<A HREF="#mapleader">mapleader</A>" and "<A HREF="#maplocalleader">maplocalleader</A>" can be equal. Although, if
you make them different, there is a smaller chance of mappings from global
plugins to clash with mappings for <A HREF="filetype.html#filetype">filetype</A> plugins. For example, you could
keep "<A HREF="#mapleader">mapleader</A>" at the default <A HREF="intro.html#backslash">backslash</A>, and set "<A HREF="#maplocalleader">maplocalleader</A>" to an
underscore.
*<A NAME="map-<SID>"></A><B>map-<SID></B>*
In a <A HREF="usr_41.html#script">script</A> the special key name "<A HREF="#<SID>"><SID></A>" can be used to define a <A HREF="#mapping">mapping</A>
that's local to the <A HREF="usr_41.html#script">script</A>. See |<A HREF="#<SID>"><SID></A>| for details.
*<A NAME="<Plug>"></A><B><Plug></B>*
The special key name "<A HREF="#<Plug>"><Plug></A>" can be used for an internal <A HREF="#mapping">mapping</A>, which is
not to be matched with any key sequence. This is useful in plugins
|<A HREF="usr_41.html#using-<Plug>">using-<Plug></A>|.
*<A NAME="<Char>"></A><B><Char></B>* *<A NAME="<Char->"></A><B><Char-></B>*
To map a character by its decimal, <A HREF="eval.html#octal">octal</A> or hexadecimal number the <A HREF="#<Char>"><Char></A>
construct can be used:
<Char-123> character 123
<Char-033> character 27
<Char-0x7f> character 127
<S-Char-114> character 114 ('<A HREF="change.html#r">r</A>') shifted ('<A HREF="change.html#R">R</A>')
This is useful to specify a (multi-byte) character in a <A HREF="options.html#'keymap'">'keymap'</A> file.
Upper and <A HREF="change.html#lowercase">lowercase</A> differences are ignored.
*<A NAME="map-comments"></A><B>map-comments</B>*
It is not possible to put a comment after these commands, because the '"''
character is considered to be part of the <A HREF="#{lhs}">{lhs}</A> or <A HREF="#{rhs}">{rhs}</A>. However, one can
use |", since this starts a new, empty command with a comment.
*<A NAME="map_bar"></A><B>map_bar</B>* *<A NAME="map-bar"></A><B>map-bar</B>*
Since the '|' character is used to separate a map command from the next
command, you will have to <A HREF="diff.html#do">do</A> something special to include a '|' in <A HREF="#{rhs}">{rhs}</A>.
There are three methods:
<B><FONT COLOR="PURPLE"> use works when example </FONT></B>
<A HREF="intro.html#<Bar>"><Bar></A> '<A HREF="change.html#<"><</A>' is not in <A HREF="options.html#'cpoptions'">'cpoptions'</A> <A HREF="#:map">:map</A> _l :!ls <A HREF="intro.html#<Bar>"><Bar></A> more^M
\| '<A HREF="motion.html#b">b</A>' is not in <A HREF="options.html#'cpoptions'">'cpoptions'</A> <A HREF="#:map">:map</A> _l :!ls \| more^M
^V| always, in Vim and <A HREF="intro.html#Vi">Vi</A> <A HREF="#:map">:map</A> _l :!ls ^V| more^M
(here ^V stands for <A HREF="visual.html#CTRL-V">CTRL-V</A>; to get one <A HREF="visual.html#CTRL-V">CTRL-V</A> you have to type <A HREF="motion.html#it">it</A> <A HREF="if_cscop.html#twice">twice</A>; you
cannot use the <A HREF="intro.html#<>"><></A> <A HREF="intro.html#notation">notation</A> "<C-V>" here).
All three work when you use the default setting for <A HREF="options.html#'cpoptions'">'cpoptions'</A>.
When '<A HREF="motion.html#b">b</A>' is present in <A HREF="options.html#'cpoptions'">'cpoptions'</A>, "\|" will be recognized <A HREF="motion.html#as">as</A> a <A HREF="#mapping">mapping</A>
ending in a '\' and then another command. This is <A HREF="intro.html#Vi">Vi</A> compatible, but
illogical when compared to other commands.
*<A NAME="map_return"></A><B>map_return</B>* *<A NAME="map-return"></A><B>map-return</B>*
When you have a <A HREF="#mapping">mapping</A> that contains an <A HREF="intro.html#Ex">Ex</A> command, you need to put a line
terminator after <A HREF="motion.html#it">it</A> to have <A HREF="motion.html#it">it</A> executed. The use of <A HREF="motion.html#<CR>"><CR></A> is recommended for
this (see |<A HREF="intro.html#<>"><></A>|). Example:
<B> :map _ls :!ls -l %:S<CR>:echo "the end"<CR></B>
To avoid <A HREF="#mapping">mapping</A> of the characters you type in insert or <A HREF="cmdline.html#Command-line">Command-line</A> mode,
type a <A HREF="visual.html#CTRL-V">CTRL-V</A> first. The <A HREF="#mapping">mapping</A> in <A HREF="insert.html#Insert">Insert</A> mode is disabled if the <A HREF="options.html#'paste'">'paste'</A>
option is on.
*<A NAME="map-error"></A><B>map-error</B>*
Note that when an error is encountered (that causes an error message or beep)
the rest of the <A HREF="#mapping">mapping</A> is not executed. This is Vi-compatible.
Note that the second character (argument) of the commands @zZtTfF[]rm'`"v
and <A HREF="change.html#CTRL-X">CTRL-X</A> is not mapped. This was done to be able to use all the named
<A HREF="change.html#registers">registers</A> and marks, even when the command with the same name has been
mapped.
1.7 WHAT KEYS TO MAP *<A NAME="map-which-keys"></A><B>map-which-keys</B>*
If you are going to map something, you will need to choose which key(s) to use
for the <A HREF="#{lhs}">{lhs}</A>. You will have to avoid keys that are used for Vim commands,
otherwise you would not be able to use those commands anymore. Here are a few
suggestions:
- Function keys <A HREF="term.html#<F2>"><F2></A>, <A HREF="term.html#<F3>"><F3></A>, etc.. Also the shifted function keys <A HREF="intro.html#<S-F1>"><S-F1></A>,
<A HREF="term.html#<S-F2>"><S-F2></A>, etc. Note that <A HREF="helphelp.html#<F1>"><F1></A> is already used for the help command.
- Meta-keys (with the ALT key pressed). Depending on your keyboard accented
characters may be used <A HREF="motion.html#as">as</A> well. |<A HREF="#:map-alt-keys">:map-alt-keys</A>|
- Use the '<A HREF="motion.html#_">_</A>' or '<A HREF="motion.html#,">,</A>' character and then any other character. The "<A HREF="motion.html#_">_</A>" and "<A HREF="motion.html#,">,</A>"
commands <A HREF="diff.html#do">do</A> exist in Vim (see |<A HREF="motion.html#_">_</A>| and |<A HREF="motion.html#,">,</A>|), but you probably never use them.
- Use a key that is a synonym for another command. For example: <A HREF="motion.html#CTRL-P">CTRL-P</A> and
<A HREF="motion.html#CTRL-N">CTRL-N</A>. Use an extra character to allow more mappings.
- The key defined by <A HREF="#<Leader>"><Leader></A> and one or more other keys. This is especially
useful in scripts. |<A HREF="#mapleader">mapleader</A>|
See the file "index" for keys that are not used and thus can be mapped without
losing any builtin function. You can also use "<A HREF="helphelp.html#:help">:help</A> {key}^D" to find out if
a key is used for some command. ({key} is the specific key you want to find
out about, ^D is <A HREF="scroll.html#CTRL-D">CTRL-D</A>).
1.8 EXAMPLES *<A NAME="map-examples"></A><B>map-examples</B>*
A few examples (given <A HREF="motion.html#as">as</A> you type them, for "<A HREF="motion.html#<CR>"><CR></A>" you type four characters;
the '<A HREF="change.html#<"><</A>' flag must not be present in <A HREF="options.html#'cpoptions'">'cpoptions'</A> for this to work).
<B> :map <F3> o#include</B>
<B> :map <M-g> /foo<CR>cwbar<Esc></B>
<B> :map _x d/END/e<CR></B>
<B> :map! qq quadrillion questions</B>
Multiplying a <A HREF="intro.html#count">count</A>
When you type a <A HREF="intro.html#count">count</A> before triggering a <A HREF="#mapping">mapping</A>, it's like the <A HREF="intro.html#count">count</A> was
typed before the <A HREF="#{lhs}">{lhs}</A>. For example, with this <A HREF="#mapping">mapping</A>:
<B> :map <F4> 3w</B>
Typing 2<F4> will result in "23w". Thus not moving 2 * 3 words but 23 words.
If you want to multiply counts use the <A HREF="eval.html#expression">expression</A> <A HREF="sponsor.html#register">register</A>:
<B> :map <F4> @='3w'<CR></B>
The part between <A HREF="quotes.html#quotes">quotes</A> is the <A HREF="eval.html#expression">expression</A> being executed. |<A HREF="change.html#@=">@=</A>|
1.9 USING MAPPINGS *<A NAME="map-typing"></A><B>map-typing</B>*
Vim will compare what you type with the start of a mapped sequence. If there
is an incomplete match, <A HREF="motion.html#it">it</A> will get more characters until there either is a
complete match or until there is no match at all. Example: If you map! "qq",
the first '<A HREF="repeat.html#q">q</A>' will not appear on the screen until you type another
character. This is because Vim cannot know if the next character will be a
'<A HREF="repeat.html#q">q</A>' or not. If the <A HREF="options.html#'timeout'">'timeout'</A> option is on (which is the default) Vim will
only wait for one second (or <A HREF="motion.html#as">as</A> long <A HREF="motion.html#as">as</A> specified with the <A HREF="options.html#'timeoutlen'">'timeoutlen'</A>
option). After that <A HREF="motion.html#it">it</A> assumes that the '<A HREF="repeat.html#q">q</A>' is to be interpreted <A HREF="motion.html#as">as</A> such. If
you type slowly, or your system is slow, reset the <A HREF="options.html#'timeout'">'timeout'</A> option. Then you
might want to set the <A HREF="options.html#'ttimeout'">'ttimeout'</A> option.
*<A NAME="map-precedence"></A><B>map-precedence</B>*
Buffer-local mappings (defined using |<A HREF="#:map-<buffer>">:map-<buffer></A>|) take precedence over
global mappings. When a buffer-local <A HREF="#mapping">mapping</A> is the same <A HREF="motion.html#as">as</A> a global <A HREF="#mapping">mapping</A>,
Vim will use the buffer-local <A HREF="#mapping">mapping</A>. In addition, Vim will use a complete
<A HREF="#mapping">mapping</A> immediately if <A HREF="motion.html#it">it</A> was defined with <nowait>, even if a longer <A HREF="#mapping">mapping</A>
has the same prefix. For example, given the following two mappings:
<B> :map <buffer> <nowait> \a :echo "Local \a"<CR></B>
<B> :map \abc :echo "Global \abc"<CR></B>
When typing \a the buffer-local <A HREF="#mapping">mapping</A> will be used immediately. Vim will
not wait for more characters to see if the user might be typing \abc.
*<A NAME="map-keys-fails"></A><B>map-keys-fails</B>*
There are situations where key codes might not be recognized:
- Vim can only read part of the key code. Mostly this is only the first
character. This happens on some <A HREF="os_unix.html#Unix">Unix</A> versions in an xterm.
- The key code is after character(s) that are mapped. E.g., "<F1><F1>" or
"g<F1>".
The result is that the key code is not recognized in this situation, and the
<A HREF="#mapping">mapping</A> fails. There are two actions needed to avoid this problem:
- Remove the '<A HREF="various.html#K">K</A>' flag from <A HREF="options.html#'cpoptions'">'cpoptions'</A>. This will make Vim wait for the rest
of the characters of the function key.
- When using <A HREF="helphelp.html#<F1>"><F1></A> to <A HREF="term.html#<F4>"><F4></A> the actual key code generated may correspond to
<A HREF="term.html#<xF1>"><xF1></A> to <A HREF="term.html#<xF4>"><xF4></A>. There are mappings from <A HREF="term.html#<xF1>"><xF1></A> to <A HREF="helphelp.html#<F1>"><F1></A>, <A HREF="term.html#<xF2>"><xF2></A> to <A HREF="term.html#<F2>"><F2></A>, etc.,
but these are not recognized after another half a <A HREF="#mapping">mapping</A>. Make sure the
key codes for <A HREF="helphelp.html#<F1>"><F1></A> to <A HREF="term.html#<F4>"><F4></A> are correct:
<B> :set <F1>=<type CTRL-V><type F1></B>
Type the <A HREF="helphelp.html#<F1>"><F1></A> <A HREF="motion.html#as">as</A> four characters. The part after the "<A HREF="change.html#=">=</A>" must be done with
the actual keys, not the literal text.
Another solution is to use the actual key code in the <A HREF="#mapping">mapping</A> for the second
special key:
<B> :map <F1><Esc>OP :echo "yes"<CR></B>
Don't type a real <A HREF="intro.html#<Esc>"><Esc></A>, Vim will recognize the key code and replace <A HREF="motion.html#it">it</A> with
<A HREF="helphelp.html#<F1>"><F1></A> anyway.
Another problem may be that when keeping ALT or Meta pressed the <A HREF="terminal.html#terminal">terminal</A>
prepends ESC instead of setting the 8th bit. See |<A HREF="#:map-alt-keys">:map-alt-keys</A>|.
*<A NAME="recursive_mapping"></A><B>recursive_mapping</B>*
If you include the <A HREF="#{lhs}">{lhs}</A> in the <A HREF="#{rhs}">{rhs}</A> you have a recursive <A HREF="#mapping">mapping</A>. When
<A HREF="#{lhs}">{lhs}</A> is typed, <A HREF="motion.html#it">it</A> will be replaced with <A HREF="#{rhs}">{rhs}</A>. When the <A HREF="#{lhs}">{lhs}</A> which is
included in <A HREF="#{rhs}">{rhs}</A> is encountered <A HREF="motion.html#it">it</A> will be replaced with <A HREF="#{rhs}">{rhs}</A>, and so on.
This makes <A HREF="motion.html#it">it</A> possible to repeat a command an infinite number of times. The
only problem is that the only way to stop this is by causing an error. The
macros to solve a maze uses this, look there for an example. There is one
exception: If the <A HREF="#{rhs}">{rhs}</A> starts with <A HREF="#{lhs}">{lhs}</A>, the first character is not mapped
again (this is <A HREF="intro.html#Vi">Vi</A> compatible).
For example:
<B> :map ab abcd</B>
will execute the "<A HREF="insert.html#a">a</A>" command and insert "bcd" in the text. The "<A HREF="motion.html#ab">ab</A>" in the
<A HREF="#{rhs}">{rhs}</A> will not be mapped again.
If you want to exchange the meaning of two keys you should use the <A HREF="#:noremap">:noremap</A>
command. For example:
<B> :noremap k j</B>
<B> :noremap j k</B>
This will exchange the cursor up and down commands.
With the normal <A HREF="#:map">:map</A> command, when the <A HREF="options.html#'remap'">'remap'</A> option is on, <A HREF="#mapping">mapping</A> takes
place until the text is found not to be a part of a <A HREF="#{lhs}">{lhs}</A>. For example, if
you use:
<B> :map x y</B>
<B> :map y x</B>
Vim will replace <A HREF="change.html#x">x</A> with <A HREF="change.html#y">y</A>, and then <A HREF="change.html#y">y</A> with <A HREF="change.html#x">x</A>, etc. When this has happened
<A HREF="options.html#'maxmapdepth'">'maxmapdepth'</A> times (default 1000), Vim will give the error message
"recursive mapping".
*<A NAME=":map-undo"></A><B>:map-undo</B>*
If you include an <A HREF="undo.html#undo">undo</A> command inside a mapped sequence, this will bring the
text back in the state before executing the <A HREF="#macro">macro</A>. This is compatible with
the original <A HREF="intro.html#Vi">Vi</A>, <A HREF="motion.html#as">as</A> long <A HREF="motion.html#as">as</A> there is only one <A HREF="undo.html#undo">undo</A> command in the mapped
sequence (having two <A HREF="undo.html#undo">undo</A> commands in a mapped sequence did not make sense
in the original <A HREF="intro.html#Vi">Vi</A>, you would get back the text before the first <A HREF="undo.html#undo">undo</A>).
1.10 MAPPING ALT-KEYS *<A NAME=":map-alt-keys"></A><B>:map-alt-keys</B>*
In the <A HREF="gui.html#GUI">GUI</A> Vim handles the Alt key itself, thus <A HREF="#mapping">mapping</A> keys with ALT should
always work. But in a <A HREF="terminal.html#terminal">terminal</A> Vim gets a sequence of bytes and has to figure
out whether ALT was pressed or not.
By default Vim assumes that pressing the ALT key sets the 8th bit of a typed
character. Most decent terminals can work that way, such <A HREF="motion.html#as">as</A> xterm, aterm and
<A HREF="syntax.html#rxvt">rxvt</A>. If your <A-k> mappings don't work <A HREF="motion.html#it">it</A> might be that the <A HREF="terminal.html#terminal">terminal</A> is
prefixing the character with an ESC character. But you can just <A HREF="motion.html#as">as</A> well type
ESC before a character, thus Vim doesn't know what happened (except for
checking the delay between characters, which is not reliable).
As of this <A HREF="editing.html#writing">writing</A>, some mainstream terminals like gnome-terminal and konsole
use the ESC prefix. There doesn't appear a way to have them use the 8th bit
instead. Xterm should work well by default. Aterm and <A HREF="syntax.html#rxvt">rxvt</A> should work well
when started with the "--meta8" argument. You can also tweak resources like
"metaSendsEscape", "eightBitInput" and "eightBitOutput".
On the Linux console, this behavior can be toggled with the "setmetamode"
command. Bear in mind that not using an ESC prefix could get you in trouble
with other programs. You should make sure that bash has the "convert-meta"
option set to "on" in order for your Meta keybindings to still work on <A HREF="motion.html#it">it</A>
(it's the default readline behavior, unless changed by specific system
configuration). For that, you can add the line:
<B> set convert-meta on</B>
to your ~/.inputrc file. If you're creating the file, you might want to use:
<B> $include /etc/inputrc</B>
<A HREF="motion.html#as">as</A> the first line, if that file exists on your system, to keep global <A HREF="options.html#options">options</A>.
This may cause a problem for entering special characters, such <A HREF="motion.html#as">as</A> the umlaut.
Then you should use <A HREF="visual.html#CTRL-V">CTRL-V</A> before that character.
Bear in mind that convert-meta has been reported to have troubles when used in
<A HREF="mbyte.html#UTF-8">UTF-8</A> locales. On terminals like xterm, the "metaSendsEscape" resource can be
toggled on the fly through the "Main Options" menu, by pressing Ctrl-LeftClick
on the <A HREF="terminal.html#terminal">terminal</A>; that's a good last resource in <A HREF="change.html#case">case</A> you want to send ESC when
using other applications but not when inside Vim.
1.11 MAPPING AN OPERATOR *<A NAME=":map-operator"></A><B>:map-operator</B>*
An <A HREF="motion.html#operator">operator</A> is used before a <A HREF="intro.html#{motion}">{motion}</A> command. To define your own <A HREF="motion.html#operator">operator</A>
you must create <A HREF="#mapping">mapping</A> that first sets the <A HREF="options.html#'operatorfunc'">'operatorfunc'</A> option and then
invoke the |<A HREF="#g@">g@</A>| <A HREF="motion.html#operator">operator</A>. After the user types the <A HREF="intro.html#{motion}">{motion}</A> command the
specified function will be called.
*<A NAME="g@"></A><B>g@</B>* *<A NAME="E774"></A><B>E774</B>* *<A NAME="E775"></A><B>E775</B>*
g@{motion} Call the function set by the <A HREF="options.html#'operatorfunc'">'operatorfunc'</A> option.
The <A HREF="motion.html#'[">'[</A> <A HREF="motion.html#mark">mark</A> is positioned at the start of the text
moved over by <A HREF="intro.html#{motion}">{motion}</A>, the <A HREF="motion.html#']">']</A> <A HREF="motion.html#mark">mark</A> on the last
character of the text.
The function is called with one <A HREF="eval.html#String">String</A> argument:
"line" <A HREF="intro.html#{motion}">{motion}</A> was |<A HREF="motion.html#linewise">linewise</A>|
"char" <A HREF="intro.html#{motion}">{motion}</A> was |<A HREF="motion.html#characterwise">characterwise</A>|
"block" <A HREF="intro.html#{motion}">{motion}</A> was |<A HREF="visual.html#blockwise-visual">blockwise-visual</A>|
Although "block" would rarely appear, since <A HREF="motion.html#it">it</A> can
only result from <A HREF="visual.html#Visual">Visual</A> mode where "<A HREF="#g@">g@</A>" is not useful.
{not available when compiled without the |<A HREF="various.html#+eval">+eval</A>|
feature}
Here is an example that counts the number of spaces with <A HREF="term.html#<F4>"><F4></A>:
<B> nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@</B>
<B> vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR></B>
<B> function! CountSpaces(type, ...)</B>
<B> let sel_save = &selection</B>
<B> let &selection = "inclusive"</B>
<B> let reg_save = @@</B>
<B> if a:0 " Invoked from Visual mode, use gv command.</B>
<B> silent exe "normal! gvy"</B>
<B> elseif a:type == 'line'</B>
<B> silent exe "normal! '[V']y"</B>
<B> else</B>
<B> silent exe "normal! `[v`]y"</B>
<B> endif</B>
<B> echomsg strlen(substitute(@@, '[^ ]', '', 'g'))</B>
<B> let &selection = sel_save</B>
<B> let @@ = reg_save</B>
<B> endfunction</B>
Note that the <A HREF="options.html#'selection'">'selection'</A> option is temporarily set to "<A HREF="motion.html#inclusive">inclusive</A>" to be able
to <A HREF="change.html#yank">yank</A> exactly the right text by using <A HREF="visual.html#Visual">Visual</A> mode from the <A HREF="motion.html#'[">'[</A> to the <A HREF="motion.html#']">']</A>
<A HREF="motion.html#mark">mark</A>.
Also note that there is a separate <A HREF="#mapping">mapping</A> for <A HREF="visual.html#Visual">Visual</A> mode. It removes the
"'<,'>" range that "<A HREF="cmdline.html#:">:</A>" inserts in <A HREF="visual.html#Visual">Visual</A> mode and invokes the function with
<A HREF="eval.html#visualmode()">visualmode()</A> and an extra argument.
==============================================================================
2. <A HREF="#Abbreviations">Abbreviations</A> *<A NAME="abbreviations"></A><B>abbreviations</B>* *<A NAME="Abbreviations"></A><B>Abbreviations</B>*
<A HREF="#Abbreviations">Abbreviations</A> are used in <A HREF="insert.html#Insert">Insert</A> mode, <A HREF="insert.html#Replace">Replace</A> mode and <A HREF="cmdline.html#Command-line">Command-line</A> mode.
If you enter a <A HREF="motion.html#word">word</A> that is an abbreviation, <A HREF="motion.html#it">it</A> is replaced with the <A HREF="motion.html#word">word</A> <A HREF="motion.html#it">it</A>
stands for. This can be used to save typing for often used long words. And
you can use <A HREF="motion.html#it">it</A> to automatically correct obvious spelling <A HREF="message.html#errors">errors</A>.
Examples:
:iab ms Microsoft
:iab tihs this
There are three types of <A HREF="#abbreviations">abbreviations</A>:
full-id The "full-id" type consists entirely of keyword characters (letters
and characters from <A HREF="options.html#'iskeyword'">'iskeyword'</A> option). This is the most common
abbreviation.
Examples: "foo", "g3", "-1"
end-id The "end-id" type ends in a keyword character, but all the other
characters are not keyword characters.
Examples: "#i", "..f", "$/7"
non-id The "non-id" type ends in a non-keyword character, the other
characters may be of any type, excluding space and <A HREF="intro.html#tab">tab</A>. {this type
is not supported by Vi}
Examples: "def#", "4/7$"
Examples of strings that cannot be <A HREF="#abbreviations">abbreviations</A>: "a.b", "#def", "a b", "_$r"
An abbreviation is only recognized when you type a non-keyword character.
This can also be the <A HREF="intro.html#<Esc>"><Esc></A> that ends insert mode or the <A HREF="motion.html#<CR>"><CR></A> that ends a
command. The non-keyword character which ends the abbreviation is inserted
after the expanded abbreviation. An exception to this is the character <C-]>,
which is used to expand an abbreviation without <A HREF="insert.html#inserting">inserting</A> any extra
characters.
Example:
<B> :ab hh hello</B>
"hh<Space>" is expanded to "hello<Space>"
"hh<C-]>" is expanded to "hello"
The characters before the cursor must match the abbreviation. Each type has
an additional rule:
full-id In front of the match is a non-keyword character, or this is where
the line or insertion starts. Exception: When the abbreviation is
only one character, <A HREF="motion.html#it">it</A> is not recognized if there is a non-keyword
character in front of <A HREF="motion.html#it">it</A>, other than a space or a <A HREF="intro.html#tab">tab</A>.
end-id In front of the match is a keyword character, or a space or a <A HREF="intro.html#tab">tab</A>,
or this is where the line or insertion starts.
non-id In front of the match is a space, <A HREF="intro.html#tab">tab</A> or the start of the line or
the insertion.
Examples: ({CURSOR} is where you type a non-keyword character)
<B> :ab foo four old otters</B>
" foo{CURSOR}" is expanded to " four old otters"
" foobar{CURSOR}" is not expanded
"barfoo{CURSOR}" is not expanded
<B> :ab #i #include</B>
"#i{CURSOR}" is expanded to "#include"
">#i{CURSOR}" is not expanded
<B> :ab ;; <endofline></B>
"test;;" is not expanded
"test ;;" is expanded to "test <endofline>"
To avoid the abbreviation in <A HREF="insert.html#Insert">Insert</A> mode: Type <A HREF="visual.html#CTRL-V">CTRL-V</A> before the character
that would trigger the abbreviation. E.g. <A HREF="visual.html#CTRL-V">CTRL-V</A> <A HREF="motion.html#<Space>"><Space></A>. Or type part of
the abbreviation, exit insert mode with <A HREF="intro.html#<Esc>"><Esc></A>, re-enter insert mode with "<A HREF="insert.html#a">a</A>"
and type the rest.
To avoid the abbreviation in <A HREF="cmdline.html#Command-line">Command-line</A> mode: Type <A HREF="visual.html#CTRL-V">CTRL-V</A> <A HREF="if_cscop.html#twice">twice</A> somewhere in
the abbreviation to avoid <A HREF="motion.html#it">it</A> to be replaced. A <A HREF="visual.html#CTRL-V">CTRL-V</A> in front of a normal
character is mostly ignored otherwise.
It is possible to move the cursor after an abbreviation:
<B> :iab if if ()<Left></B>
This does not work if <A HREF="options.html#'cpoptions'">'cpoptions'</A> includes the '<' flag. |<A HREF="intro.html#<>"><></A>|
You can even <A HREF="diff.html#do">do</A> more complicated things. For example, to consume the space
typed after an abbreviation:
<B> func Eatchar(pat)</B>
<B> let c = nr2char(getchar(0))</B>
<B> return (c =~ a:pat) ? '' : c</B>
<B> endfunc</B>
<B> iabbr <silent> if if ()<Left><C-R>=Eatchar('\s')<CR></B>
There are no default <A HREF="#abbreviations">abbreviations</A>.
<A HREF="#Abbreviations">Abbreviations</A> are never recursive. You can use "<A HREF="#:ab">:ab</A> <A HREF="motion.html#f">f</A> f-o-o" without any
problem. But <A HREF="#abbreviations">abbreviations</A> can be mapped. {some versions of <A HREF="intro.html#Vi">Vi</A> support
recursive <A HREF="#abbreviations">abbreviations</A>, for no apparent reason}
<A HREF="#Abbreviations">Abbreviations</A> are disabled if the <A HREF="options.html#'paste'">'paste'</A> option is on.
*<A NAME=":abbreviate-local"></A><B>:abbreviate-local</B>* *<A NAME=":abbreviate-<buffer>"></A><B>:abbreviate-<buffer></B>*
Just like mappings, <A HREF="#abbreviations">abbreviations</A> can be local to a buffer. This is mostly
used in a |<A HREF="usr_43.html#filetype-plugin">filetype-plugin</A>| file. Example for a C plugin file:
<B> :abb <buffer> FF for (i = 0; i < ; ++i)</B>
*<A NAME=":ab"></A><B>:ab</B>* *<A NAME=":abbreviate"></A><B>:abbreviate</B>*
:ab[breviate] <A HREF="eval.html#list">list</A> all <A HREF="#abbreviations">abbreviations</A>. The character in the first
column indicates the mode where the abbreviation is
used: '<A HREF="insert.html#i">i</A>' for insert mode, '<A HREF="change.html#c">c</A>' for <A HREF="cmdline.html#Command-line">Command-line</A>
mode, '<A HREF="change.html#!">!</A>' for both. These are the same <A HREF="motion.html#as">as</A> for
mappings, see |<A HREF="#map-listing">map-listing</A>|.
*<A NAME=":abbreviate-verbose"></A><B>:abbreviate-verbose</B>*
When <A HREF="options.html#'verbose'">'verbose'</A> is non-zero, listing an abbreviation will also display where <A HREF="motion.html#it">it</A>
was last defined. Example:
<B> :verbose abbreviate</B>
<B> ! teh the</B>
<B> Last set from /home/abcd/vim/abbr.vim</B>
See |<A HREF="various.html#:verbose-cmd">:verbose-cmd</A>| for more information.
:ab[breviate] <A HREF="#{lhs}">{lhs}</A> <A HREF="eval.html#list">list</A> the <A HREF="#abbreviations">abbreviations</A> that start with <A HREF="#{lhs}">{lhs}</A>
You may need to insert a <A HREF="visual.html#CTRL-V">CTRL-V</A> (type <A HREF="motion.html#it">it</A> <A HREF="if_cscop.html#twice">twice</A>) to
avoid that a typed <A HREF="#{lhs}">{lhs}</A> is expanded, since
command-line <A HREF="#abbreviations">abbreviations</A> apply here.
:ab[breviate] [<expr>] [<buffer>] <A HREF="#{lhs}">{lhs}</A> <A HREF="#{rhs}">{rhs}</A>
add abbreviation for <A HREF="#{lhs}">{lhs}</A> to <A HREF="#{rhs}">{rhs}</A>. If <A HREF="#{lhs}">{lhs}</A> already
existed <A HREF="motion.html#it">it</A> is replaced with the new <A HREF="#{rhs}">{rhs}</A>. <A HREF="#{rhs}">{rhs}</A> may
contain spaces.
See |<A HREF="#:map-<expr>">:map-<expr></A>| for the optional <expr> argument.
See |<A HREF="#:map-<buffer>">:map-<buffer></A>| for the optional <buffer> argument.
*<A NAME=":una"></A><B>:una</B>* *<A NAME=":unabbreviate"></A><B>:unabbreviate</B>*
:una[bbreviate] <A HREF="#{lhs}">{lhs}</A> Remove abbreviation for <A HREF="#{lhs}">{lhs}</A> from the <A HREF="eval.html#list">list</A>. If none
is found, remove <A HREF="#abbreviations">abbreviations</A> in which <A HREF="#{lhs}">{lhs}</A> matches
with the <A HREF="#{rhs}">{rhs}</A>. This is done so that you can even
remove <A HREF="#abbreviations">abbreviations</A> after expansion. To avoid
expansion insert a <A HREF="visual.html#CTRL-V">CTRL-V</A> (type <A HREF="motion.html#it">it</A> <A HREF="if_cscop.html#twice">twice</A>).
*<A NAME=":norea"></A><B>:norea</B>* *<A NAME=":noreabbrev"></A><B>:noreabbrev</B>*
:norea[bbrev] [<expr>] [<buffer>] [lhs] [rhs]
same <A HREF="motion.html#as">as</A> "<A HREF="#:ab">:ab</A>", but no remapping for this <A HREF="#{rhs}">{rhs}</A> {not
in Vi}
*<A NAME=":ca"></A><B>:ca</B>* *<A NAME=":cabbrev"></A><B>:cabbrev</B>*
:ca[bbrev] [<expr>] [<buffer>] [lhs] [rhs]
same <A HREF="motion.html#as">as</A> "<A HREF="#:ab">:ab</A>", but for <A HREF="cmdline.html#Command-line">Command-line</A> mode only. {not
in Vi}
*<A NAME=":cuna"></A><B>:cuna</B>* *<A NAME=":cunabbrev"></A><B>:cunabbrev</B>*
:cuna[bbrev] <A HREF="#{lhs}">{lhs}</A> same <A HREF="motion.html#as">as</A> "<A HREF="#:una">:una</A>", but for <A HREF="cmdline.html#Command-line">Command-line</A> mode only. {not
in Vi}
*<A NAME=":cnorea"></A><B>:cnorea</B>* *<A NAME=":cnoreabbrev"></A><B>:cnoreabbrev</B>*
:cnorea[bbrev] [<expr>] [<buffer>] [lhs] [rhs]
same <A HREF="motion.html#as">as</A> "<A HREF="#:ab">:ab</A>", but for <A HREF="cmdline.html#Command-line">Command-line</A> mode only and no
remapping for this <A HREF="#{rhs}">{rhs}</A> {not in Vi}
*<A NAME=":ia"></A><B>:ia</B>* *<A NAME=":iabbrev"></A><B>:iabbrev</B>*
:ia[bbrev] [<expr>] [<buffer>] [lhs] [rhs]
same <A HREF="motion.html#as">as</A> "<A HREF="#:ab">:ab</A>", but for <A HREF="insert.html#Insert">Insert</A> mode only. {not in Vi}
*<A NAME=":iuna"></A><B>:iuna</B>* *<A NAME=":iunabbrev"></A><B>:iunabbrev</B>*
:iuna[bbrev] <A HREF="#{lhs}">{lhs}</A> same <A HREF="motion.html#as">as</A> "<A HREF="#:una">:una</A>", but for insert mode only. {not in
Vi}
*<A NAME=":inorea"></A><B>:inorea</B>* *<A NAME=":inoreabbrev"></A><B>:inoreabbrev</B>*
:inorea[bbrev] [<expr>] [<buffer>] [lhs] [rhs]
same <A HREF="motion.html#as">as</A> "<A HREF="#:ab">:ab</A>", but for <A HREF="insert.html#Insert">Insert</A> mode only and no
remapping for this <A HREF="#{rhs}">{rhs}</A> {not in Vi}
*<A NAME=":abc"></A><B>:abc</B>* *<A NAME=":abclear"></A><B>:abclear</B>*
:abc[lear] [<buffer>] Remove all <A HREF="#abbreviations">abbreviations</A>. {not in Vi}
*<A NAME=":iabc"></A><B>:iabc</B>* *<A NAME=":iabclear"></A><B>:iabclear</B>*
:iabc[lear] [<buffer>] Remove all <A HREF="#abbreviations">abbreviations</A> for <A HREF="insert.html#Insert">Insert</A> mode. {not in Vi}
*<A NAME=":cabc"></A><B>:cabc</B>* *<A NAME=":cabclear"></A><B>:cabclear</B>*
:cabc[lear] [<buffer>] Remove all <A HREF="#abbreviations">abbreviations</A> for <A HREF="cmdline.html#Command-line">Command-line</A> mode. {not
in Vi}
*<A NAME="using_CTRL-V"></A><B>using_CTRL-V</B>*
It is possible to use special characters in the rhs of an abbreviation.
<A HREF="visual.html#CTRL-V">CTRL-V</A> has to be used to avoid the special meaning of most non printable
characters. How many CTRL-Vs need to be typed depends on how you enter the
abbreviation. This also applies to mappings. Let's use an example here.
Suppose you want to abbreviate "esc" to enter an <A HREF="intro.html#<Esc>"><Esc></A> character. When you
type the "<A HREF="#:ab">:ab</A>" command in Vim, you have to enter this: (here ^V is a <A HREF="visual.html#CTRL-V">CTRL-V</A>
and ^[ is <A HREF="intro.html#<Esc>"><Esc></A>)
You type: <A HREF="motion.html#ab">ab</A> esc ^V^V^V^V^V^[
All keyboard input is subjected to ^V <A HREF="change.html#quote">quote</A> interpretation, so
the first, third, and fifth ^V characters simply allow the second,
and fourth ^Vs, and the ^[, to be entered into the command-line.
You see: <A HREF="motion.html#ab">ab</A> esc ^V^V^[
The command-line contains two actual ^Vs before the ^[. This is
how <A HREF="motion.html#it">it</A> should appear in your <A HREF="starting.html#.exrc">.exrc</A> file, if you choose to go that
route. The first ^V is there to <A HREF="change.html#quote">quote</A> the second ^V; the <A HREF="#:ab">:ab</A>
command uses ^V <A HREF="motion.html#as">as</A> its own <A HREF="change.html#quote">quote</A> character, so you can include quoted
<A HREF="pattern.html#whitespace">whitespace</A> or the | character in the abbreviation. The <A HREF="#:ab">:ab</A> command
doesn't <A HREF="diff.html#do">do</A> anything special with the ^[ character, so <A HREF="motion.html#it">it</A> doesn't need
to be quoted. (Although quoting isn't harmful; that's why typing 7
[but not 8!] ^Vs works.)
Stored <A HREF="motion.html#as">as</A>: esc ^V^[
After parsing, the abbreviation's short form ("esc") and long form
(the two characters "^V^[") are stored in the abbreviation table.
If you give the <A HREF="#:ab">:ab</A> command with no arguments, this is how the
abbreviation will be displayed.
Later, when the abbreviation is expanded because the user typed in
the <A HREF="motion.html#word">word</A> "esc", the long form is subjected to the same type of
^V interpretation <A HREF="motion.html#as">as</A> keyboard input. So the ^V protects the ^[
character from being interpreted <A HREF="motion.html#as">as</A> the "exit <A HREF="insert.html#Insert">Insert</A> mode" character.
Instead, the ^[ is inserted into the text.
Expands to: ^[
[example given by Steve Kirkendall]
==============================================================================
3. Local mappings and <A HREF="eval.html#functions">functions</A> *<A NAME="script-local"></A><B>script-local</B>*
When using several Vim <A HREF="usr_41.html#script">script</A> files, there is the danger that mappings and
<A HREF="eval.html#functions">functions</A> used in one <A HREF="usr_41.html#script">script</A> use the same name <A HREF="motion.html#as">as</A> in other scripts. To avoid
this, they can be made local to the <A HREF="usr_41.html#script">script</A>.
*<A NAME="<SID>"></A><B><SID></B>* *<A NAME="<SNR>"></A><B><SNR></B>* *<A NAME="E81"></A><B>E81</B>*
The <A HREF="eval.html#string">string</A> "<A HREF="#<SID>"><SID></A>" can be used in a <A HREF="#mapping">mapping</A> or menu. This requires that the
'<A HREF="change.html#<"><</A>' flag is not present in <A HREF="options.html#'cpoptions'">'cpoptions'</A>.
When executing the map command, Vim will replace "<A HREF="#<SID>"><SID></A>" with the special
key code <A HREF="#<SNR>"><SNR></A>, followed by a number that's unique for the <A HREF="usr_41.html#script">script</A>, and an
underscore. Example:
<B> :map <SID>Add</B>
could define a <A HREF="#mapping">mapping</A> "<SNR>23_Add".
When defining a function in a <A HREF="usr_41.html#script">script</A>, "s:" can be prepended to the name to
make <A HREF="motion.html#it">it</A> local to the <A HREF="usr_41.html#script">script</A>. But when a <A HREF="#mapping">mapping</A> is executed from outside of
the <A HREF="usr_41.html#script">script</A>, <A HREF="motion.html#it">it</A> doesn't know in which <A HREF="usr_41.html#script">script</A> the function was defined. To
avoid this problem, use "<A HREF="#<SID>"><SID></A>" instead of "s:". The same translation is done
<A HREF="motion.html#as">as</A> for mappings. This makes <A HREF="motion.html#it">it</A> possible to define a call to the function in
a <A HREF="#mapping">mapping</A>.
When a local function is executed, <A HREF="motion.html#it">it</A> runs in the context of the <A HREF="usr_41.html#script">script</A> <A HREF="motion.html#it">it</A> was
defined in. This means that new <A HREF="eval.html#functions">functions</A> and mappings <A HREF="motion.html#it">it</A> defines can also
use "s:" or "<A HREF="#<SID>"><SID></A>" and <A HREF="motion.html#it">it</A> will use the same unique number <A HREF="motion.html#as">as</A> when the
function itself was defined. Also, the "<A HREF="eval.html#s:var">s:var</A>" local <A HREF="usr_41.html#script">script</A> <A HREF="eval.html#variables">variables</A> can be
used.
When executing an <A HREF="autocmd.html#autocommand">autocommand</A> or a user command, <A HREF="motion.html#it">it</A> will run in the context of
the <A HREF="usr_41.html#script">script</A> <A HREF="motion.html#it">it</A> was defined in. This makes <A HREF="motion.html#it">it</A> possible that the command calls a
local function or uses a local <A HREF="#mapping">mapping</A>.
Otherwise, using "<A HREF="#<SID>"><SID></A>" outside of a <A HREF="usr_41.html#script">script</A> context is an error.
If you need to get the <A HREF="usr_41.html#script">script</A> number to use in a complicated <A HREF="usr_41.html#script">script</A>, you can
use this function:
<B> function s:SID()</B>
<B> return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')</B>
<B> endfun</B>
The "<A HREF="#<SNR>"><SNR></A>" will be shown when listing <A HREF="eval.html#functions">functions</A> and mappings. This is useful
to find out what they are defined to.
The |<A HREF="repeat.html#:scriptnames">:scriptnames</A>| command can be used to see which scripts have been sourced
and what their <A HREF="#<SNR>"><SNR></A> number is.
This is all {not in Vi} and {not available when compiled without the |<A HREF="various.html#+eval">+eval</A>|
feature}.
==============================================================================
4. User-defined commands *<A NAME="user-commands"></A><B>user-commands</B>*
It is possible to define your own <A HREF="intro.html#Ex">Ex</A> commands. A user-defined command can act
just like a built-in command (it can have a range or arguments, arguments can
be completed <A HREF="motion.html#as">as</A> filenames or buffer names, etc), except that when the command
is executed, <A HREF="motion.html#it">it</A> is transformed into a normal <A HREF="intro.html#Ex">Ex</A> command and then executed.
For starters: See section |<A HREF="usr_40.html#40.2">40.2</A>| in the user manual.
*<A NAME="E183"></A><B>E183</B>* *<A NAME="E841"></A><B>E841</B>* *<A NAME="user-cmd-ambiguous"></A><B>user-cmd-ambiguous</B>*
All user defined commands must start with an <A HREF="change.html#uppercase">uppercase</A> <A HREF="print.html#letter">letter</A>, to avoid
confusion with builtin commands. Exceptions are these builtin commands:
<A HREF="editing.html#:Next">:Next</A>
<A HREF="editing.html#:X">:X</A>
They cannot be used for a user defined command. "<A HREF="various.html#:Print">:Print</A>" is also an existing
command, but <A HREF="motion.html#it">it</A> is deprecated and can be overruled.
The other characters of the user command can be <A HREF="change.html#uppercase">uppercase</A> letters, <A HREF="change.html#lowercase">lowercase</A>
letters or digits. When using digits, note that other commands that take a
numeric argument may become ambiguous. For example, the command ":Cc2" could
be the user command ":Cc2" without an argument, or the command ":Cc" with
argument "2". It is advised to put a space between the command name and the
argument to avoid these problems.
When using a user-defined command, the command can be abbreviated. However, if
an abbreviation is not unique, an error will be issued. Furthermore, a
built-in command will always take precedence.
Example:
<B> :command Rename ...</B>
<B> :command Renumber ...</B>
<B> :Rena " Means "Rename"</B>
<B> :Renu " Means "Renumber"</B>
<B> :Ren " Error - ambiguous</B>
<B> :command Paste ...</B>
<B> :P " The built-in :Print</B>
It is recommended that full names for user-defined commands are used in
scripts.
:com[mand] *<A NAME=":com"></A><B>:com</B>* *<A NAME=":command"></A><B>:command</B>*
<A HREF="eval.html#List">List</A> all user-defined commands. When listing commands,
the characters in the first two columns are
! Command has the -bang attribute
" Command has the <A HREF="if_ole.html#-register">-register</A> attribute
<A HREF="motion.html#b">b</A> Command is local to current buffer
(see below for details on attributes)
The <A HREF="eval.html#list">list</A> can be filtered on command name with
|<A HREF="various.html#:filter">:filter</A>|, e.g., to <A HREF="eval.html#list">list</A> all commands with "Pyth" in
the name:
<B> filter Pyth command</B>
:com[mand] {cmd} <A HREF="eval.html#List">List</A> the user-defined commands that start with {cmd}
*<A NAME=":command-verbose"></A><B>:command-verbose</B>*
When <A HREF="options.html#'verbose'">'verbose'</A> is non-zero, listing a command will also display where <A HREF="motion.html#it">it</A> was
last defined. Example:
<B> :verbose command TOhtml</B>
<B><FONT COLOR="PURPLE"> Name Args Range Complete Definition </FONT></B>
<B><FONT COLOR="PURPLE"> TOhtml 0 % :call Convert2HTML(<line1>, <line2>) </FONT></B>
<B><FONT COLOR="PURPLE"> Last set from /usr/share/vim/vim-7.0/plugin/tohtml.vim </FONT></B>
See |<A HREF="various.html#:verbose-cmd">:verbose-cmd</A>| for more information.
*<A NAME="E174"></A><B>E174</B>* *<A NAME="E182"></A><B>E182</B>*
:com[mand][!] [{attr}...] {cmd} {rep}
Define a user command. The name of the command is
{cmd} and its replacement text is {rep}. The command's
attributes (see below) are {attr}. If the command
already exists, an error is reported, unless a ! is
specified, in which <A HREF="change.html#case">case</A> the command is redefined.
:delc[ommand] {cmd} *<A NAME=":delc"></A><B>:delc</B>* *<A NAME=":delcommand"></A><B>:delcommand</B>* *<A NAME="E184"></A><B>E184</B>*
Delete the user-defined command {cmd}.
:comc[lear] *<A NAME=":comc"></A><B>:comc</B>* *<A NAME=":comclear"></A><B>:comclear</B>*
Delete all user-defined commands.
Command attributes
User-defined commands are treated by Vim just like any other <A HREF="intro.html#Ex">Ex</A> commands. They
can have arguments, or have a range specified. Arguments are subject to
completion <A HREF="motion.html#as">as</A> filenames, <A HREF="windows.html#buffers">buffers</A>, etc. Exactly how this works depends upon the
command's attributes, which are specified when the command is defined.
There are a number of attributes, split into four categories: argument
handling, completion behavior, range handling, and special cases. The
attributes are described below, by category.
Argument handling *<A NAME="E175"></A><B>E175</B>* *<A NAME="E176"></A><B>E176</B>* *<A NAME=":command-nargs"></A><B>:command-nargs</B>*
By default, a user defined command will take no arguments (and an error is
reported if any are supplied). However, <A HREF="motion.html#it">it</A> is possible to specify that the
command can take arguments, using the -nargs attribute. Valid cases are:
-nargs=0 No arguments are allowed (the default)
-nargs=1 Exactly one argument is required, <A HREF="motion.html#it">it</A> includes spaces
-nargs=* Any number of arguments are allowed (0, 1, or many),
separated by white space
-nargs=? 0 or 1 arguments are allowed
-nargs=+ Arguments must be supplied, but any number are allowed
Arguments are considered to be separated by (unescaped) spaces or tabs in this
context, except when there is one argument, then the white space is part of
the argument.
Note that arguments are used <A HREF="motion.html#as">as</A> text, not <A HREF="motion.html#as">as</A> expressions. Specifically,
"<A HREF="eval.html#s:var">s:var</A>" will use the <A HREF="#script-local">script-local</A> variable in the <A HREF="usr_41.html#script">script</A> where the command was
defined, not where <A HREF="motion.html#it">it</A> is invoked! Example:
script1.vim:
<B> :let s:error = "None"</B>
<B> :command -nargs=1 Error echoerr <args></B>
script2.vim:
<B> :source script1.vim</B>
<B> :let s:error = "Wrong!"</B>
<B> :Error s:error</B>
Executing script2.vim will result in "None" being echoed. Not what you
intended! Calling a function may be an alternative.
Completion behavior *<A NAME=":command-completion"></A><B>:command-completion</B>* *<A NAME="E179"></A><B>E179</B>*
*<A NAME="E180"></A><B>E180</B>* *<A NAME="E181"></A><B>E181</B>* *<A NAME=":command-complete"></A><B>:command-complete</B>*
By default, the arguments of user defined commands <A HREF="diff.html#do">do</A> not undergo completion.
However, by specifying one or the other of the following attributes, argument
completion can be enabled:
-complete=augroup autocmd groups
-complete=buffer buffer names
-complete=behave <A HREF="gui.html#:behave">:behave</A> suboptions
-complete=color color schemes
-complete=command <A HREF="intro.html#Ex">Ex</A> command (and arguments)
-complete=compiler compilers
-complete=cscope |<A HREF="if_cscop.html#:cscope">:cscope</A>| suboptions
-complete=dir directory names
-complete=environment environment variable names
-complete=event <A HREF="autocmd.html#autocommand">autocommand</A> events
-complete=expression Vim <A HREF="eval.html#expression">expression</A>
-complete=file file and directory names
-complete=file_in_path file and directory names in |<A HREF="options.html#'path'">'path'</A>|
-complete=filetype filetype names |<A HREF="options.html#'filetype'">'filetype'</A>|
-complete=function function name
-complete=help help subjects
-complete=highlight highlight groups
-complete=history <A HREF="cmdline.html#:history">:history</A> suboptions
-complete=locale <A HREF="mbyte.html#locale">locale</A> names (as output of <A HREF="mbyte.html#locale">locale</A> -a)
-complete=mapclear buffer argument
-complete=mapping <A HREF="#mapping">mapping</A> name
-complete=menu <A HREF="gui.html#menus">menus</A>
-complete=messages |<A HREF="message.html#:messages">:messages</A>| suboptions
-complete=option <A HREF="options.html#options">options</A>
-complete=packadd optional package |<A HREF="repeat.html#pack-add">pack-add</A>| names
-complete=shellcmd Shell command
-complete=sign |<A HREF="sign.html#:sign">:sign</A>| suboptions
-complete=syntax syntax file names |<A HREF="options.html#'syntax'">'syntax'</A>|
-complete=syntime |<A HREF="syntax.html#:syntime">:syntime</A>| suboptions
-complete=tag <A HREF="tagsrch.html#tags">tags</A>
-complete=tag_listfiles <A HREF="tagsrch.html#tags">tags</A>, file names are shown when <A HREF="scroll.html#CTRL-D">CTRL-D</A> is hit
-complete=user user names
-complete=var user <A HREF="eval.html#variables">variables</A>
-complete=custom,{func} custom completion, defined via {func}
-complete=customlist,{func} custom completion, defined via {func}
Note: That some completion methods might expand environment <A HREF="eval.html#variables">variables</A>.
Custom completion *<A NAME=":command-completion-custom"></A><B>:command-completion-custom</B>*
*<A NAME=":command-completion-customlist"></A><B>:command-completion-customlist</B>*
*<A NAME="E467"></A><B>E467</B>* *<A NAME="E468"></A><B>E468</B>*
It is possible to define customized completion schemes via the "custom,{func}"
or the "customlist,{func}" completion argument. The {func} part should be a
function with the following signature:
<B> :function {func}(ArgLead, CmdLine, CursorPos)</B>
The function need not use all these arguments. The function should provide the
completion candidates <A HREF="motion.html#as">as</A> the return value.
For the "custom" argument, the function should return the completion
candidates one per line in a newline separated <A HREF="eval.html#string">string</A>.
For the "customlist" argument, the function should return the completion
candidates <A HREF="motion.html#as">as</A> a Vim <A HREF="eval.html#List">List</A>. Non-string items in the <A HREF="eval.html#list">list</A> are ignored.
The function arguments are:
ArgLead the leading portion of the argument currently being
completed on
CmdLine the entire command line
CursorPos the cursor position in <A HREF="motion.html#it">it</A> (byte index)
The function may use these for determining context. For the "custom"
argument, <A HREF="motion.html#it">it</A> is not necessary to <A HREF="change.html#filter">filter</A> candidates against the (implicit
<A HREF="pattern.html#pattern">pattern</A> in) ArgLead. Vim will <A HREF="change.html#filter">filter</A> the candidates with its <A HREF="pattern.html#regexp">regexp</A> engine
after function return, and this is probably more efficient in most cases. For
the "customlist" argument, Vim will not <A HREF="change.html#filter">filter</A> the returned completion
candidates and the user supplied function should <A HREF="change.html#filter">filter</A> the candidates.
The following example lists user names to a Finger command
<B> :com -complete=custom,ListUsers -nargs=1 Finger !finger <args></B>
<B> :fun ListUsers(A,L,P)</B>
<B> : return system("cut -d: -f1 /etc/passwd")</B>
<B> :endfun</B>
The following example completes filenames from the directories specified in
the <A HREF="options.html#'path'">'path'</A> option:
<B> :com -nargs=1 -bang -complete=customlist,EditFileComplete</B>
<B> \ EditFile edit<bang> <args></B>
<B> :fun EditFileComplete(A,L,P)</B>
<B> : return split(globpath(&path, a:A), "\n")</B>
<B> :endfun</B>
This example does not work for file names with spaces!
Range handling *<A NAME="E177"></A><B>E177</B>* *<A NAME="E178"></A><B>E178</B>* *<A NAME=":command-range"></A><B>:command-range</B>*
*<A NAME=":command-count"></A><B>:command-count</B>*
By default, user-defined commands <A HREF="diff.html#do">do</A> not accept a line number range. However,
<A HREF="motion.html#it">it</A> is possible to specify that the command does take a range (the -range
attribute), or that <A HREF="motion.html#it">it</A> takes an arbitrary <A HREF="intro.html#count">count</A> value, either in the line
number position (-range=N, like the |<A HREF="windows.html#:split">:split</A>| command) or <A HREF="motion.html#as">as</A> a "<A HREF="intro.html#count">count</A>"
argument (-count=N, like the |<A HREF="editing.html#:Next">:Next</A>| command). The <A HREF="intro.html#count">count</A> will then be
available in the argument with |<A HREF="#<count>"><count></A>|.
Possible attributes are:
-range Range allowed, default is current line
-range=% Range allowed, default is whole file (1,$)
-range=N A <A HREF="intro.html#count">count</A> (default N) which is specified in the line
number position (like |<A HREF="windows.html#:split">:split</A>|); allows for zero line
number.
-count=N A <A HREF="intro.html#count">count</A> (default N) which is specified either in the line
number position, or <A HREF="motion.html#as">as</A> an initial argument (like |<A HREF="editing.html#:Next">:Next</A>|).
Specifying -count (without a default) acts like -count=0
Note that -range=N and -count=N are mutually <A HREF="motion.html#exclusive">exclusive</A> - only one should be
specified.
*<A NAME=":command-addr"></A><B>:command-addr</B>*
It is possible that the special characters in the range like ., $ or <A HREF="motion.html#%">%</A> which
by default correspond to the current line, last line and the whole buffer,
relate to arguments, (loaded) <A HREF="windows.html#buffers">buffers</A>, <A HREF="windows.html#windows">windows</A> or <A HREF="intro.html#tab">tab</A> pages.
Possible values are:
-addr=lines Range of lines (this is the default)
-addr=arguments Range for arguments
-addr=buffers Range for <A HREF="windows.html#buffers">buffers</A> (also not loaded <A HREF="windows.html#buffers">buffers</A>)
-addr=loaded_buffers Range for loaded <A HREF="windows.html#buffers">buffers</A>
-addr=windows Range for <A HREF="windows.html#windows">windows</A>
-addr=tabs Range for <A HREF="intro.html#tab">tab</A> pages
<A HREF="eval.html#Special">Special</A> cases *<A NAME=":command-bang"></A><B>:command-bang</B>* *<A NAME=":command-bar"></A><B>:command-bar</B>*
*<A NAME=":command-register"></A><B>:command-register</B>* *<A NAME=":command-buffer"></A><B>:command-buffer</B>*
There are some special cases <A HREF="motion.html#as">as</A> well:
-bang The command can take a ! modifier (like <A HREF="editing.html#:q">:q</A> or <A HREF="editing.html#:w">:w</A>)
-bar The command can be followed by a "|" and another command.
A "|" inside the command argument is not allowed then.
Also checks for a " to start a comment.
<A HREF="if_ole.html#-register">-register</A> The first argument to the command can be an optional
<A HREF="sponsor.html#register">register</A> name (like <A HREF="change.html#:del">:del</A>, <A HREF="change.html#:put">:put</A>, <A HREF="change.html#:yank">:yank</A>).
-buffer The command will only be available in the current buffer.
In the cases of the -count and <A HREF="if_ole.html#-register">-register</A> attributes, if the optional argument
is supplied, <A HREF="motion.html#it">it</A> is removed from the argument <A HREF="eval.html#list">list</A> and is available to the
replacement text separately.
Note that these arguments can be abbreviated, but that is a deprecated
feature. Use the full name for new scripts.
Replacement text
The replacement text for a user defined command is scanned for special <A HREF="intro.html#escape">escape</A>
sequences, using <...> <A HREF="intro.html#notation">notation</A>. Escape sequences are replaced with values
from the entered command line, and all other text is copied unchanged. The
resulting <A HREF="eval.html#string">string</A> is executed <A HREF="motion.html#as">as</A> an <A HREF="intro.html#Ex">Ex</A> command. To avoid the replacement use
<A HREF="intro.html#<lt>"><lt></A> in place of the initial <A HREF="change.html#<"><</A>. Thus to include "<A HREF="#<bang>"><bang></A>" literally use
"<lt>bang>".
The valid <A HREF="intro.html#escape">escape</A> sequences are
*<A NAME="<line1>"></A><B><line1></B>*
<A HREF="#<line1>"><line1></A> The starting line of the command range.
*<A NAME="<line2>"></A><B><line2></B>*
<A HREF="#<line2>"><line2></A> The final line of the command range.
*<A NAME="<range>"></A><B><range></B>*
<A HREF="#<range>"><range></A> The number of items in the command range: 0, 1 or 2
*<A NAME="<count>"></A><B><count></B>*
<A HREF="#<count>"><count></A> Any <A HREF="intro.html#count">count</A> supplied (as described for the '-range'
and '-count' attributes).
*<A NAME="<bang>"></A><B><bang></B>*
<A HREF="#<bang>"><bang></A> (See the '-bang' attribute) Expands to a ! if the
command was executed with a ! modifier, otherwise
expands to nothing.
*<A NAME="<mods>"></A><B><mods></B>*
<A HREF="#<mods>"><mods></A> The command modifiers, if specified. Otherwise, expands to
nothing. Supported modifiers are |<A HREF="windows.html#:aboveleft">:aboveleft</A>|, |<A HREF="windows.html#:belowright">:belowright</A>|,
|<A HREF="windows.html#:botright">:botright</A>|, |<A HREF="editing.html#:browse">:browse</A>|, |<A HREF="editing.html#:confirm">:confirm</A>|, |<A HREF="windows.html#:hide">:hide</A>|, |<A HREF="editing.html#:keepalt">:keepalt</A>|,
|<A HREF="motion.html#:keepjumps">:keepjumps</A>|, |<A HREF="motion.html#:keepmarks">:keepmarks</A>|, |<A HREF="cmdline.html#:keeppatterns">:keeppatterns</A>|, |<A HREF="windows.html#:leftabove">:leftabove</A>|,
|<A HREF="motion.html#:lockmarks">:lockmarks</A>|, |<A HREF="recover.html#:noswapfile">:noswapfile</A>| |<A HREF="windows.html#:rightbelow">:rightbelow</A>|, |<A HREF="various.html#:silent">:silent</A>|, |<A HREF="tabpage.html#:tab">:tab</A>|,
|<A HREF="windows.html#:topleft">:topleft</A>|, |<A HREF="various.html#:verbose">:verbose</A>|, and |<A HREF="windows.html#:vertical">:vertical</A>|.
Note that these are not yet supported: |<A HREF="autocmd.html#:noautocmd">:noautocmd</A>|,
|<A HREF="eval.html#:sandbox">:sandbox</A>| and |<A HREF="various.html#:unsilent">:unsilent</A>|.
Examples:
<B> command! -nargs=+ -complete=file MyEdit</B>
<B> \ for f in expand(<q-args>, 0, 1) |</B>
<B> \ exe '<mods> split ' . f |</B>
<B> \ endfor</B>
<B> function! SpecialEdit(files, mods)</B>
<B> for f in expand(a:files, 0, 1)</B>
<B> exe a:mods . ' split ' . f</B>
<B> endfor</B>
<B> endfunction</B>
<B> command! -nargs=+ -complete=file Sedit</B>
<B> \ call SpecialEdit(<q-args>, <q-mods>)</B>
*<A NAME="<reg>"></A><B><reg></B>* *<A NAME="<register>"></A><B><register></B>*
<A HREF="#<reg>"><reg></A> (See the '<A HREF="if_ole.html#-register">-register</A>' attribute) The optional <A HREF="sponsor.html#register">register</A>,
if specified. Otherwise, expands to nothing. <A HREF="#<register>"><register></A>
is a synonym for this.
*<A NAME="<args>"></A><B><args></B>*
<A HREF="#<args>"><args></A> The command arguments, exactly <A HREF="motion.html#as">as</A> supplied (but <A HREF="motion.html#as">as</A>
noted above, any <A HREF="intro.html#count">count</A> or <A HREF="sponsor.html#register">register</A> can consume some
of the arguments, which are then not part of <A HREF="#<args>"><args></A>).
<A HREF="intro.html#<lt>"><lt></A> A single '<A HREF="change.html#<"><</A>' (Less-Than) character. This is needed if you
want to get a literal copy of one of these <A HREF="intro.html#escape">escape</A> sequences
into the expansion - for example, to get <A HREF="#<bang>"><bang></A>, use
<lt>bang>.
*<A NAME="<q-args>"></A><B><q-args></B>*
If the first two characters of an <A HREF="intro.html#escape">escape</A> sequence are "q-" (for example,
<A HREF="#<q-args>"><q-args></A>) then the value is quoted in such a way <A HREF="motion.html#as">as</A> to make <A HREF="motion.html#it">it</A> a valid value
for use in an <A HREF="eval.html#expression">expression</A>. This uses the argument <A HREF="motion.html#as">as</A> one single value.
When there is no argument <A HREF="#<q-args>"><q-args></A> is an empty <A HREF="eval.html#string">string</A>.
*<A NAME="<f-args>"></A><B><f-args></B>*
To allow commands to pass their arguments on to a user-defined function, there
is a special form <A HREF="#<f-args>"><f-args></A> ("function args"). This splits the command
arguments at spaces and tabs, <A HREF="quotes.html#quotes">quotes</A> each argument individually, and the
<A HREF="#<f-args>"><f-args></A> sequence is replaced by the comma-separated <A HREF="eval.html#list">list</A> of quoted arguments.
See the Mycmd example below. If no arguments are given <A HREF="#<f-args>"><f-args></A> is removed.
To embed <A HREF="pattern.html#whitespace">whitespace</A> into an argument of <A HREF="#<f-args>"><f-args></A>, prepend a <A HREF="intro.html#backslash">backslash</A>.
<A HREF="#<f-args>"><f-args></A> replaces every pair of backslashes (\\) with one <A HREF="intro.html#backslash">backslash</A>. A
<A HREF="intro.html#backslash">backslash</A> followed by a character other than white space or a <A HREF="intro.html#backslash">backslash</A>
remains unmodified. Overview:
<B><FONT COLOR="PURPLE"> command <f-args> </FONT></B>
XX <A HREF="motion.html#ab">ab</A> '<A HREF="motion.html#ab">ab</A>'
XX a\b 'a\b'
XX a\ <A HREF="motion.html#b">b</A> <A HREF="motion.html#'a">'a</A> b'
XX a\ <A HREF="motion.html#b">b</A> <A HREF="motion.html#'a">'a</A> '', '<A HREF="motion.html#b">b</A>'
XX a\\b 'a\b'
XX a\\ <A HREF="motion.html#b">b</A> 'a\', '<A HREF="motion.html#b">b</A>'
XX a\\\b 'a\\b'
XX a\\\ <A HREF="motion.html#b">b</A> 'a\ b'
XX a\\\\b 'a\\b'
XX a\\\\ <A HREF="motion.html#b">b</A> 'a\\', '<A HREF="motion.html#b">b</A>'
Examples
<B> " Delete everything after here to the end</B>
<B> :com Ddel +,$d</B>
<B> " Rename the current buffer</B>
<B> :com -nargs=1 -bang -complete=file Ren f <args>|w<bang></B>
<B> " Replace a range with the contents of a file</B>
<B> " (Enter this all as one line)</B>
<B> :com -range -nargs=1 -complete=file</B>
<B> Replace <line1>-pu_|<line1>,<line2>d|r <args>|<line1>d</B>
<B> " Count the number of lines in the range</B>
<B> :com! -range -nargs=0 Lines echo <line2> - <line1> + 1 "lines"</B>
<B> " Call a user function (example of <f-args>)</B>
<B> :com -nargs=* Mycmd call Myfunc(<f-args>)</B>
When executed <A HREF="motion.html#as">as</A>:
<B> :Mycmd arg1 arg2</B>
This will invoke:
<B> :call Myfunc("arg1","arg2")</B>
<B> :" A more substantial example</B>
<B> :function Allargs(command)</B>
<B> : let i = 0</B>
<B> : while i < argc()</B>
<B> : if filereadable(argv(i))</B>
<B> : execute "e " . argv(i)</B>
<B> : execute a:command</B>
<B> : endif</B>
<B> : let i = i + 1</B>
<B> : endwhile</B>
<B> :endfunction</B>
<B> :command -nargs=+ -complete=command Allargs call Allargs(<q-args>)</B>
The command Allargs takes any Vim command(s) <A HREF="motion.html#as">as</A> argument and executes <A HREF="motion.html#it">it</A> on all
files in the argument <A HREF="eval.html#list">list</A>. Usage example (note use of the "<A HREF="motion.html#e">e</A>" flag to ignore
<A HREF="message.html#errors">errors</A> and the "update" command to write modified buffers):
<B> :Allargs %s/foo/bar/ge|update</B>
This will invoke:
<B> :call Allargs("%s/foo/bar/ge|update")</B>
When defining a user command in a <A HREF="usr_41.html#script">script</A>, <A HREF="motion.html#it">it</A> will be able to call <A HREF="eval.html#functions">functions</A>
local to the <A HREF="usr_41.html#script">script</A> and use mappings local to the <A HREF="usr_41.html#script">script</A>. When the user
invokes the user command, <A HREF="motion.html#it">it</A> will run in the context of the <A HREF="usr_41.html#script">script</A> <A HREF="motion.html#it">it</A> was
defined in. This matters if |<A HREF="#<SID>"><SID></A>| is used in a command.
<A HREF="#top">top</A> - <A HREF="index.html">main help file</A>
</PRE>
</BODY>
</HTML>
|