/usr/share/doc/vim/html/autocmd.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 | <HTML>
<HEAD>
<META HTTP-EQUIV="Content-type" content="text/html; charset=ISO-8859-1">
<TITLE>Vim documentation: autocmd</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>Vim documentation: autocmd</H1>
<A NAME="top"></A>
<A HREF="index.html">main help file</A>
<HR>
<PRE>
*<A NAME="autocmd.txt"></A><B>autocmd.txt</B>* For Vim version 8.0. Last change: 2018 Jan 31
VIM REFERENCE MANUAL by <A HREF="intro.html#Bram">Bram</A> <A HREF="intro.html#Moolenaar">Moolenaar</A>
Automatic commands *<A NAME="autocommand"></A><B>autocommand</B>*
For a basic explanation, see section |<A HREF="usr_40.html#40.3">40.3</A>| in the user manual.
1. Introduction |<A HREF="#autocmd-intro">autocmd-intro</A>|
2. Defining autocommands |<A HREF="#autocmd-define">autocmd-define</A>|
3. Removing autocommands |<A HREF="#autocmd-remove">autocmd-remove</A>|
4. Listing autocommands |<A HREF="#autocmd-list">autocmd-list</A>|
5. Events |<A HREF="#autocmd-events">autocmd-events</A>|
6. Patterns |<A HREF="#autocmd-patterns">autocmd-patterns</A>|
7. Buffer-local autocommands |<A HREF="#autocmd-buflocal">autocmd-buflocal</A>|
8. Groups |<A HREF="#autocmd-groups">autocmd-groups</A>|
9. Executing autocommands |<A HREF="#autocmd-execute">autocmd-execute</A>|
10. Using autocommands |<A HREF="#autocmd-use">autocmd-use</A>|
11. Disabling autocommands |<A HREF="#autocmd-disable">autocmd-disable</A>|
{Vi does not have any of these commands}
{only when the |<A HREF="various.html#+autocmd">+autocmd</A>| feature has not been disabled at compile time}
==============================================================================
1. Introduction *<A NAME="autocmd-intro"></A><B>autocmd-intro</B>*
You can specify commands to be executed automatically when reading or <A HREF="editing.html#writing">writing</A>
a file, when entering or leaving a buffer or <A HREF="windows.html#window">window</A>, and when <A HREF="starting.html#exiting">exiting</A> Vim.
For example, you can create an <A HREF="#autocommand">autocommand</A> to set the <A HREF="options.html#'cindent'">'cindent'</A> option for
files matching *.c. You can also use autocommands to implement advanced
features, such <A HREF="motion.html#as">as</A> editing compressed files (see |<A HREF="#gzip-example">gzip-example</A>|). The usual
place to put autocommands is in your <A HREF="starting.html#.vimrc">.vimrc</A> or <A HREF="starting.html#.exrc">.exrc</A> file.
*<A NAME="E203"></A><B>E203</B>* *<A NAME="E204"></A><B>E204</B>* *<A NAME="E143"></A><B>E143</B>* *<A NAME="E855"></A><B>E855</B>* *<A NAME="E937"></A><B>E937</B>*
WARNING: Using autocommands is very powerful, and may lead to unexpected side
effects. Be careful not to destroy your text.
- It's a good idea to <A HREF="diff.html#do">do</A> some <A HREF="eval.html#testing">testing</A> on an expendable copy of a file first.
For example: If you use autocommands to decompress a file when starting to
edit <A HREF="motion.html#it">it</A>, make sure that the autocommands for compressing when <A HREF="editing.html#writing">writing</A> work
correctly.
- Be prepared for an error halfway through (e.g., disk full). Vim will mostly
be able to <A HREF="undo.html#undo">undo</A> the changes to the buffer, but you may have to clean up the
changes to other files by hand (e.g., <A HREF="pi_gzip.html#compress">compress</A> a file that has been
decompressed).
- If the BufRead* events allow you to edit a compressed file, the FileRead*
events should <A HREF="diff.html#do">do</A> the same (this makes <A HREF="recover.html#recovery">recovery</A> possible in some rare cases).
It's a good idea to use the same autocommands for the File* and Buf* events
when possible.
==============================================================================
2. Defining autocommands *<A NAME="autocmd-define"></A><B>autocmd-define</B>*
*<A NAME=":au"></A><B>:au</B>* *<A NAME=":autocmd"></A><B>:autocmd</B>*
:au[tocmd] [group] <A HREF="#{event}">{event}</A> <A HREF="#{pat}">{pat}</A> [nested] {cmd}
Add {cmd} to the <A HREF="eval.html#list">list</A> of commands that Vim will
execute automatically on <A HREF="#{event}">{event}</A> for a file matching
<A HREF="#{pat}">{pat}</A> |<A HREF="#autocmd-patterns">autocmd-patterns</A>|.
Vim always adds the {cmd} after existing autocommands,
so that the autocommands execute in the order in which
they were given. See |<A HREF="#autocmd-nested">autocmd-nested</A>| for [nested].
The special <A HREF="pattern.html#pattern">pattern</A> <buffer> or <A HREF="#<buffer=N>"><buffer=N></A> defines a buffer-local <A HREF="#autocommand">autocommand</A>.
See |<A HREF="#autocmd-buflocal">autocmd-buflocal</A>|.
Note: The "<A HREF="#:autocmd">:autocmd</A>" command can only be followed by another command when the
'|' appears before {cmd}. This works:
<B> :augroup mine | au! BufRead | augroup END</B>
But this sees "augroup" <A HREF="motion.html#as">as</A> part of the defined command:
<B> :augroup mine | au! BufRead * | augroup END</B>
<B> :augroup mine | au BufRead * set tw=70 | augroup END</B>
Instead you can put the group name into the command:
<B> :au! mine BufRead *</B>
<B> :au mine BufRead * set tw=70</B>
Or use `:execute`:
<B> :augroup mine | exe "au! BufRead *" | augroup END</B>
<B> :augroup mine | exe "au BufRead * set tw=70" | augroup END</B>
Note that special characters (e.g., "<A HREF="motion.html#%">%</A>", "<cword>") in the "<A HREF="#:autocmd">:autocmd</A>"
arguments are not expanded when the <A HREF="#autocommand">autocommand</A> is defined. These will be
expanded when the Event is recognized, and the {cmd} is executed. The only
exception is that "<A HREF="cmdline.html#<sfile>"><sfile></A>" is expanded when the autocmd is defined. Example:
<B> :au BufNewFile,BufRead *.html so <sfile>:h/html.vim</B>
Here Vim expands <A HREF="cmdline.html#<sfile>"><sfile></A> to the name of the file containing this line.
`:autocmd` adds to the <A HREF="eval.html#list">list</A> of autocommands regardless of whether they are
already present. When your <A HREF="starting.html#.vimrc">.vimrc</A> file is sourced <A HREF="if_cscop.html#twice">twice</A>, the autocommands
will appear <A HREF="if_cscop.html#twice">twice</A>. To avoid this, define your autocommands in a group, so
that you can easily clear them:
<B> augroup vimrc</B>
<B> autocmd! " Remove all vimrc autocommands</B>
<B> au BufNewFile,BufRead *.html so <sfile>:h/html.vim</B>
<B> augroup END</B>
If you don't want to remove all autocommands, you can instead use a variable
to ensure that Vim includes the autocommands only once:
<B> :if !exists("autocommands_loaded")</B>
<B> : let autocommands_loaded = 1</B>
<B> : au ...</B>
<B> :endif</B>
When the [group] argument is not given, Vim uses the current group (as defined
with ":augroup"); otherwise, Vim uses the group defined with [group]. Note
that [group] must have been defined before. You cannot define a new group
with "<A HREF="#:au">:au</A> group ..."; use "<A HREF="#:augroup">:augroup</A>" for that.
While <A HREF="eval.html#testing">testing</A> autocommands, you might find the <A HREF="options.html#'verbose'">'verbose'</A> option to be useful:
<B> :set verbose=9</B>
This setting makes Vim echo the autocommands <A HREF="motion.html#as">as</A> <A HREF="motion.html#it">it</A> executes them.
When defining an <A HREF="#autocommand">autocommand</A> 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 event is
triggered and the command executed, <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="map.html#<SID>"><SID></A>| is used in a command.
When executing the commands, the message from one command overwrites a
previous message. This is different from when executing the commands
manually. Mostly the screen will not scroll up, thus there is no <A HREF="message.html#hit-enter">hit-enter</A>
prompt. When one command outputs two <A HREF="message.html#messages">messages</A> this can happen anyway.
==============================================================================
3. Removing autocommands *<A NAME="autocmd-remove"></A><B>autocmd-remove</B>*
:au[tocmd]! [group] <A HREF="#{event}">{event}</A> <A HREF="#{pat}">{pat}</A> [nested] {cmd}
Remove all autocommands associated with <A HREF="#{event}">{event}</A> and
<A HREF="#{pat}">{pat}</A>, and add the command {cmd}. See
|<A HREF="#autocmd-nested">autocmd-nested</A>| for [nested].
:au[tocmd]! [group] <A HREF="#{event}">{event}</A> <A HREF="#{pat}">{pat}</A>
Remove all autocommands associated with <A HREF="#{event}">{event}</A> and
<A HREF="#{pat}">{pat}</A>.
:au[tocmd]! [group] * <A HREF="#{pat}">{pat}</A>
Remove all autocommands associated with <A HREF="#{pat}">{pat}</A> for all
events.
:au[tocmd]! [group] <A HREF="#{event}">{event}</A>
Remove ALL autocommands for <A HREF="#{event}">{event}</A>.
Warning: You should not <A HREF="diff.html#do">do</A> this without a group for
|<A HREF="#BufRead">BufRead</A>| and other common events, <A HREF="motion.html#it">it</A> can break
plugins, <A HREF="syntax.html#syntax">syntax</A> highlighting, etc.
:au[tocmd]! [group] Remove ALL autocommands.
Warning: You should normally not <A HREF="diff.html#do">do</A> this without a
group, <A HREF="motion.html#it">it</A> breaks plugins, <A HREF="syntax.html#syntax">syntax</A> highlighting, etc.
When the [group] argument is not given, Vim uses the current group (as defined
with ":augroup"); otherwise, Vim uses the group defined with [group].
==============================================================================
4. Listing autocommands *<A NAME="autocmd-list"></A><B>autocmd-list</B>*
:au[tocmd] [group] <A HREF="#{event}">{event}</A> <A HREF="#{pat}">{pat}</A>
Show the autocommands associated with <A HREF="#{event}">{event}</A> and
<A HREF="#{pat}">{pat}</A>.
:au[tocmd] [group] * <A HREF="#{pat}">{pat}</A>
Show the autocommands associated with <A HREF="#{pat}">{pat}</A> for all
events.
:au[tocmd] [group] <A HREF="#{event}">{event}</A>
Show all autocommands for <A HREF="#{event}">{event}</A>.
:au[tocmd] [group] Show all autocommands.
If you provide the [group] argument, Vim lists only the autocommands for
[group]; otherwise, Vim lists the autocommands for ALL groups. Note that this
argument behavior differs from that for defining and removing autocommands.
In order to <A HREF="eval.html#list">list</A> buffer-local autocommands, use a <A HREF="pattern.html#pattern">pattern</A> in the form <buffer>
or <A HREF="#<buffer=N>"><buffer=N></A>. See |<A HREF="#autocmd-buflocal">autocmd-buflocal</A>|.
*<A NAME=":autocmd-verbose"></A><B>:autocmd-verbose</B>*
When <A HREF="options.html#'verbose'">'verbose'</A> is non-zero, listing an <A HREF="#autocommand">autocommand</A> will also display where <A HREF="motion.html#it">it</A>
was last defined. Example:
<B> :verbose autocmd BufEnter</B>
<B> FileExplorer BufEnter</B>
<B> * call s:LocalBrowse(expand("<amatch>"))</B>
<B> Last set from /usr/share/vim/vim-7.0/plugin/NetrwPlugin.vim</B>
See |<A HREF="various.html#:verbose-cmd">:verbose-cmd</A>| for more information.
==============================================================================
5. Events *<A NAME="autocmd-events"></A><B>autocmd-events</B>* *<A NAME="E215"></A><B>E215</B>* *<A NAME="E216"></A><B>E216</B>*
You can specify a comma-separated <A HREF="eval.html#list">list</A> of event names. No white space can be
used in this <A HREF="eval.html#list">list</A>. The command applies to all the events in the <A HREF="eval.html#list">list</A>.
For READING FILES there are four kinds of events possible:
<A HREF="#BufNewFile">BufNewFile</A> starting to edit a non-existent file
<A HREF="#BufReadPre">BufReadPre</A> <A HREF="#BufReadPost">BufReadPost</A> starting to edit an existing file
<A HREF="#FilterReadPre">FilterReadPre</A> <A HREF="#FilterReadPost">FilterReadPost</A> read the temp file with <A HREF="change.html#filter">filter</A> output
<A HREF="#FileReadPre">FileReadPre</A> <A HREF="#FileReadPost">FileReadPost</A> any other file read
Vim uses only one of these four kinds when reading a file. The "Pre" and
"Post" events are both triggered, before and after reading the file.
Note that the autocommands for the *ReadPre events and all the Filter events
are not allowed to change the current buffer (you will get an error message if
this happens). This is to prevent the file to be read into the wrong buffer.
Note that the <A HREF="options.html#'modified'">'modified'</A> flag is reset AFTER executing the <A HREF="#BufReadPost">BufReadPost</A>
and <A HREF="#BufNewFile">BufNewFile</A> autocommands. But when the <A HREF="options.html#'modified'">'modified'</A> option was set by the
autocommands, this doesn't happen.
You can use the <A HREF="options.html#'eventignore'">'eventignore'</A> option to ignore a number of events or all
events.
*<A NAME="autocommand-events"></A><B>autocommand-events</B>* *<A NAME="{event}"></A><B>{event}</B>*
Vim recognizes the following events. Vim ignores the <A HREF="change.html#case">case</A> of event names
(e.g., you can use "BUFread" or "bufread" instead of "BufRead").
First an overview by function with a short explanation. Then the <A HREF="eval.html#list">list</A>
alphabetically with full explanations |<A HREF="#autocmd-events-abc">autocmd-events-abc</A>|.
<B><FONT COLOR="PURPLE">Name triggered by </FONT></B>
Reading
|<A HREF="#BufNewFile">BufNewFile</A>| starting to edit a file that doesn't exist
|<A HREF="#BufReadPre">BufReadPre</A>| starting to edit a new buffer, before reading the file
|<A HREF="#BufRead">BufRead</A>| starting to edit a new buffer, after reading the file
|<A HREF="#BufReadPost">BufReadPost</A>| starting to edit a new buffer, after reading the file
|<A HREF="#BufReadCmd">BufReadCmd</A>| before starting to edit a new buffer |<A HREF="#Cmd-event">Cmd-event</A>|
|<A HREF="#FileReadPre">FileReadPre</A>| before reading a file with a "<A HREF="insert.html#:read">:read</A>" command
|<A HREF="#FileReadPost">FileReadPost</A>| after reading a file with a "<A HREF="insert.html#:read">:read</A>" command
|<A HREF="#FileReadCmd">FileReadCmd</A>| before reading a file with a "<A HREF="insert.html#:read">:read</A>" command |<A HREF="#Cmd-event">Cmd-event</A>|
|<A HREF="#FilterReadPre">FilterReadPre</A>| before reading a file from a <A HREF="change.html#filter">filter</A> command
|<A HREF="#FilterReadPost">FilterReadPost</A>| after reading a file from a <A HREF="change.html#filter">filter</A> command
|<A HREF="#StdinReadPre">StdinReadPre</A>| before reading from stdin into the buffer
|<A HREF="#StdinReadPost">StdinReadPost</A>| After reading from the stdin into the buffer
Writing
|<A HREF="#BufWrite">BufWrite</A>| starting to write the whole buffer to a file
|<A HREF="#BufWritePre">BufWritePre</A>| starting to write the whole buffer to a file
|<A HREF="#BufWritePost">BufWritePost</A>| after <A HREF="editing.html#writing">writing</A> the whole buffer to a file
|<A HREF="#BufWriteCmd">BufWriteCmd</A>| before <A HREF="editing.html#writing">writing</A> the whole buffer to a file |<A HREF="#Cmd-event">Cmd-event</A>|
|<A HREF="#FileWritePre">FileWritePre</A>| starting to write part of a buffer to a file
|<A HREF="#FileWritePost">FileWritePost</A>| after <A HREF="editing.html#writing">writing</A> part of a buffer to a file
|<A HREF="#FileWriteCmd">FileWriteCmd</A>| before <A HREF="editing.html#writing">writing</A> part of a buffer to a file |<A HREF="#Cmd-event">Cmd-event</A>|
|<A HREF="#FileAppendPre">FileAppendPre</A>| starting to append to a file
|<A HREF="#FileAppendPost">FileAppendPost</A>| after appending to a file
|<A HREF="#FileAppendCmd">FileAppendCmd</A>| before appending to a file |<A HREF="#Cmd-event">Cmd-event</A>|
|<A HREF="#FilterWritePre">FilterWritePre</A>| starting to write a file for a <A HREF="change.html#filter">filter</A> command or <A HREF="diff.html#diff">diff</A>
|<A HREF="#FilterWritePost">FilterWritePost</A>| after <A HREF="editing.html#writing">writing</A> a file for a <A HREF="change.html#filter">filter</A> command or <A HREF="diff.html#diff">diff</A>
Buffers
|<A HREF="#BufAdd">BufAdd</A>| just after adding a buffer to the buffer <A HREF="eval.html#list">list</A>
|<A HREF="#BufCreate">BufCreate</A>| just after adding a buffer to the buffer <A HREF="eval.html#list">list</A>
|<A HREF="#BufDelete">BufDelete</A>| before <A HREF="change.html#deleting">deleting</A> a buffer from the buffer <A HREF="eval.html#list">list</A>
|<A HREF="#BufWipeout">BufWipeout</A>| before completely <A HREF="change.html#deleting">deleting</A> a buffer
|<A HREF="#BufFilePre">BufFilePre</A>| before <A HREF="change.html#changing">changing</A> the name of the current buffer
|<A HREF="#BufFilePost">BufFilePost</A>| after <A HREF="change.html#changing">changing</A> the name of the current buffer
|<A HREF="#BufEnter">BufEnter</A>| after entering a buffer
|<A HREF="#BufLeave">BufLeave</A>| before leaving to another buffer
|<A HREF="#BufWinEnter">BufWinEnter</A>| after a buffer is displayed in a <A HREF="windows.html#window">window</A>
|<A HREF="#BufWinLeave">BufWinLeave</A>| before a buffer is removed from a <A HREF="windows.html#window">window</A>
|<A HREF="#BufUnload">BufUnload</A>| before unloading a buffer
|<A HREF="#BufHidden">BufHidden</A>| just after a buffer has become hidden
|<A HREF="#BufNew">BufNew</A>| just after creating a new buffer
|<A HREF="#SwapExists">SwapExists</A>| detected an existing swap file
Options
|<A HREF="#FileType">FileType</A>| when the <A HREF="options.html#'filetype'">'filetype'</A> option has been set
|<A HREF="#Syntax">Syntax</A>| when the <A HREF="options.html#'syntax'">'syntax'</A> option has been set
|<A HREF="#EncodingChanged">EncodingChanged</A>| after the <A HREF="options.html#'encoding'">'encoding'</A> option has been changed
|<A HREF="#TermChanged">TermChanged</A>| after the value of <A HREF="options.html#'term'">'term'</A> has changed
|<A HREF="#OptionSet">OptionSet</A>| after setting any option
Startup and exit
|<A HREF="#VimEnter">VimEnter</A>| after doing all the <A HREF="starting.html#startup">startup</A> stuff
|<A HREF="#GUIEnter">GUIEnter</A>| after starting the GUI successfully
|<A HREF="#GUIFailed">GUIFailed</A>| after starting the GUI failed
|<A HREF="#TermResponse">TermResponse</A>| after the <A HREF="terminal.html#terminal">terminal</A> response to |<A HREF="term.html#t_RV">t_RV</A>| is received
|<A HREF="#QuitPre">QuitPre</A>| when using `:quit`, before deciding whether to quit
|<A HREF="#VimLeavePre">VimLeavePre</A>| before <A HREF="starting.html#exiting">exiting</A> Vim, before <A HREF="editing.html#writing">writing</A> the <A HREF="starting.html#viminfo">viminfo</A> file
|<A HREF="#VimLeave">VimLeave</A>| before <A HREF="starting.html#exiting">exiting</A> Vim, after <A HREF="editing.html#writing">writing</A> the <A HREF="starting.html#viminfo">viminfo</A> file
Various
|<A HREF="#FileChangedShell">FileChangedShell</A>| Vim notices that a file changed since editing started
|<A HREF="#FileChangedShellPost">FileChangedShellPost</A>| After handling a file changed since editing started
|<A HREF="#FileChangedRO">FileChangedRO</A>| before making the first change to a read-only file
|<A HREF="#ShellCmdPost">ShellCmdPost</A>| after executing a shell command
|<A HREF="#ShellFilterPost">ShellFilterPost</A>| after filtering with a shell command
|<A HREF="#CmdUndefined">CmdUndefined</A>| a user command is used but <A HREF="motion.html#it">it</A> isn't defined
|<A HREF="#FuncUndefined">FuncUndefined</A>| a user function is used but <A HREF="motion.html#it">it</A> isn't defined
|<A HREF="#SpellFileMissing">SpellFileMissing</A>| a <A HREF="spell.html#spell">spell</A> file is used but <A HREF="motion.html#it">it</A> can't be found
|<A HREF="#SourcePre">SourcePre</A>| before sourcing a Vim <A HREF="usr_41.html#script">script</A>
|<A HREF="#SourceCmd">SourceCmd</A>| before sourcing a Vim <A HREF="usr_41.html#script">script</A> |<A HREF="#Cmd-event">Cmd-event</A>|
|<A HREF="#VimResized">VimResized</A>| after the Vim <A HREF="windows.html#window">window</A> size changed
|<A HREF="#FocusGained">FocusGained</A>| Vim got input focus
|<A HREF="#FocusLost">FocusLost</A>| Vim lost input focus
|<A HREF="#CursorHold">CursorHold</A>| the user doesn't press a key for a while
|<A HREF="#CursorHoldI">CursorHoldI</A>| the user doesn't press a key for a while in <A HREF="insert.html#Insert">Insert</A> mode
|<A HREF="#CursorMoved">CursorMoved</A>| the cursor was moved in <A HREF="intro.html#Normal">Normal</A> mode
|<A HREF="#CursorMovedI">CursorMovedI</A>| the cursor was moved in <A HREF="insert.html#Insert">Insert</A> mode
|<A HREF="#WinNew">WinNew</A>| after creating a new <A HREF="windows.html#window">window</A>
|<A HREF="#TabNew">TabNew</A>| after creating a new <A HREF="intro.html#tab">tab</A> page
|<A HREF="#TabClosed">TabClosed</A>| after closing a <A HREF="intro.html#tab">tab</A> page
|<A HREF="#WinEnter">WinEnter</A>| after entering another <A HREF="windows.html#window">window</A>
|<A HREF="#WinLeave">WinLeave</A>| before leaving a <A HREF="windows.html#window">window</A>
|<A HREF="#TabEnter">TabEnter</A>| after entering another <A HREF="intro.html#tab">tab</A> page
|<A HREF="#TabLeave">TabLeave</A>| before leaving a <A HREF="intro.html#tab">tab</A> page
|<A HREF="#CmdwinEnter">CmdwinEnter</A>| after entering the command-line <A HREF="windows.html#window">window</A>
|<A HREF="#CmdwinLeave">CmdwinLeave</A>| before leaving the command-line <A HREF="windows.html#window">window</A>
|<A HREF="#InsertEnter">InsertEnter</A>| starting Insert mode
|<A HREF="#InsertChange">InsertChange</A>| when typing <A HREF="insert.html#<Insert>"><Insert></A> while in Insert or <A HREF="insert.html#Replace">Replace</A> mode
|<A HREF="#InsertLeave">InsertLeave</A>| when leaving Insert mode
|<A HREF="#InsertCharPre">InsertCharPre</A>| when a character was typed in Insert mode, before
<A HREF="insert.html#inserting">inserting</A> <A HREF="motion.html#it">it</A>
|<A HREF="#TextChanged">TextChanged</A>| after a change was made to the text in <A HREF="intro.html#Normal">Normal</A> mode
|<A HREF="#TextChangedI">TextChangedI</A>| after a change was made to the text in <A HREF="insert.html#Insert">Insert</A> mode
|<A HREF="#TextYankPost">TextYankPost</A>| after text is yanked or deleted
|<A HREF="#ColorScheme">ColorScheme</A>| after loading a color scheme
|<A HREF="#RemoteReply">RemoteReply</A>| a reply from a server Vim was received
|<A HREF="#QuickFixCmdPre">QuickFixCmdPre</A>| before a <A HREF="quickfix.html#quickfix">quickfix</A> command is run
|<A HREF="#QuickFixCmdPost">QuickFixCmdPost</A>| after a <A HREF="quickfix.html#quickfix">quickfix</A> command is run
|<A HREF="#SessionLoadPost">SessionLoadPost</A>| after loading a session file
|<A HREF="#MenuPopup">MenuPopup</A>| just before showing the popup menu
|<A HREF="#CompleteDone">CompleteDone</A>| after <A HREF="insert.html#Insert">Insert</A> mode completion is done
|<A HREF="#User">User</A>| to be used in combination with "<A HREF="#:doautocmd">:doautocmd</A>"
The alphabetical <A HREF="eval.html#list">list</A> of <A HREF="#autocommand">autocommand</A> events: *<A NAME="autocmd-events-abc"></A><B>autocmd-events-abc</B>*
*<A NAME="BufCreate"></A><B>BufCreate</B>* *<A NAME="BufAdd"></A><B>BufAdd</B>*
<A HREF="#BufAdd">BufAdd</A> or <A HREF="#BufCreate">BufCreate</A> Just after creating a new buffer which is
added to the buffer <A HREF="eval.html#list">list</A>, or adding a buffer
to the buffer <A HREF="eval.html#list">list</A>.
Also used just after a buffer in the buffer
<A HREF="eval.html#list">list</A> has been renamed.
The <A HREF="#BufCreate">BufCreate</A> event is for historic reasons.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being created "<A HREF="cmdline.html#<afile>"><afile></A>".
*<A NAME="BufDelete"></A><B>BufDelete</B>*
<A HREF="#BufDelete">BufDelete</A> Before <A HREF="change.html#deleting">deleting</A> a buffer from the buffer <A HREF="eval.html#list">list</A>.
The <A HREF="#BufUnload">BufUnload</A> may be called first (if the
buffer was loaded).
Also used just before a buffer in the buffer
<A HREF="eval.html#list">list</A> is renamed.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being deleted "<A HREF="cmdline.html#<afile>"><afile></A>" and "<A HREF="cmdline.html#<abuf>"><abuf></A>".
Don't change to another buffer, <A HREF="motion.html#it">it</A> will cause
problems.
*<A NAME="BufEnter"></A><B>BufEnter</B>*
<A HREF="#BufEnter">BufEnter</A> After entering a buffer. Useful for setting
<A HREF="options.html#options">options</A> for a file type. Also executed when
starting to edit a buffer, after the
<A HREF="#BufReadPost">BufReadPost</A> autocommands.
*<A NAME="BufFilePost"></A><B>BufFilePost</B>*
<A HREF="#BufFilePost">BufFilePost</A> After <A HREF="change.html#changing">changing</A> the name of the current buffer
with the "<A HREF="editing.html#:file">:file</A>" or "<A HREF="editing.html#:saveas">:saveas</A>" command.
*<A NAME="BufFilePre"></A><B>BufFilePre</B>*
<A HREF="#BufFilePre">BufFilePre</A> Before <A HREF="change.html#changing">changing</A> the name of the current buffer
with the "<A HREF="editing.html#:file">:file</A>" or "<A HREF="editing.html#:saveas">:saveas</A>" command.
*<A NAME="BufHidden"></A><B>BufHidden</B>*
<A HREF="#BufHidden">BufHidden</A> Just after a buffer has become hidden. That
is, when there are no longer <A HREF="windows.html#windows">windows</A> that show
the buffer, but the buffer is not unloaded or
deleted. Not used for "<A HREF="editing.html#:qa">:qa</A>" or "<A HREF="editing.html#:q">:q</A>" when
<A HREF="starting.html#exiting">exiting</A> Vim.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being unloaded "<A HREF="cmdline.html#<afile>"><afile></A>".
*<A NAME="BufLeave"></A><B>BufLeave</B>*
<A HREF="#BufLeave">BufLeave</A> Before leaving to another buffer. Also when
leaving or closing the current <A HREF="windows.html#window">window</A> and the
new current <A HREF="windows.html#window">window</A> is not for the same buffer.
Not used for "<A HREF="editing.html#:qa">:qa</A>" or "<A HREF="editing.html#:q">:q</A>" when <A HREF="starting.html#exiting">exiting</A> Vim.
*<A NAME="BufNew"></A><B>BufNew</B>*
<A HREF="#BufNew">BufNew</A> Just after creating a new buffer. Also used
just after a buffer has been renamed. When
the buffer is added to the buffer <A HREF="eval.html#list">list</A> <A HREF="#BufAdd">BufAdd</A>
will be triggered too.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being created "<A HREF="cmdline.html#<afile>"><afile></A>".
*<A NAME="BufNewFile"></A><B>BufNewFile</B>*
<A HREF="#BufNewFile">BufNewFile</A> When starting to edit a file that doesn't
exist. Can be used to read in a <A HREF="#skeleton">skeleton</A>
file.
*<A NAME="BufRead"></A><B>BufRead</B>* *<A NAME="BufReadPost"></A><B>BufReadPost</B>*
<A HREF="#BufRead">BufRead</A> or <A HREF="#BufReadPost">BufReadPost</A> When starting to edit a new buffer, after
reading the file into the buffer, before
executing the modelines. See |<A HREF="#BufWinEnter">BufWinEnter</A>|
for when you need to <A HREF="diff.html#do">do</A> something after
processing the modelines.
This does NOT work for "<A HREF="insert.html#:r">:r</A> file". Not used
when the file doesn't exist. Also used after
successfully recovering a file.
Also triggered for the filetypedetect group
when executing "<A HREF="filetype.html#:filetype">:filetype</A> detect" and when
<A HREF="editing.html#writing">writing</A> an unnamed buffer in a way that the
buffer gets a name.
*<A NAME="BufReadCmd"></A><B>BufReadCmd</B>*
<A HREF="#BufReadCmd">BufReadCmd</A> Before starting to edit a new buffer. Should
read the file into the buffer. |<A HREF="#Cmd-event">Cmd-event</A>|
*<A NAME="BufReadPre"></A><B>BufReadPre</B>* *<A NAME="E200"></A><B>E200</B>* *<A NAME="E201"></A><B>E201</B>*
<A HREF="#BufReadPre">BufReadPre</A> When starting to edit a new buffer, before
reading the file into the buffer. Not used
if the file doesn't exist.
*<A NAME="BufUnload"></A><B>BufUnload</B>*
<A HREF="#BufUnload">BufUnload</A> Before unloading a buffer. This is when the
text in the buffer is going to be freed. This
may be after a <A HREF="#BufWritePost">BufWritePost</A> and before a
<A HREF="#BufDelete">BufDelete</A>. Also used for all <A HREF="windows.html#buffers">buffers</A> that are
loaded when Vim is going to exit.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being unloaded "<A HREF="cmdline.html#<afile>"><afile></A>".
Don't change to another buffer or <A HREF="windows.html#window">window</A>, <A HREF="motion.html#it">it</A>
will cause problems!
When <A HREF="starting.html#exiting">exiting</A> and <A HREF="eval.html#v:dying">v:dying</A> is 2 or more this
event is not triggered.
*<A NAME="BufWinEnter"></A><B>BufWinEnter</B>*
<A HREF="#BufWinEnter">BufWinEnter</A> After a buffer is displayed in a <A HREF="windows.html#window">window</A>. This
can be when the buffer is loaded (after
processing the modelines) or when a hidden
buffer is displayed in a <A HREF="windows.html#window">window</A> (and is no
longer hidden).
Does not happen for |<A HREF="windows.html#:split">:split</A>| without
arguments, since you keep editing the same
buffer, or "<A HREF="windows.html#:split">:split</A>" with a file that's already
open in a <A HREF="windows.html#window">window</A>, because <A HREF="motion.html#it">it</A> re-uses an
existing buffer. But <A HREF="motion.html#it">it</A> does happen for a
"<A HREF="windows.html#:split">:split</A>" with the name of the current buffer,
since <A HREF="motion.html#it">it</A> reloads that buffer.
*<A NAME="BufWinLeave"></A><B>BufWinLeave</B>*
<A HREF="#BufWinLeave">BufWinLeave</A> Before a buffer is removed from a <A HREF="windows.html#window">window</A>.
Not when it's still visible in another <A HREF="windows.html#window">window</A>.
Also triggered when <A HREF="starting.html#exiting">exiting</A>. It's triggered
before <A HREF="#BufUnload">BufUnload</A> or <A HREF="#BufHidden">BufHidden</A>.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being unloaded "<A HREF="cmdline.html#<afile>"><afile></A>".
When <A HREF="starting.html#exiting">exiting</A> and <A HREF="eval.html#v:dying">v:dying</A> is 2 or more this
event is not triggered.
*<A NAME="BufWipeout"></A><B>BufWipeout</B>*
<A HREF="#BufWipeout">BufWipeout</A> Before completely <A HREF="change.html#deleting">deleting</A> a buffer. The
<A HREF="#BufUnload">BufUnload</A> and <A HREF="#BufDelete">BufDelete</A> events may be called
first (if the buffer was loaded and was in the
buffer <A HREF="eval.html#list">list</A>). Also used just before a buffer
is renamed (also when it's not in the buffer
<A HREF="eval.html#list">list</A>).
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer being deleted "<A HREF="cmdline.html#<afile>"><afile></A>".
Don't change to another buffer, <A HREF="motion.html#it">it</A> will cause
problems.
*<A NAME="BufWrite"></A><B>BufWrite</B>* *<A NAME="BufWritePre"></A><B>BufWritePre</B>*
<A HREF="#BufWrite">BufWrite</A> or <A HREF="#BufWritePre">BufWritePre</A> Before <A HREF="editing.html#writing">writing</A> the whole buffer to a file.
*<A NAME="BufWriteCmd"></A><B>BufWriteCmd</B>*
<A HREF="#BufWriteCmd">BufWriteCmd</A> Before <A HREF="editing.html#writing">writing</A> the whole buffer to a file.
Should <A HREF="diff.html#do">do</A> the <A HREF="editing.html#writing">writing</A> of the file and reset
<A HREF="options.html#'modified'">'modified'</A> if successful, unless '<A HREF="motion.html#+">+</A>' is in
<A HREF="options.html#'cpo'">'cpo'</A> and <A HREF="editing.html#writing">writing</A> to another file |<A HREF="options.html#cpo-+">cpo-+</A>|.
The buffer contents should not be changed.
When the command resets <A HREF="options.html#'modified'">'modified'</A> the <A HREF="undo.html#undo">undo</A>
information is adjusted to <A HREF="motion.html#mark">mark</A> older <A HREF="undo.html#undo">undo</A>
states <A HREF="motion.html#as">as</A> <A HREF="options.html#'modified'">'modified'</A>, like |<A HREF="editing.html#:write">:write</A>| does.
|<A HREF="#Cmd-event">Cmd-event</A>|
*<A NAME="BufWritePost"></A><B>BufWritePost</B>*
<A HREF="#BufWritePost">BufWritePost</A> After <A HREF="editing.html#writing">writing</A> the whole buffer to a file
(should <A HREF="undo.html#undo">undo</A> the commands for <A HREF="#BufWritePre">BufWritePre</A>).
*<A NAME="CmdUndefined"></A><B>CmdUndefined</B>*
<A HREF="#CmdUndefined">CmdUndefined</A> When a user command is used but <A HREF="motion.html#it">it</A> isn't
defined. Useful for defining a command only
when it's used. The <A HREF="pattern.html#pattern">pattern</A> is matched
against the command name. Both <A HREF="cmdline.html#<amatch>"><amatch></A> and
<A HREF="cmdline.html#<afile>"><afile></A> are set to the name of the command.
NOTE: Autocompletion won't work until the
command is defined. An alternative is to
always define the user command and have <A HREF="motion.html#it">it</A>
invoke an autoloaded function. See |<A HREF="eval.html#autoload">autoload</A>|.
*<A NAME="CmdlineChanged"></A><B>CmdlineChanged</B>*
<A HREF="#CmdlineChanged">CmdlineChanged</A> After a change was made to the text inside
command line. Be careful not to mess up the
command line, <A HREF="motion.html#it">it</A> may cause Vim to lock up.
<A HREF="cmdline.html#<afile>"><afile></A> is set to a single character,
indicating the type of command-line.
|<A HREF="cmdline.html#cmdwin-char">cmdwin-char</A>|
*<A NAME="CmdlineEnter"></A><B>CmdlineEnter</B>*
<A HREF="#CmdlineEnter">CmdlineEnter</A> After moving the cursor to the command line,
where the user can type a command or search
<A HREF="eval.html#string">string</A>.
<A HREF="cmdline.html#<afile>"><afile></A> is set to a single character,
indicating the type of command-line.
|<A HREF="cmdline.html#cmdwin-char">cmdwin-char</A>|
*<A NAME="CmdlineLeave"></A><B>CmdlineLeave</B>*
<A HREF="#CmdlineLeave">CmdlineLeave</A> Before leaving the command line.
Also when abandoning the command line, after
typing <A HREF="pattern.html#CTRL-C">CTRL-C</A> or <A HREF="intro.html#<Esc>"><Esc></A>.
When the commands result in an error the
command line is still executed.
<A HREF="cmdline.html#<afile>"><afile></A> is set to a single character,
indicating the type of command-line.
|<A HREF="cmdline.html#cmdwin-char">cmdwin-char</A>|
*<A NAME="CmdwinEnter"></A><B>CmdwinEnter</B>*
<A HREF="#CmdwinEnter">CmdwinEnter</A> After entering the command-line <A HREF="windows.html#window">window</A>.
Useful for setting <A HREF="options.html#options">options</A> specifically for
this special type of <A HREF="windows.html#window">window</A>. This is
triggered _instead_ of <A HREF="#BufEnter">BufEnter</A> and <A HREF="#WinEnter">WinEnter</A>.
<A HREF="cmdline.html#<afile>"><afile></A> is set to a single character,
indicating the type of command-line.
|<A HREF="cmdline.html#cmdwin-char">cmdwin-char</A>|
*<A NAME="CmdwinLeave"></A><B>CmdwinLeave</B>*
<A HREF="#CmdwinLeave">CmdwinLeave</A> Before leaving the command-line <A HREF="windows.html#window">window</A>.
Useful to clean up any global setting done
with <A HREF="#CmdwinEnter">CmdwinEnter</A>. This is triggered _instead_
of <A HREF="#BufLeave">BufLeave</A> and <A HREF="#WinLeave">WinLeave</A>.
<A HREF="cmdline.html#<afile>"><afile></A> is set to a single character,
indicating the type of command-line.
|<A HREF="cmdline.html#cmdwin-char">cmdwin-char</A>|
*<A NAME="ColorScheme"></A><B>ColorScheme</B>*
<A HREF="#ColorScheme">ColorScheme</A> After loading a color scheme. |<A HREF="syntax.html#:colorscheme">:colorscheme</A>|
The <A HREF="pattern.html#pattern">pattern</A> is matched against the
colorscheme name. <A HREF="cmdline.html#<afile>"><afile></A> can be used for the
name of the actual file where this option was
set, and <A HREF="cmdline.html#<amatch>"><amatch></A> for the new colorscheme
name.
*<A NAME="CompleteDone"></A><B>CompleteDone</B>*
<A HREF="#CompleteDone">CompleteDone</A> After <A HREF="insert.html#Insert">Insert</A> mode completion is done. Either
when something was completed or abandoning
completion. |<A HREF="insert.html#ins-completion">ins-completion</A>|
The |<A HREF="eval.html#v:completed_item">v:completed_item</A>| variable contains
information about the completed item.
*<A NAME="CursorHold"></A><B>CursorHold</B>*
<A HREF="#CursorHold">CursorHold</A> When the user doesn't press a key for the time
specified with <A HREF="options.html#'updatetime'">'updatetime'</A>. Not re-triggered
until the user has pressed a key (i.e. doesn't
fire every <A HREF="options.html#'updatetime'">'updatetime'</A> ms if you leave Vim to
make some coffee. :) See |<A HREF="windows.html#CursorHold-example">CursorHold-example</A>|
for previewing <A HREF="tagsrch.html#tags">tags</A>.
This event is only triggered in <A HREF="intro.html#Normal">Normal</A> mode.
It is not triggered when waiting for a command
argument to be typed, or a <A HREF="intro.html#movement">movement</A> after an
<A HREF="motion.html#operator">operator</A>.
While <A HREF="repeat.html#recording">recording</A> the <A HREF="#CursorHold">CursorHold</A> event is not
triggered. |<A HREF="repeat.html#q">q</A>|
*<A NAME="<CursorHold>"></A><B><CursorHold></B>*
Internally the <A HREF="#autocommand">autocommand</A> is triggered by the
<A HREF="#<CursorHold>"><CursorHold></A> key. In an <A HREF="eval.html#expression">expression</A> <A HREF="map.html#mapping">mapping</A>
|<A HREF="eval.html#getchar()">getchar()</A>| may see this character.
Note: Interactive commands cannot be used for
this event. There is no <A HREF="message.html#hit-enter">hit-enter</A> prompt,
the screen is updated directly (when needed).
Note: In the future there will probably be
another option to set the time.
Hint: to force an update of the status lines
use:
<B> :let &ro = &ro</B>
{only on <A HREF="os_amiga.html#Amiga">Amiga</A>, <A HREF="os_unix.html#Unix">Unix</A>, <A HREF="os_win32.html#Win32">Win32</A>, <A HREF="os_msdos.html#MSDOS">MSDOS</A> and all <A HREF="gui.html#GUI">GUI</A>
versions}
*<A NAME="CursorHoldI"></A><B>CursorHoldI</B>*
<A HREF="#CursorHoldI">CursorHoldI</A> Just like <A HREF="#CursorHold">CursorHold</A>, but in <A HREF="insert.html#Insert">Insert</A> mode.
Not triggered when waiting for another key,
e.g. after <A HREF="visual.html#CTRL-V">CTRL-V</A>, and not when in <A HREF="change.html#CTRL-X">CTRL-X</A> mode
|<A HREF="insert.html#insert_expand">insert_expand</A>|.
*<A NAME="CursorMoved"></A><B>CursorMoved</B>*
<A HREF="#CursorMoved">CursorMoved</A> After the cursor was moved in <A HREF="intro.html#Normal">Normal</A> or <A HREF="visual.html#Visual">Visual</A>
mode. Also when the text of the cursor line
has been changed, e.g., with "<A HREF="change.html#x">x</A>", "rx" or "<A HREF="change.html#p">p</A>".
Not triggered when there is typeahead or when
an <A HREF="motion.html#operator">operator</A> is pending.
For an example see |<A HREF="tips.html#match-parens">match-parens</A>|.
Careful: This is triggered very often, don't
<A HREF="diff.html#do">do</A> anything that the user does not expect or
that is slow.
*<A NAME="CursorMovedI"></A><B>CursorMovedI</B>*
<A HREF="#CursorMovedI">CursorMovedI</A> After the cursor was moved in <A HREF="insert.html#Insert">Insert</A> mode.
Not triggered when the popup menu is visible.
Otherwise the same <A HREF="motion.html#as">as</A> <A HREF="#CursorMoved">CursorMoved</A>.
*<A NAME="EncodingChanged"></A><B>EncodingChanged</B>*
<A HREF="#EncodingChanged">EncodingChanged</A> Fires off after the <A HREF="options.html#'encoding'">'encoding'</A> option has been
changed. Useful to set up fonts, for example.
*<A NAME="FileAppendCmd"></A><B>FileAppendCmd</B>*
<A HREF="#FileAppendCmd">FileAppendCmd</A> Before appending to a file. Should <A HREF="diff.html#do">do</A> the
appending to the file. Use the <A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A>
marks for the range of lines.|Cmd-eventYXXY
*<A NAME="FileAppendPost"></A><B>FileAppendPost</B>*
<A HREF="#FileAppendPost">FileAppendPost</A> After appending to a file.
*<A NAME="FileAppendPre"></A><B>FileAppendPre</B>*
<A HREF="#FileAppendPre">FileAppendPre</A> Before appending to a file. Use the <A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A>
marks for the range of lines.
*<A NAME="FileChangedRO"></A><B>FileChangedRO</B>*
<A HREF="#FileChangedRO">FileChangedRO</A> Before making the first change to a read-only
file. Can be used to check-out the file from
a source <A HREF="intro.html#control">control</A> system. Not triggered when
the change was caused by an <A HREF="#autocommand">autocommand</A>.
This event is triggered when making the first
change in a buffer or the first change after
<A HREF="options.html#'readonly'">'readonly'</A> was set, just before the change is
applied to the text.
WARNING: If the <A HREF="#autocommand">autocommand</A> moves the cursor
the effect of the change is undefined.
*<A NAME="E788"></A><B>E788</B>*
It is not allowed to change to another buffer
here. You can <A HREF="editing.html#reload">reload</A> the buffer but not edit
another one.
*<A NAME="E881"></A><B>E881</B>*
If the number of lines changes saving for <A HREF="undo.html#undo">undo</A>
may fail and the change will be aborted.
*<A NAME="FileChangedShell"></A><B>FileChangedShell</B>*
<A HREF="#FileChangedShell">FileChangedShell</A> When Vim notices that the modification time of
a file has changed since editing started.
Also when the file attributes of the file
change or when the size of the file changes.
|<A HREF="editing.html#timestamp">timestamp</A>|
Mostly triggered after executing a shell
command, but also with a |<A HREF="editing.html#:checktime">:checktime</A>| command
or when <A HREF="starting.html#gvim">gvim</A> regains input focus.
This <A HREF="#autocommand">autocommand</A> is triggered for each changed
file. It is not used when <A HREF="options.html#'autoread'">'autoread'</A> is set
and the buffer was not changed. If a
<A HREF="#FileChangedShell">FileChangedShell</A> <A HREF="#autocommand">autocommand</A> is present the
warning message and prompt is not given.
The |<A HREF="eval.html#v:fcs_reason">v:fcs_reason</A>| variable is set to indicate
what happened and |<A HREF="eval.html#v:fcs_choice">v:fcs_choice</A>| can be used
to tell Vim what to <A HREF="diff.html#do">do</A> next.
NOTE: When this <A HREF="#autocommand">autocommand</A> is executed, the
current buffer "<A HREF="motion.html#%">%</A>" may be different from the
buffer that was changed, which is in "<A HREF="cmdline.html#<afile>"><afile></A>".
NOTE: The commands must not change the current
buffer, jump to another buffer or delete a
buffer. *<A NAME="E246"></A><B>E246</B>* *<A NAME="E811"></A><B>E811</B>*
NOTE: This event never nests, to avoid an
endless loop. This means that while executing
commands for the <A HREF="#FileChangedShell">FileChangedShell</A> event no
other <A HREF="#FileChangedShell">FileChangedShell</A> event will be
triggered.
*<A NAME="FileChangedShellPost"></A><B>FileChangedShellPost</B>*
<A HREF="#FileChangedShellPost">FileChangedShellPost</A> After handling a file that was changed outside
of Vim. Can be used to update the statusline.
*<A NAME="FileEncoding"></A><B>FileEncoding</B>*
<A HREF="#FileEncoding">FileEncoding</A> Obsolete. It still works and is equivalent
to |<A HREF="#EncodingChanged">EncodingChanged</A>|.
*<A NAME="FileReadCmd"></A><B>FileReadCmd</B>*
<A HREF="#FileReadCmd">FileReadCmd</A> Before reading a file with a "<A HREF="insert.html#:read">:read</A>" command.
Should <A HREF="diff.html#do">do</A> the reading of the file. |<A HREF="#Cmd-event">Cmd-event</A>|
*<A NAME="FileReadPost"></A><B>FileReadPost</B>*
<A HREF="#FileReadPost">FileReadPost</A> After reading a file with a "<A HREF="insert.html#:read">:read</A>" command.
Note that Vim sets the <A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A> marks to the
first and last line of the read. This can be
used to operate on the lines just read.
*<A NAME="FileReadPre"></A><B>FileReadPre</B>*
<A HREF="#FileReadPre">FileReadPre</A> Before reading a file with a "<A HREF="insert.html#:read">:read</A>" command.
*<A NAME="FileType"></A><B>FileType</B>*
<A HREF="#FileType">FileType</A> When the <A HREF="options.html#'filetype'">'filetype'</A> option has been set. The
<A HREF="pattern.html#pattern">pattern</A> is matched against the <A HREF="filetype.html#filetype">filetype</A>.
<A HREF="cmdline.html#<afile>"><afile></A> can be used for the name of the file
where this option was set, and <A HREF="cmdline.html#<amatch>"><amatch></A> for
the new value of <A HREF="options.html#'filetype'">'filetype'</A>. Navigating to
another <A HREF="windows.html#window">window</A> or buffer is not allowed.
See |<A HREF="filetype.html#filetypes">filetypes</A>|.
*<A NAME="FileWriteCmd"></A><B>FileWriteCmd</B>*
<A HREF="#FileWriteCmd">FileWriteCmd</A> Before <A HREF="editing.html#writing">writing</A> to a file, when not <A HREF="editing.html#writing">writing</A> the
whole buffer. Should <A HREF="diff.html#do">do</A> the <A HREF="editing.html#writing">writing</A> to the
file. Should not change the buffer. Use the
<A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A> marks for the range of lines.
|<A HREF="#Cmd-event">Cmd-event</A>|
*<A NAME="FileWritePost"></A><B>FileWritePost</B>*
<A HREF="#FileWritePost">FileWritePost</A> After <A HREF="editing.html#writing">writing</A> to a file, when not <A HREF="editing.html#writing">writing</A> the
whole buffer.
*<A NAME="FileWritePre"></A><B>FileWritePre</B>*
<A HREF="#FileWritePre">FileWritePre</A> Before <A HREF="editing.html#writing">writing</A> to a file, when not <A HREF="editing.html#writing">writing</A> the
whole buffer. Use the <A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A> marks for the
range of lines.
*<A NAME="FilterReadPost"></A><B>FilterReadPost</B>*
<A HREF="#FilterReadPost">FilterReadPost</A> After reading a file from a <A HREF="change.html#filter">filter</A> command.
Vim checks the <A HREF="pattern.html#pattern">pattern</A> against the name of
the current buffer <A HREF="motion.html#as">as</A> with <A HREF="#FilterReadPre">FilterReadPre</A>.
Not triggered when <A HREF="options.html#'shelltemp'">'shelltemp'</A> is off.
*<A NAME="FilterReadPre"></A><B>FilterReadPre</B>* *<A NAME="E135"></A><B>E135</B>*
<A HREF="#FilterReadPre">FilterReadPre</A> Before reading a file from a <A HREF="change.html#filter">filter</A> command.
Vim checks the <A HREF="pattern.html#pattern">pattern</A> against the name of
the current buffer, not the name of the
temporary file that is the output of the
<A HREF="change.html#filter">filter</A> command.
Not triggered when <A HREF="options.html#'shelltemp'">'shelltemp'</A> is off.
*<A NAME="FilterWritePost"></A><B>FilterWritePost</B>*
<A HREF="#FilterWritePost">FilterWritePost</A> After <A HREF="editing.html#writing">writing</A> a file for a <A HREF="change.html#filter">filter</A> command or
making a <A HREF="diff.html#diff">diff</A>.
Vim checks the <A HREF="pattern.html#pattern">pattern</A> against the name of
the current buffer <A HREF="motion.html#as">as</A> with <A HREF="#FilterWritePre">FilterWritePre</A>.
Not triggered when <A HREF="options.html#'shelltemp'">'shelltemp'</A> is off.
*<A NAME="FilterWritePre"></A><B>FilterWritePre</B>*
<A HREF="#FilterWritePre">FilterWritePre</A> Before <A HREF="editing.html#writing">writing</A> a file for a <A HREF="change.html#filter">filter</A> command or
making a <A HREF="diff.html#diff">diff</A>.
Vim checks the <A HREF="pattern.html#pattern">pattern</A> against the name of
the current buffer, not the name of the
temporary file that is the output of the
<A HREF="change.html#filter">filter</A> command.
Not triggered when <A HREF="options.html#'shelltemp'">'shelltemp'</A> is off.
*<A NAME="FocusGained"></A><B>FocusGained</B>*
<A HREF="#FocusGained">FocusGained</A> When Vim got input focus. Only for the <A HREF="gui.html#GUI">GUI</A>
version and a few console versions where this
can be detected.
*<A NAME="FocusLost"></A><B>FocusLost</B>*
<A HREF="#FocusLost">FocusLost</A> When Vim lost input focus. Only for the <A HREF="gui.html#GUI">GUI</A>
version and a few console versions where this
can be detected. May also happen when a
<A HREF="gui_w32.html#dialog">dialog</A> pops up.
*<A NAME="FuncUndefined"></A><B>FuncUndefined</B>*
<A HREF="#FuncUndefined">FuncUndefined</A> When a user function is used but <A HREF="motion.html#it">it</A> isn't
defined. Useful for defining a function only
when it's used. The <A HREF="pattern.html#pattern">pattern</A> is matched
against the function name. Both <A HREF="cmdline.html#<amatch>"><amatch></A> and
<A HREF="cmdline.html#<afile>"><afile></A> are set to the name of the function.
NOTE: When <A HREF="editing.html#writing">writing</A> Vim scripts a better
alternative is to use an autoloaded function.
See |<A HREF="eval.html#autoload-functions">autoload-functions</A>|.
*<A NAME="GUIEnter"></A><B>GUIEnter</B>*
<A HREF="#GUIEnter">GUIEnter</A> After starting the <A HREF="gui.html#GUI">GUI</A> successfully, and after
opening the <A HREF="windows.html#window">window</A>. It is triggered before
<A HREF="#VimEnter">VimEnter</A> when using <A HREF="starting.html#gvim">gvim</A>. Can be used to
position the <A HREF="windows.html#window">window</A> from a <A HREF="gui.html#.gvimrc">.gvimrc</A> file:
<B> :autocmd GUIEnter * winpos 100 50</B>
*<A NAME="GUIFailed"></A><B>GUIFailed</B>*
<A HREF="#GUIFailed">GUIFailed</A> After starting the <A HREF="gui.html#GUI">GUI</A> failed. Vim may
continue to run in the <A HREF="terminal.html#terminal">terminal</A>, if possible
(only on <A HREF="os_unix.html#Unix">Unix</A> and alikes, when connecting the
X server fails). You may want to quit Vim:
<B> :autocmd GUIFailed * qall</B>
*<A NAME="InsertChange"></A><B>InsertChange</B>*
<A HREF="#InsertChange">InsertChange</A> When typing <A HREF="insert.html#<Insert>"><Insert></A> while in <A HREF="insert.html#Insert">Insert</A> or
<A HREF="insert.html#Replace">Replace</A> mode. The |<A HREF="eval.html#v:insertmode">v:insertmode</A>| variable
indicates the new mode.
Be careful not to move the cursor or <A HREF="diff.html#do">do</A>
anything else that the user does not expect.
*<A NAME="InsertCharPre"></A><B>InsertCharPre</B>*
<A HREF="#InsertCharPre">InsertCharPre</A> When a character is typed in <A HREF="insert.html#Insert">Insert</A> mode,
before <A HREF="insert.html#inserting">inserting</A> the char.
The |<A HREF="eval.html#v:char">v:char</A>| variable indicates the char typed
and can be changed during the event to insert
a different character. When |<A HREF="eval.html#v:char">v:char</A>| is set
to more than one character this text is
inserted literally.
It is not allowed to change the text |<A HREF="eval.html#textlock">textlock</A>|.
The event is not triggered when <A HREF="options.html#'paste'">'paste'</A> is
set.
*<A NAME="InsertEnter"></A><B>InsertEnter</B>*
<A HREF="#InsertEnter">InsertEnter</A> Just before starting <A HREF="insert.html#Insert">Insert</A> mode. Also for
<A HREF="insert.html#Replace">Replace</A> mode and Virtual <A HREF="insert.html#Replace">Replace</A> mode. The
|<A HREF="eval.html#v:insertmode">v:insertmode</A>| variable indicates the mode.
Be careful not to <A HREF="diff.html#do">do</A> anything else that the
user does not expect.
The cursor is restored afterwards. If you <A HREF="diff.html#do">do</A>
not want that set |<A HREF="eval.html#v:char">v:char</A>| to a non-empty
<A HREF="eval.html#string">string</A>.
*<A NAME="InsertLeave"></A><B>InsertLeave</B>*
<A HREF="#InsertLeave">InsertLeave</A> When leaving <A HREF="insert.html#Insert">Insert</A> mode. Also when using
CTRL-O |<A HREF="insert.html#i_CTRL-O">i_CTRL-O</A>|. But not for |<A HREF="insert.html#i_CTRL-C">i_CTRL-C</A>|.
*<A NAME="MenuPopup"></A><B>MenuPopup</B>*
<A HREF="#MenuPopup">MenuPopup</A> Just before showing the popup menu (under the
right mouse button). Useful for adjusting the
menu for what is under the cursor or mouse
pointer.
The <A HREF="pattern.html#pattern">pattern</A> is matched against a single
character representing the mode:
<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>
<A HREF="insert.html#o">o</A> <A HREF="intro.html#Operator-pending">Operator-pending</A>
<A HREF="insert.html#i">i</A> <A HREF="insert.html#Insert">Insert</A>
<A HREF="change.html#c">c</A> Command line
*<A NAME="OptionSet"></A><B>OptionSet</B>*
<A HREF="#OptionSet">OptionSet</A> After setting an option. The <A HREF="pattern.html#pattern">pattern</A> is
matched against the long option name.
The |<A HREF="eval.html#v:option_old">v:option_old</A>| variable indicates the
old option value, |<A HREF="eval.html#v:option_new">v:option_new</A>| variable
indicates the newly set value, the
|<A HREF="eval.html#v:option_type">v:option_type</A>| variable indicates whether
it's global or local scoped and |<A HREF="cmdline.html#<amatch>"><amatch></A>|
indicates what option has been set.
Is not triggered on <A HREF="starting.html#startup">startup</A> and for the <A HREF="options.html#'key'">'key'</A>
option for obvious reasons.
Usage example: Check for the existence of the
directory in the <A HREF="options.html#'backupdir'">'backupdir'</A> and <A HREF="options.html#'undodir'">'undodir'</A>
<A HREF="options.html#options">options</A>, create the directory if <A HREF="motion.html#it">it</A> doesn't
exist yet.
Note: It's a bad idea to reset an option
during this <A HREF="#autocommand">autocommand</A>, this may break a
<A HREF="usr_05.html#plugin">plugin</A>. You can always use `:noa` to prevent
triggering this <A HREF="#autocommand">autocommand</A>.
*<A NAME="QuickFixCmdPre"></A><B>QuickFixCmdPre</B>*
<A HREF="#QuickFixCmdPre">QuickFixCmdPre</A> Before a <A HREF="quickfix.html#quickfix">quickfix</A> command is run (|<A HREF="quickfix.html#:make">:make</A>|,
|<A HREF="quickfix.html#:lmake">:lmake</A>|, |<A HREF="quickfix.html#:grep">:grep</A>|, |<A HREF="quickfix.html#:lgrep">:lgrep</A>|, |<A HREF="quickfix.html#:grepadd">:grepadd</A>|,
|<A HREF="quickfix.html#:lgrepadd">:lgrepadd</A>|, |<A HREF="quickfix.html#:vimgrep">:vimgrep</A>|, |<A HREF="quickfix.html#:lvimgrep">:lvimgrep</A>|,
|<A HREF="quickfix.html#:vimgrepadd">:vimgrepadd</A>|, |<A HREF="quickfix.html#:lvimgrepadd">:lvimgrepadd</A>|, |<A HREF="if_cscop.html#:cscope">:cscope</A>|,
|<A HREF="quickfix.html#:cfile">:cfile</A>|, |<A HREF="quickfix.html#:cgetfile">:cgetfile</A>|, |<A HREF="quickfix.html#:caddfile">:caddfile</A>|, |<A HREF="quickfix.html#:lfile">:lfile</A>|,
|<A HREF="quickfix.html#:lgetfile">:lgetfile</A>|, |<A HREF="quickfix.html#:laddfile">:laddfile</A>|, |<A HREF="helphelp.html#:helpgrep">:helpgrep</A>|,
|<A HREF="helphelp.html#:lhelpgrep">:lhelpgrep</A>|, |<A HREF="quickfix.html#:cexpr">:cexpr</A>|, |<A HREF="quickfix.html#:cgetexpr">:cgetexpr</A>|,
|<A HREF="quickfix.html#:caddexpr">:caddexpr</A>|, |<A HREF="quickfix.html#:cbuffer">:cbuffer</A>|, |<A HREF="quickfix.html#:cgetbuffer">:cgetbuffer</A>|,
|<A HREF="quickfix.html#:caddbuffer">:caddbuffer</A>|).
The <A HREF="pattern.html#pattern">pattern</A> is matched against the command
being run. When |<A HREF="quickfix.html#:grep">:grep</A>| is used but <A HREF="options.html#'grepprg'">'grepprg'</A>
is set to "internal" <A HREF="motion.html#it">it</A> still matches "<A HREF="quickfix.html#grep">grep</A>".
This command cannot be used to set the
<A HREF="options.html#'makeprg'">'makeprg'</A> and <A HREF="options.html#'grepprg'">'grepprg'</A> <A HREF="eval.html#variables">variables</A>.
If this command causes an error, the <A HREF="quickfix.html#quickfix">quickfix</A>
command is not executed.
*<A NAME="QuickFixCmdPost"></A><B>QuickFixCmdPost</B>*
<A HREF="#QuickFixCmdPost">QuickFixCmdPost</A> Like <A HREF="#QuickFixCmdPre">QuickFixCmdPre</A>, but after a <A HREF="quickfix.html#quickfix">quickfix</A>
command is run, before jumping to the first
location. For |<A HREF="quickfix.html#:cfile">:cfile</A>| and |<A HREF="quickfix.html#:lfile">:lfile</A>| commands
<A HREF="motion.html#it">it</A> is run after error file is read and before
moving to the first error.
See |<A HREF="quickfix.html#QuickFixCmdPost-example">QuickFixCmdPost-example</A>|.
*<A NAME="QuitPre"></A><B>QuitPre</B>*
<A HREF="#QuitPre">QuitPre</A> When using `:quit`, `:wq` or `:qall`, before
deciding whether <A HREF="motion.html#it">it</A> closes the current <A HREF="windows.html#window">window</A>
or quits Vim. Can be used to close any
non-essential <A HREF="windows.html#window">window</A> if the current <A HREF="windows.html#window">window</A> is
the last ordinary <A HREF="windows.html#window">window</A>.
*<A NAME="RemoteReply"></A><B>RemoteReply</B>*
<A HREF="#RemoteReply">RemoteReply</A> When a reply from a Vim that <A HREF="eval.html#functions">functions</A> <A HREF="motion.html#as">as</A>
server was received |<A HREF="eval.html#server2client()">server2client()</A>|. The
<A HREF="pattern.html#pattern">pattern</A> is matched against the {serverid}.
<A HREF="cmdline.html#<amatch>"><amatch></A> is equal to the {serverid} from which
the reply was sent, and <A HREF="cmdline.html#<afile>"><afile></A> is the actual
reply <A HREF="eval.html#string">string</A>.
Note that even if an <A HREF="#autocommand">autocommand</A> is defined,
the reply should be read with |<A HREF="eval.html#remote_read()">remote_read()</A>|
to consume <A HREF="motion.html#it">it</A>.
*<A NAME="SessionLoadPost"></A><B>SessionLoadPost</B>*
<A HREF="#SessionLoadPost">SessionLoadPost</A> After loading the session file created using
the |<A HREF="starting.html#:mksession">:mksession</A>| command.
*<A NAME="ShellCmdPost"></A><B>ShellCmdPost</B>*
<A HREF="#ShellCmdPost">ShellCmdPost</A> After executing a shell command with |<A HREF="various.html#:!cmd">:!cmd</A>|,
|<A HREF="various.html#:shell">:shell</A>|, |<A HREF="quickfix.html#:make">:make</A>| and |<A HREF="quickfix.html#:grep">:grep</A>|. Can be used to
check for any changed files.
*<A NAME="ShellFilterPost"></A><B>ShellFilterPost</B>*
<A HREF="#ShellFilterPost">ShellFilterPost</A> After executing a shell command with
":{range}!cmd", "<A HREF="editing.html#:w">:w</A> !cmd" or "<A HREF="insert.html#:r">:r</A> !cmd".
Can be used to check for any changed files.
*<A NAME="SourcePre"></A><B>SourcePre</B>*
<A HREF="#SourcePre">SourcePre</A> Before sourcing a Vim <A HREF="usr_41.html#script">script</A>. |<A HREF="repeat.html#:source">:source</A>|
<A HREF="cmdline.html#<afile>"><afile></A> is the name of the file being sourced.
*<A NAME="SourceCmd"></A><B>SourceCmd</B>*
<A HREF="#SourceCmd">SourceCmd</A> When sourcing a Vim <A HREF="usr_41.html#script">script</A>. |<A HREF="repeat.html#:source">:source</A>|
<A HREF="cmdline.html#<afile>"><afile></A> is the name of the file being sourced.
The <A HREF="#autocommand">autocommand</A> must source this file.
|<A HREF="#Cmd-event">Cmd-event</A>|
*<A NAME="SpellFileMissing"></A><B>SpellFileMissing</B>*
<A HREF="#SpellFileMissing">SpellFileMissing</A> When trying to load a <A HREF="spell.html#spell">spell</A> checking file and
<A HREF="motion.html#it">it</A> can't be found. The <A HREF="pattern.html#pattern">pattern</A> is matched
against the language. <A HREF="cmdline.html#<amatch>"><amatch></A> is the
language, <A HREF="options.html#'encoding'">'encoding'</A> also matters. See
|<A HREF="spell.html#spell-SpellFileMissing">spell-SpellFileMissing</A>|.
*<A NAME="StdinReadPost"></A><B>StdinReadPost</B>*
<A HREF="#StdinReadPost">StdinReadPost</A> After reading from the stdin into the buffer,
before executing the modelines. Only used
when the "<A HREF="motion.html#-">-</A>" argument was used when Vim was
started |<A HREF="starting.html#--">--</A>|.
*<A NAME="StdinReadPre"></A><B>StdinReadPre</B>*
<A HREF="#StdinReadPre">StdinReadPre</A> Before reading from stdin into the buffer.
Only used when the "<A HREF="motion.html#-">-</A>" argument was used when
Vim was started |<A HREF="starting.html#--">--</A>|.
*<A NAME="SwapExists"></A><B>SwapExists</B>*
<A HREF="#SwapExists">SwapExists</A> Detected an existing swap file when starting
to edit a file. Only when <A HREF="motion.html#it">it</A> is possible to
select a way to handle the situation, when Vim
would ask the user what to <A HREF="diff.html#do">do</A>.
The |<A HREF="eval.html#v:swapname">v:swapname</A>| variable holds the name of
the swap file found, <A HREF="cmdline.html#<afile>"><afile></A> the file being
edited. |<A HREF="eval.html#v:swapcommand">v:swapcommand</A>| may contain a command
to be executed in the opened file.
The commands should set the |<A HREF="eval.html#v:swapchoice">v:swapchoice</A>|
variable to a <A HREF="eval.html#string">string</A> with one character to
tell Vim what should be done next:
'<A HREF="insert.html#o">o</A>' open read-only
'<A HREF="motion.html#e">e</A>' edit the file anyway
'<A HREF="change.html#r">r</A>' recover
'<A HREF="change.html#d">d</A>' delete the swap file
'<A HREF="repeat.html#q">q</A>' quit, don't edit the file
'<A HREF="insert.html#a">a</A>' abort, like hitting <A HREF="pattern.html#CTRL-C">CTRL-C</A>
When set to an empty <A HREF="eval.html#string">string</A> the user will be
asked, <A HREF="motion.html#as">as</A> if there was no <A HREF="#SwapExists">SwapExists</A> autocmd.
*<A NAME="E812"></A><B>E812</B>*
It is not allowed to change to another buffer,
change a buffer name or change directory
here.
*<A NAME="Syntax"></A><B>Syntax</B>*
<A HREF="#Syntax">Syntax</A> When the <A HREF="options.html#'syntax'">'syntax'</A> option has been set. The
<A HREF="pattern.html#pattern">pattern</A> is matched against the <A HREF="syntax.html#syntax">syntax</A> name.
<A HREF="cmdline.html#<afile>"><afile></A> can be used for the name of the file
where this option was set, and <A HREF="cmdline.html#<amatch>"><amatch></A> for
the new value of <A HREF="options.html#'syntax'">'syntax'</A>.
See |<A HREF="syntax.html#:syn-on">:syn-on</A>|.
*<A NAME="TabClosed"></A><B>TabClosed</B>*
<A HREF="#TabClosed">TabClosed</A> After closing a <A HREF="intro.html#tab">tab</A> page.
*<A NAME="TabEnter"></A><B>TabEnter</B>*
<A HREF="#TabEnter">TabEnter</A> Just after entering a tab page. |<A HREF="tabpage.html#tab-page">tab-page</A>|
After triggering the <A HREF="#WinEnter">WinEnter</A> and before
triggering the <A HREF="#BufEnter">BufEnter</A> event.
*<A NAME="TabLeave"></A><B>TabLeave</B>*
<A HREF="#TabLeave">TabLeave</A> Just before leaving a tab page. |<A HREF="tabpage.html#tab-page">tab-page</A>|
A <A HREF="#WinLeave">WinLeave</A> event will have been triggered
first.
*<A NAME="TabNew"></A><B>TabNew</B>*
<A HREF="#TabNew">TabNew</A> When a tab page was created. |<A HREF="tabpage.html#tab-page">tab-page</A>|
A <A HREF="#WinEnter">WinEnter</A> event will have been triggered
first, <A HREF="#TabEnter">TabEnter</A> follows.
*<A NAME="TermChanged"></A><B>TermChanged</B>*
<A HREF="#TermChanged">TermChanged</A> After the value of <A HREF="options.html#'term'">'term'</A> has changed. Useful
for re-loading the <A HREF="syntax.html#syntax">syntax</A> file to update the
colors, fonts and other terminal-dependent
settings. Executed for all loaded <A HREF="windows.html#buffers">buffers</A>.
*<A NAME="TermResponse"></A><B>TermResponse</B>*
<A HREF="#TermResponse">TermResponse</A> After the response to |<A HREF="term.html#t_RV">t_RV</A>| is received from
the <A HREF="terminal.html#terminal">terminal</A>. The value of |<A HREF="eval.html#v:termresponse">v:termresponse</A>|
can be used to <A HREF="diff.html#do">do</A> things depending on the
<A HREF="terminal.html#terminal">terminal</A> version. Note that this event may be
triggered halfway executing another event,
especially if file I/O, a shell command or
anything else that takes time is involved.
*<A NAME="TextChanged"></A><B>TextChanged</B>*
<A HREF="#TextChanged">TextChanged</A> After a change was made to the text in the
current buffer in <A HREF="intro.html#Normal">Normal</A> mode. That is when
|<A HREF="eval.html#b:changedtick">b:changedtick</A>| has changed.
Not triggered when there is typeahead or when
an <A HREF="motion.html#operator">operator</A> is pending.
Careful: This is triggered very often, don't
<A HREF="diff.html#do">do</A> anything that the user does not expect or
that is slow.
*<A NAME="TextChangedI"></A><B>TextChangedI</B>*
<A HREF="#TextChangedI">TextChangedI</A> After a change was made to the text in the
current buffer in <A HREF="insert.html#Insert">Insert</A> mode.
Not triggered when the popup menu is visible.
Otherwise the same <A HREF="motion.html#as">as</A> <A HREF="#TextChanged">TextChanged</A>.
*<A NAME="TextYankPost"></A><B>TextYankPost</B>*
<A HREF="#TextYankPost">TextYankPost</A> After text has been yanked or deleted in the
current buffer. The following values of
|<A HREF="eval.html#v:event">v:event</A>| can be used to determine the operation
that triggered this autocmd:
<A HREF="motion.html#operator">operator</A> The operation performed.
regcontents Text that was stored in the
<A HREF="sponsor.html#register">register</A>, <A HREF="motion.html#as">as</A> a <A HREF="eval.html#list">list</A> of lines,
like with:
<B> getreg(r, 1, 1)</B>
regname Name of the |<A HREF="sponsor.html#register">register</A>| or
empty <A HREF="eval.html#string">string</A> for the unnamed
<A HREF="sponsor.html#register">register</A>.
regtype Type of the <A HREF="sponsor.html#register">register</A>, see
|<A HREF="eval.html#getregtype()">getregtype()</A>|.
Not triggered when |<A HREF="change.html#quote_">quote_</A>| is used nor when
called recursively.
It is not allowed to change the buffer text,
see |<A HREF="eval.html#textlock">textlock</A>|.
*<A NAME="User"></A><B>User</B>*
<A HREF="#User">User</A> Never executed automatically. To be used for
autocommands that are only executed with
"<A HREF="#:doautocmd">:doautocmd</A>".
*<A NAME="UserGettingBored"></A><B>UserGettingBored</B>*
<A HREF="#UserGettingBored">UserGettingBored</A> When the user presses the same key <A HREF="usr_42.html#42">42</A> times.
Just kidding! :-)
*<A NAME="VimEnter"></A><B>VimEnter</B>*
<A HREF="#VimEnter">VimEnter</A> After doing all the <A HREF="starting.html#startup">startup</A> stuff, including
loading <A HREF="starting.html#.vimrc">.vimrc</A> files, executing the "<A HREF="starting.html#-c">-c</A> cmd"
arguments, creating all <A HREF="windows.html#windows">windows</A> and loading
the <A HREF="windows.html#buffers">buffers</A> in them.
Just before this event is triggered the
|<A HREF="eval.html#v:vim_did_enter">v:vim_did_enter</A>| variable is set, so that you
can <A HREF="diff.html#do">do</A>:
<B> if v:vim_did_enter</B>
<B> call s:init()</B>
<B> else</B>
<B> au VimEnter * call s:init()</B>
<B> endif</B>
*<A NAME="VimLeave"></A><B>VimLeave</B>*
<A HREF="#VimLeave">VimLeave</A> Before <A HREF="starting.html#exiting">exiting</A> Vim, just after <A HREF="editing.html#writing">writing</A> the
.viminfo file. Executed only once, like
<A HREF="#VimLeavePre">VimLeavePre</A>.
To detect an abnormal exit use |<A HREF="eval.html#v:dying">v:dying</A>|.
When <A HREF="eval.html#v:dying">v:dying</A> is 2 or more this event is not
triggered.
*<A NAME="VimLeavePre"></A><B>VimLeavePre</B>*
<A HREF="#VimLeavePre">VimLeavePre</A> Before <A HREF="starting.html#exiting">exiting</A> Vim, just before <A HREF="editing.html#writing">writing</A> the
.viminfo file. This is executed only once,
if there is a match with the name of what
happens to be the current buffer when <A HREF="starting.html#exiting">exiting</A>.
Mostly useful with a "*" <A HREF="pattern.html#pattern">pattern</A>.
<B> :autocmd VimLeavePre * call CleanupStuff()</B>
To detect an abnormal exit use |<A HREF="eval.html#v:dying">v:dying</A>|.
When <A HREF="eval.html#v:dying">v:dying</A> is 2 or more this event is not
triggered.
*<A NAME="VimResized"></A><B>VimResized</B>*
<A HREF="#VimResized">VimResized</A> After the Vim <A HREF="windows.html#window">window</A> was resized, thus <A HREF="options.html#'lines'">'lines'</A>
and/or <A HREF="options.html#'columns'">'columns'</A> changed. Not when starting
up though.
*<A NAME="WinEnter"></A><B>WinEnter</B>*
<A HREF="#WinEnter">WinEnter</A> After entering another <A HREF="windows.html#window">window</A>. Not done for
the first <A HREF="windows.html#window">window</A>, when Vim has just started.
Useful for setting the <A HREF="windows.html#window">window</A> height.
If the <A HREF="windows.html#window">window</A> is for another buffer, Vim
executes the <A HREF="#BufEnter">BufEnter</A> autocommands after the
<A HREF="#WinEnter">WinEnter</A> autocommands.
Note: When using "<A HREF="windows.html#:split">:split</A> fname" the <A HREF="#WinEnter">WinEnter</A>
event is triggered after the split but before
the file "fname" is loaded.
*<A NAME="WinLeave"></A><B>WinLeave</B>*
<A HREF="#WinLeave">WinLeave</A> Before leaving a <A HREF="windows.html#window">window</A>. If the <A HREF="windows.html#window">window</A> to be
entered next is for a different buffer, Vim
executes the <A HREF="#BufLeave">BufLeave</A> autocommands before the
<A HREF="#WinLeave">WinLeave</A> autocommands (but not for ":new").
Not used for "<A HREF="editing.html#:qa">:qa</A>" or "<A HREF="editing.html#:q">:q</A>" when <A HREF="starting.html#exiting">exiting</A> Vim.
*<A NAME="WinNew"></A><B>WinNew</B>*
<A HREF="#WinNew">WinNew</A> When a new <A HREF="windows.html#window">window</A> was created. Not done for
the first <A HREF="windows.html#window">window</A>, when Vim has just started.
Before a <A HREF="#WinEnter">WinEnter</A> event.
==============================================================================
6. Patterns *<A NAME="autocmd-patterns"></A><B>autocmd-patterns</B>* *<A NAME="{pat}"></A><B>{pat}</B>*
The <A HREF="#{pat}">{pat}</A> argument can be a comma separated <A HREF="eval.html#list">list</A>. This works <A HREF="motion.html#as">as</A> if the
command was given with each <A HREF="pattern.html#pattern">pattern</A> separately. Thus this command:
<B> :autocmd BufRead *.txt,*.info set et</B>
Is equivalent to:
<B> :autocmd BufRead *.txt set et</B>
<B> :autocmd BufRead *.info set et</B>
The file <A HREF="pattern.html#pattern">pattern</A> <A HREF="#{pat}">{pat}</A> is tested for a match against the file name in one of
two ways:
1. When there is no '<A HREF="pattern.html#/">/</A>' in the <A HREF="pattern.html#pattern">pattern</A>, Vim checks for a match against only
the tail part of the file name (without its leading directory path).
2. When there is a '<A HREF="pattern.html#/">/</A>' in the <A HREF="pattern.html#pattern">pattern</A>, Vim checks for a match against both the
short file name (as you typed <A HREF="motion.html#it">it</A>) and the full file name (after expanding
<A HREF="motion.html#it">it</A> to a full path and resolving symbolic links).
The special <A HREF="pattern.html#pattern">pattern</A> <buffer> or <A HREF="#<buffer=N>"><buffer=N></A> is used for buffer-local
autocommands |<A HREF="#autocmd-buflocal">autocmd-buflocal</A>|. This <A HREF="pattern.html#pattern">pattern</A> is not matched against the name
of a buffer.
Examples:
<B> :autocmd BufRead *.txt set et</B>
Set the <A HREF="options.html#'et'">'et'</A> option for all text files.
<B> :autocmd BufRead /vim/src/*.c set cindent</B>
Set the <A HREF="options.html#'cindent'">'cindent'</A> option for C files in the /vim/src directory.
<B> :autocmd BufRead /tmp/*.c set ts=5</B>
If you have a link from "/tmp/test.c" to "/home/nobody/vim/src/test.c", and
you start editing "/tmp/test.c", this <A HREF="#autocommand">autocommand</A> will match.
Note: To match part of a path, but not from the root directory, use a '*' <A HREF="motion.html#as">as</A>
the first character. Example:
<B> :autocmd BufRead */doc/*.txt set tw=78</B>
This <A HREF="#autocommand">autocommand</A> will for example be executed for "/tmp/doc/xx.txt" and
"/usr/home/piet/doc/yy.txt". The number of directories does not matter here.
The file name that the <A HREF="pattern.html#pattern">pattern</A> is matched against is after expanding
<A HREF="editing.html#wildcards">wildcards</A>. Thus if you issue this command:
<B> :e $ROOTDIR/main.$EXT</B>
The argument is first expanded to:
<B> /usr/root/main.py</B>
Before it's matched with the <A HREF="pattern.html#pattern">pattern</A> of the <A HREF="#autocommand">autocommand</A>. Careful with this
when using events like <A HREF="#FileReadCmd">FileReadCmd</A>, the value of <A HREF="cmdline.html#<amatch>"><amatch></A> may not be what you
expect.
Environment <A HREF="eval.html#variables">variables</A> can be used in a <A HREF="pattern.html#pattern">pattern</A>:
<B> :autocmd BufRead $VIMRUNTIME/doc/*.txt set expandtab</B>
And ~ can be used for the home directory (if <A HREF="options.html#$HOME">$HOME</A> is defined):
<B> :autocmd BufWritePost ~/.vimrc so ~/.vimrc</B>
<B> :autocmd BufRead ~archive/* set readonly</B>
The environment variable is expanded when the <A HREF="#autocommand">autocommand</A> is defined, not when
the <A HREF="#autocommand">autocommand</A> is executed. This is different from the command!
*<A NAME="file-pattern"></A><B>file-pattern</B>*
The <A HREF="pattern.html#pattern">pattern</A> is interpreted like mostly used in file names:
* matches any sequence of characters; Unusual: includes path
separators
? matches any single character
\? matches a '<A HREF="pattern.html#?">?</A>'
. matches a '<A HREF="repeat.html#.">.</A>'
~ matches a '<A HREF="change.html#~">~</A>'
, separates patterns
\, matches a '<A HREF="motion.html#,">,</A>'
{ } like \( \) in a |<A HREF="pattern.html#pattern">pattern</A>|
, inside { }: like \| in a |pattern||||
\} literal }
\{ literal {
\\\{n,m\} like \{n,m} in a |<A HREF="pattern.html#pattern">pattern</A>|
\ special meaning like in a |<A HREF="pattern.html#pattern">pattern</A>|
[ch] matches '<A HREF="change.html#c">c</A>' or '<A HREF="motion.html#h">h</A>'
[^ch] match any character but '<A HREF="change.html#c">c</A>' and '<A HREF="motion.html#h">h</A>'
Note that for all systems the '<A HREF="pattern.html#/">/</A>' character is used for path separator (even
<A HREF="os_msdos.html#MS-DOS">MS-DOS</A> and <A HREF="os_os2.html#OS/2">OS/2</A>). This was done because the <A HREF="intro.html#backslash">backslash</A> is difficult to use
in a <A HREF="pattern.html#pattern">pattern</A> and to make the autocommands portable across different systems.
It is possible to use |<A HREF="pattern.html#pattern">pattern</A>| items, but they may not work <A HREF="motion.html#as">as</A> expected,
because of the translation done for the above.
*<A NAME="autocmd-changes"></A><B>autocmd-changes</B>*
Matching with the <A HREF="pattern.html#pattern">pattern</A> is done when an event is triggered. Changing the
buffer name in one of the autocommands, or even <A HREF="change.html#deleting">deleting</A> the buffer, does not
change which autocommands will be executed. Example:
<B> au BufEnter *.foo bdel</B>
<B> au BufEnter *.foo set modified</B>
This will delete the current buffer and then set <A HREF="options.html#'modified'">'modified'</A> in what has become
the current buffer instead. Vim doesn't take into account that "*.foo"
doesn't match with that buffer name. It matches "*.foo" with the name of the
buffer at the moment the event was triggered.
However, buffer-local autocommands will not be executed for a buffer that has
been wiped out with |<A HREF="windows.html#:bwipe">:bwipe</A>|. After <A HREF="change.html#deleting">deleting</A> the buffer with |<A HREF="windows.html#:bdel">:bdel</A>| the
buffer actually still exists (it becomes unlisted), thus the autocommands are
still executed.
==============================================================================
7. Buffer-local autocommands *<A NAME="autocmd-buflocal"></A><B>autocmd-buflocal</B>* *<A NAME="autocmd-buffer-local"></A><B>autocmd-buffer-local</B>*
*<A NAME="<buffer=N>"></A><B><buffer=N></B>* *<A NAME="<buffer=abuf>"></A><B><buffer=abuf></B>* *<A NAME="E680"></A><B>E680</B>*
Buffer-local autocommands are attached to a specific buffer. They are useful
if the buffer does not have a name and when the name does not match a specific
<A HREF="pattern.html#pattern">pattern</A>. But <A HREF="motion.html#it">it</A> also means they must be explicitly added to each buffer.
Instead of a <A HREF="pattern.html#pattern">pattern</A> buffer-local autocommands use one of these forms:
<buffer> current buffer
<buffer=99> buffer number 99
<A HREF="#<buffer=abuf>"><buffer=abuf></A> using <A HREF="cmdline.html#<abuf>"><abuf></A> (only when executing autocommands)
|<A HREF="cmdline.html#<abuf>"><abuf></A>|
Examples:
<B> :au CursorHold <buffer> echo 'hold'</B>
<B> :au CursorHold <buffer=33> echo 'hold'</B>
<B> :au BufNewFile * au CursorHold <buffer=abuf> echo 'hold'</B>
All the commands for autocommands also work with buffer-local autocommands,
simply use the special <A HREF="eval.html#string">string</A> instead of the <A HREF="pattern.html#pattern">pattern</A>. Examples:
<B> :au! * <buffer> " remove buffer-local autocommands for</B>
<B> " current buffer</B>
<B> :au! * <buffer=33> " remove buffer-local autocommands for</B>
<B> " buffer #33</B>
<B> :bufdo :au! CursorHold <buffer> " remove autocmd for given event for all</B>
<B> " buffers</B>
<B> :au * <buffer> " list buffer-local autocommands for</B>
<B> " current buffer</B>
Note that when an <A HREF="#autocommand">autocommand</A> is defined for the current buffer, <A HREF="motion.html#it">it</A> is stored
with the buffer number. Thus <A HREF="motion.html#it">it</A> uses the form "<buffer=12>", where 12 is the
number of the current buffer. You will see this when listing autocommands,
for example.
To test for presence of buffer-local autocommands use the |<A HREF="eval.html#exists()">exists()</A>| function
<A HREF="motion.html#as">as</A> follows:
<B> :if exists("#CursorHold#<buffer=12>") | ... | endif</B>
<B> :if exists("#CursorHold#<buffer>") | ... | endif " for current buffer</B>
When a buffer is wiped out its buffer-local autocommands are also gone, of
course. Note that when <A HREF="change.html#deleting">deleting</A> a buffer, e.g., with "<A HREF="windows.html#:bdel">:bdel</A>", <A HREF="motion.html#it">it</A> is only
unlisted, the autocommands are still present. In order to see the removal of
buffer-local autocommands:
<B> :set verbose=6</B>
It is not possible to define buffer-local autocommands for a non-existent
buffer.
==============================================================================
8. Groups *<A NAME="autocmd-groups"></A><B>autocmd-groups</B>*
Autocommands can be put together in a group. This is useful for removing or
executing a group of autocommands. For example, all the autocommands for
<A HREF="syntax.html#syntax">syntax</A> highlighting are put in the "highlight" group, to be able to execute
"<A HREF="#:doautoall">:doautoall</A> highlight BufRead" when the <A HREF="gui.html#GUI">GUI</A> starts.
When no specific group is selected, Vim uses the default group. The default
group does not have a name. You cannot execute the autocommands from the
default group separately; you can execute them only by executing autocommands
for all groups.
Normally, when executing autocommands automatically, Vim uses the autocommands
for all groups. The group only matters when executing autocommands with
"<A HREF="#:doautocmd">:doautocmd</A>" or "<A HREF="#:doautoall">:doautoall</A>", or when defining or <A HREF="change.html#deleting">deleting</A> autocommands.
The group name can contain any characters except white space. The group name
"end" is reserved (also in <A HREF="change.html#uppercase">uppercase</A>).
The group name is <A HREF="change.html#case">case</A> sensitive. Note that this is different from the event
name!
*<A NAME=":aug"></A><B>:aug</B>* *<A NAME=":augroup"></A><B>:augroup</B>*
:aug[roup] {name} Define the autocmd group name for the
following "<A HREF="#:autocmd">:autocmd</A>" commands. The name "end"
or "END" selects the default group.
To avoid confusion, the name should be
different from existing <A HREF="#{event}">{event}</A> names, <A HREF="motion.html#as">as</A> this
most likely will not <A HREF="diff.html#do">do</A> what you intended.
*<A NAME=":augroup-delete"></A><B>:augroup-delete</B>* *<A NAME="E367"></A><B>E367</B>* *<A NAME="W19"></A><B>W19</B>* *<A NAME="E936"></A><B>E936</B>*
:aug[roup]! {name} Delete the autocmd group {name}. Don't use
this if there is still an <A HREF="#autocommand">autocommand</A> using
this group! You will get a warning if doing
<A HREF="motion.html#it">it</A> anyway. when the group is the current group
you will get error <A HREF="#E936">E936</A>.
To enter autocommands for a specific group, use this method:
1. <A HREF="visual.html#Select">Select</A> the group with "<A HREF="#:augroup">:augroup</A> {name}".
2. Delete any old autocommands with ":au!".
3. Define the autocommands.
4. Go back to the default group with "augroup END".
Example:
<B> :augroup uncompress</B>
<B> : au!</B>
<B> : au BufEnter *.gz %!gunzip</B>
<B> :augroup END</B>
This prevents having the autocommands defined <A HREF="if_cscop.html#twice">twice</A> (e.g., after sourcing the
<A HREF="starting.html#.vimrc">.vimrc</A> file again).
==============================================================================
9. Executing autocommands *<A NAME="autocmd-execute"></A><B>autocmd-execute</B>*
Vim can also execute Autocommands non-automatically. This is useful if you
have changed autocommands, or when Vim has executed the wrong autocommands
(e.g., the file <A HREF="pattern.html#pattern">pattern</A> match was wrong).
Note that the <A HREF="options.html#'eventignore'">'eventignore'</A> option applies here too. Events listed in this
option will not cause any commands to be executed.
*<A NAME=":do"></A><B>:do</B>* *<A NAME=":doau"></A><B>:doau</B>* *<A NAME=":doautocmd"></A><B>:doautocmd</B>* *<A NAME="E217"></A><B>E217</B>*
:do[autocmd] [<nomodeline>] [group] <A HREF="#{event}">{event}</A> [fname]
Apply the autocommands matching [fname] (default:
current file name) for <A HREF="#{event}">{event}</A> to the current buffer.
You can use this when the current file name does not
match the right <A HREF="pattern.html#pattern">pattern</A>, after <A HREF="change.html#changing">changing</A> settings, or
to execute autocommands for a certain event.
It's possible to use this inside an <A HREF="#autocommand">autocommand</A> too,
so you can base the autocommands for one extension on
another extension. Example:
<B> :au BufEnter *.cpp so ~/.vimrc_cpp</B>
<B> :au BufEnter *.cpp doau BufEnter x.c</B>
Be careful to avoid endless loops. See
|<A HREF="#autocmd-nested">autocmd-nested</A>|.
When the [group] argument is not given, Vim executes
the autocommands for all groups. When the [group]
argument is included, Vim executes only the matching
autocommands for that group. Note: if you use an
undefined group name, Vim gives you an error message.
*<A NAME="<nomodeline>"></A><B><nomodeline></B>*
After applying the autocommands the modelines are
processed, so that their settings overrule the
settings from autocommands, like what happens when
editing a file. This is skipped when the <A HREF="#<nomodeline>"><nomodeline></A>
argument is present. You probably want to use
<A HREF="#<nomodeline>"><nomodeline></A> for events that are not used when loading
a buffer, such <A HREF="motion.html#as">as</A> |<A HREF="#User">User</A>|.
Processing modelines is also skipped when no
matching autocommands were executed.
*<A NAME=":doautoa"></A><B>:doautoa</B>* *<A NAME=":doautoall"></A><B>:doautoall</B>*
:doautoa[ll] [<nomodeline>] [group] <A HREF="#{event}">{event}</A> [fname]
Like "<A HREF="#:doautocmd">:doautocmd</A>", but apply the autocommands to each
loaded buffer. Note that [fname] is used to select
the autocommands, not the <A HREF="windows.html#buffers">buffers</A> to which they are
applied.
Careful: Don't use this for autocommands that delete a
buffer, change to another buffer or change the
contents of a buffer; the result is unpredictable.
This command is intended for autocommands that set
<A HREF="options.html#options">options</A>, change highlighting, and things like that.
==============================================================================
10. Using autocommands *<A NAME="autocmd-use"></A><B>autocmd-use</B>*
For WRITING FILES there are four possible sets of events. Vim uses only one
of these sets for a write command:
<A HREF="#BufWriteCmd">BufWriteCmd</A> <A HREF="#BufWritePre">BufWritePre</A> <A HREF="#BufWritePost">BufWritePost</A> <A HREF="editing.html#writing">writing</A> the whole buffer
<A HREF="#FilterWritePre">FilterWritePre</A> <A HREF="#FilterWritePost">FilterWritePost</A> <A HREF="editing.html#writing">writing</A> to <A HREF="change.html#filter">filter</A> temp file
<A HREF="#FileAppendCmd">FileAppendCmd</A> <A HREF="#FileAppendPre">FileAppendPre</A> <A HREF="#FileAppendPost">FileAppendPost</A> appending to a file
<A HREF="#FileWriteCmd">FileWriteCmd</A> <A HREF="#FileWritePre">FileWritePre</A> <A HREF="#FileWritePost">FileWritePost</A> any other file write
When there is a matching "*Cmd" <A HREF="#autocommand">autocommand</A>, <A HREF="motion.html#it">it</A> is assumed <A HREF="motion.html#it">it</A> will <A HREF="diff.html#do">do</A> the
<A HREF="editing.html#writing">writing</A>. No further <A HREF="editing.html#writing">writing</A> is done and the other events are not triggered.
|<A HREF="#Cmd-event">Cmd-event</A>|
Note that the *WritePost commands should <A HREF="undo.html#undo">undo</A> any changes to the buffer that
were caused by the *WritePre commands; otherwise, <A HREF="editing.html#writing">writing</A> the file will have
the side effect of <A HREF="change.html#changing">changing</A> the buffer.
Before executing the autocommands, the buffer from which the lines are to be
written temporarily becomes the current buffer. Unless the autocommands
change the current buffer or delete the previously current buffer, the
previously current buffer is made the current buffer again.
The *WritePre and *AppendPre autocommands must not delete the buffer from
which the lines are to be written.
The <A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A> marks have a special position:
- Before the *ReadPre event the <A HREF="motion.html#'[">'[</A> <A HREF="motion.html#mark">mark</A> is set to the line just above where
the new lines will be inserted.
- Before the *ReadPost event the <A HREF="motion.html#'[">'[</A> <A HREF="motion.html#mark">mark</A> is set to the first line that was
just read, the <A HREF="motion.html#']">']</A> <A HREF="motion.html#mark">mark</A> to the last line.
- Before executing the *WriteCmd, *WritePre and *AppendPre autocommands the <A HREF="motion.html#'[">'[</A>
<A HREF="motion.html#mark">mark</A> is set to the first line that will be written, the <A HREF="motion.html#']">']</A> <A HREF="motion.html#mark">mark</A> to the last
line.
Careful: <A HREF="motion.html#'[">'[</A> and <A HREF="motion.html#']">']</A> change when using commands that change the buffer.
In commands which expect a file name, you can use "<A HREF="cmdline.html#<afile>"><afile></A>" for the file name
that is being read |<A HREF="cmdline.html#:<afile>">:<afile></A>| (you can also use "<A HREF="motion.html#%">%</A>" for the current file
name). "<A HREF="cmdline.html#<abuf>"><abuf></A>" can be used for the buffer number of the currently effective
buffer. This also works for <A HREF="windows.html#buffers">buffers</A> that doesn't have a name. But <A HREF="motion.html#it">it</A> doesn't
work for files without a buffer (e.g., with "<A HREF="insert.html#:r">:r</A> file").
*<A NAME="gzip-example"></A><B>gzip-example</B>*
Examples for reading and <A HREF="editing.html#writing">writing</A> compressed files:
<B> :augroup gzip</B>
<B> : autocmd!</B>
<B> : autocmd BufReadPre,FileReadPre *.gz set bin</B>
<B> : autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip</B>
<B> : autocmd BufReadPost,FileReadPost *.gz set nobin</B>
<B> : autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " . expand("%:r")</B>
<B> : autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r</B>
<B> : autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r</B>
<B> : autocmd FileAppendPre *.gz !gunzip <afile></B>
<B> : autocmd FileAppendPre *.gz !mv <afile>:r <afile></B>
<B> : autocmd FileAppendPost *.gz !mv <afile> <afile>:r</B>
<B> : autocmd FileAppendPost *.gz !gzip <afile>:r</B>
<B> :augroup END</B>
The "<A HREF="pi_gzip.html#gzip">gzip</A>" group is used to be able to delete any existing autocommands with
":autocmd!", for when the file is sourced <A HREF="if_cscop.html#twice">twice</A>.
("<afile>:r" is the file name without the extension, see |<A HREF="cmdline.html#:_%:">:_%:</A>|)
The commands executed for the <A HREF="#BufNewFile">BufNewFile</A>, BufRead/BufReadPost, <A HREF="#BufWritePost">BufWritePost</A>,
<A HREF="#FileAppendPost">FileAppendPost</A> and <A HREF="#VimLeave">VimLeave</A> events <A HREF="diff.html#do">do</A> not set or reset the changed flag of the
buffer. When you decompress the buffer with the <A HREF="#BufReadPost">BufReadPost</A> autocommands, you
can still exit with "<A HREF="editing.html#:q">:q</A>". When you use "<A HREF="undo.html#:undo">:undo</A>" in <A HREF="#BufWritePost">BufWritePost</A> to <A HREF="undo.html#undo">undo</A> the
changes made by <A HREF="#BufWritePre">BufWritePre</A> commands, you can still <A HREF="diff.html#do">do</A> "<A HREF="editing.html#:q">:q</A>" (this also makes
"<A HREF="editing.html#ZZ">ZZ</A>" work). If you <A HREF="diff.html#do">do</A> want the buffer to be marked <A HREF="motion.html#as">as</A> modified, set the
<A HREF="options.html#'modified'">'modified'</A> option.
To execute <A HREF="intro.html#Normal">Normal</A> mode commands from an <A HREF="#autocommand">autocommand</A>, use the "<A HREF="various.html#:normal">:normal</A>"
command. Use with care! If the <A HREF="intro.html#Normal">Normal</A> mode command is not finished, the user
needs to type characters (e.g., after "<A HREF="various.html#:normal">:normal</A> m" you need to type a <A HREF="motion.html#mark">mark</A>
name).
If you want the buffer to be unmodified after <A HREF="change.html#changing">changing</A> <A HREF="motion.html#it">it</A>, reset the
<A HREF="options.html#'modified'">'modified'</A> option. This makes <A HREF="motion.html#it">it</A> possible to exit the buffer with "<A HREF="editing.html#:q">:q</A>"
instead of ":q!".
*<A NAME="autocmd-nested"></A><B>autocmd-nested</B>* *<A NAME="E218"></A><B>E218</B>*
By default, autocommands <A HREF="diff.html#do">do</A> not nest. If you use "<A HREF="editing.html#:e">:e</A>" or "<A HREF="editing.html#:w">:w</A>" in an
<A HREF="#autocommand">autocommand</A>, Vim does not execute the <A HREF="#BufRead">BufRead</A> and <A HREF="#BufWrite">BufWrite</A> autocommands for
those commands. If you <A HREF="diff.html#do">do</A> want this, use the "nested" flag for those commands
in which you want nesting. For example:
<B> :autocmd FileChangedShell *.c nested e!</B>
The nesting is limited to 10 levels to get out of recursive loops.
It's possible to use the "<A HREF="#:au">:au</A>" command in an <A HREF="#autocommand">autocommand</A>. This can be a
self-modifying command! This can be useful for an <A HREF="#autocommand">autocommand</A> that should
execute only once.
If you want to skip autocommands for one command, use the |<A HREF="#:noautocmd">:noautocmd</A>| command
modifier or the <A HREF="options.html#'eventignore'">'eventignore'</A> option.
Note: When reading a file (with "<A HREF="insert.html#:read">:read</A> file" or with a <A HREF="change.html#filter">filter</A> command) and the
last line in the file does not have an <A HREF="intro.html#<EOL>"><EOL></A>, Vim remembers this. At the next
write (with "<A HREF="editing.html#:write">:write</A> file" or with a <A HREF="change.html#filter">filter</A> command), if the same line is
written again <A HREF="motion.html#as">as</A> the last line in a file AND <A HREF="options.html#'binary'">'binary'</A> is set, Vim does not
supply an <A HREF="intro.html#<EOL>"><EOL></A>. This makes a <A HREF="change.html#filter">filter</A> command on the just read lines write the
same file <A HREF="motion.html#as">as</A> was read, and makes a write command on just filtered lines write
the same file <A HREF="motion.html#as">as</A> was read from the <A HREF="change.html#filter">filter</A>. For example, another way to write
a compressed file:
<B> :autocmd FileWritePre *.gz set bin|'[,']!gzip</B>
<B> :autocmd FileWritePost *.gz undo|set nobin</B>
*<A NAME="autocommand-pattern"></A><B>autocommand-pattern</B>*
You can specify multiple patterns, separated by commas. Here are some
examples:
<B> :autocmd BufRead * set tw=79 nocin ic infercase fo=2croq</B>
<B> :autocmd BufRead .letter set tw=72 fo=2tcrq</B>
<B> :autocmd BufEnter .letter set dict=/usr/lib/dict/words</B>
<B> :autocmd BufLeave .letter set dict=</B>
<B> :autocmd BufRead,BufNewFile *.c,*.h set tw=0 cin noic</B>
<B> :autocmd BufEnter *.c,*.h abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O</B>
<B> :autocmd BufLeave *.c,*.h unabbr FOR</B>
For makefiles (makefile, Makefile, imakefile, makefile.unix, etc.):
<B> :autocmd BufEnter ?akefile* set include=^s\=include</B>
<B> :autocmd BufLeave ?akefile* set include&</B>
To always start editing C files at the first function:
<B> :autocmd BufRead *.c,*.h 1;/^{</B>
Without the "1;" above, the search would start from wherever the file was
entered, rather than from the start of the file.
*<A NAME="skeleton"></A><B>skeleton</B>* *<A NAME="template"></A><B>template</B>*
To read a <A HREF="#skeleton">skeleton</A> (template) file when opening a new file:
<B> :autocmd BufNewFile *.c 0r ~/vim/skeleton.c</B>
<B> :autocmd BufNewFile *.h 0r ~/vim/skeleton.h</B>
<B> :autocmd BufNewFile *.java 0r ~/vim/skeleton.java</B>
To insert the current date and time in a *.html file when <A HREF="editing.html#writing">writing</A> <A HREF="motion.html#it">it</A>:
<B> :autocmd BufWritePre,FileWritePre *.html ks|call LastMod()|'s</B>
<B> :fun LastMod()</B>
<B> : if line("$") > 20</B>
<B> : let l = 20</B>
<B> : else</B>
<B> : let l = line("$")</B>
<B> : endif</B>
<B> : exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .</B>
<B> : \ strftime("%Y %b %d")</B>
<B> :endfun</B>
You need to have a line "Last modified: <date time>" in the first 20 lines
of the file for this to work. Vim replaces <date time> (and anything in the
same line after <A HREF="motion.html#it">it</A>) with the current date and time. Explanation:
ks <A HREF="motion.html#mark">mark</A> current position with <A HREF="motion.html#mark">mark</A> '<A HREF="change.html#s">s</A>'
call LastMod() call the LastMod() function to <A HREF="diff.html#do">do</A> the work
's return the cursor to the old position
The LastMod() function checks if the file is shorter than 20 lines, and then
uses the "<A HREF="repeat.html#:g">:g</A>" command to find lines that contain "Last modified: ". For those
lines the "<A HREF="change.html#:s">:s</A>" command is executed to replace the existing date with the
current one. The "<A HREF="eval.html#:execute">:execute</A>" command is used to be able to use an <A HREF="eval.html#expression">expression</A>
for the "<A HREF="repeat.html#:g">:g</A>" and "<A HREF="change.html#:s">:s</A>" commands. The date is obtained with the <A HREF="eval.html#strftime()">strftime()</A>
function. You can change its argument to get another date <A HREF="eval.html#string">string</A>.
When entering <A HREF="#:autocmd">:autocmd</A> on the command-line, completion of events and command
names may be done (with <A HREF="motion.html#<Tab>"><Tab></A>, <A HREF="scroll.html#CTRL-D">CTRL-D</A>, etc.) where appropriate.
Vim executes all matching autocommands in the order that you specify them.
It is recommended that your first <A HREF="#autocommand">autocommand</A> be used for all files by using
"*" <A HREF="motion.html#as">as</A> the file <A HREF="pattern.html#pattern">pattern</A>. This means that you can define defaults you like
here for any settings, and if there is another matching <A HREF="#autocommand">autocommand</A> <A HREF="motion.html#it">it</A> will
override these. But if there is no other matching <A HREF="#autocommand">autocommand</A>, then at least
your default settings are recovered (if entering this file from another for
which autocommands did match). Note that "*" will also match files starting
with "<A HREF="repeat.html#.">.</A>", unlike <A HREF="os_unix.html#Unix">Unix</A> shells.
*<A NAME="autocmd-searchpat"></A><B>autocmd-searchpat</B>*
Autocommands <A HREF="diff.html#do">do</A> not change the current search patterns. Vim saves the current
search patterns before executing autocommands then restores them after the
autocommands finish. This means that autocommands <A HREF="diff.html#do">do</A> not affect the strings
highlighted with the <A HREF="options.html#'hlsearch'">'hlsearch'</A> option. Within autocommands, you can still
use search patterns normally, e.g., with the "<A HREF="pattern.html#n">n</A>" command.
If you want an <A HREF="#autocommand">autocommand</A> to set the search <A HREF="pattern.html#pattern">pattern</A>, such that <A HREF="motion.html#it">it</A> is used
after the <A HREF="#autocommand">autocommand</A> finishes, use the "<A HREF="eval.html#:let">:let</A> <A HREF="change.html#@/">@/</A> =" command.
The search-highlighting cannot be switched off with "<A HREF="pattern.html#:nohlsearch">:nohlsearch</A>" in an
<A HREF="#autocommand">autocommand</A>. Use the '<A HREF="motion.html#h">h</A>' flag in the <A HREF="options.html#'viminfo'">'viminfo'</A> option to disable search-
highlighting when starting Vim.
*<A NAME="Cmd-event"></A><B>Cmd-event</B>*
When using one of the "*Cmd" events, the matching autocommands are expected to
<A HREF="diff.html#do">do</A> the file reading, <A HREF="editing.html#writing">writing</A> or sourcing. This can be used when working with
a special kind of file, for example on a remote system.
CAREFUL: If you use these events in a wrong way, <A HREF="motion.html#it">it</A> may have the effect of
making <A HREF="motion.html#it">it</A> impossible to read or write the matching files! Make sure you test
your autocommands properly. Best is to use a <A HREF="pattern.html#pattern">pattern</A> that will never match a
normal file name, for example "ftp://*".
When defining a <A HREF="#BufReadCmd">BufReadCmd</A> <A HREF="motion.html#it">it</A> will be difficult for Vim to recover a crashed
editing session. When recovering from the original file, Vim reads only those
parts of a file that are not found in the swap file. Since that is not
possible with a <A HREF="#BufReadCmd">BufReadCmd</A>, use the |<A HREF="recover.html#:preserve">:preserve</A>| command to make sure the
original file isn't needed for <A HREF="recover.html#recovery">recovery</A>. You might want to <A HREF="diff.html#do">do</A> this only when
you expect the file to be modified.
For file read and write commands the |<A HREF="eval.html#v:cmdarg">v:cmdarg</A>| variable holds the "++enc="
and "++ff=" argument that are effective. These should be used for the command
that reads/writes the file. The |<A HREF="eval.html#v:cmdbang">v:cmdbang</A>| variable is one when "<A HREF="change.html#!">!</A>" was
used, zero otherwise.
See the $VIMRUNTIME/plugin/netrwPlugin.vim for examples.
==============================================================================
11. Disabling autocommands *<A NAME="autocmd-disable"></A><B>autocmd-disable</B>*
To disable autocommands for some time use the <A HREF="options.html#'eventignore'">'eventignore'</A> option. Note that
this may cause unexpected behavior, make sure you restore <A HREF="options.html#'eventignore'">'eventignore'</A>
afterwards, using a |<A HREF="eval.html#:try">:try</A>| block with |<A HREF="eval.html#:finally">:finally</A>|.
*<A NAME=":noautocmd"></A><B>:noautocmd</B>* *<A NAME=":noa"></A><B>:noa</B>*
To disable autocommands for just one command use the "<A HREF="#:noautocmd">:noautocmd</A>" command
modifier. This will set <A HREF="options.html#'eventignore'">'eventignore'</A> to "all" for the duration of the
following command. Example:
<B> :noautocmd w fname.gz</B>
This will write the file without triggering the autocommands defined by the
<A HREF="pi_gzip.html#gzip">gzip</A> <A HREF="usr_05.html#plugin">plugin</A>.
<A HREF="#top">top</A> - <A HREF="index.html">main help file</A>
</PRE>
</BODY>
</HTML>
|