/usr/share/doc/vim/html/pattern.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 | <HTML>
<HEAD>
<META HTTP-EQUIV="Content-type" content="text/html; charset=ISO-8859-1">
<TITLE>Vim documentation: pattern</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>Vim documentation: pattern</H1>
<A NAME="top"></A>
<A HREF="index.html">main help file</A>
<HR>
<PRE>
*<A NAME="pattern.txt"></A><B>pattern.txt</B>* For Vim version 8.0. Last change: 2017 Jun 05
VIM REFERENCE MANUAL by <A HREF="intro.html#Bram">Bram</A> <A HREF="intro.html#Moolenaar">Moolenaar</A>
Patterns and search commands *<A NAME="pattern-searches"></A><B>pattern-searches</B>*
The very basics can be found in section |<A HREF="usr_03.html#03.9">03.9</A>| of the user manual. A few more
explanations are in chapter 27 |<A HREF="usr_27.html">usr_27.txt</A>|.
1. Search commands |<A HREF="#search-commands">search-commands</A>|
2. The definition of a pattern |<A HREF="#search-pattern">search-pattern</A>|
3. Magic |<A HREF="#/magic">/magic</A>|
4. Overview of pattern items |<A HREF="#pattern-overview">pattern-overview</A>|
5. Multi items |<A HREF="#pattern-multi-items">pattern-multi-items</A>|
6. Ordinary atoms |<A HREF="#pattern-atoms">pattern-atoms</A>|
7. Ignoring case in a <A HREF="#pattern">pattern</A> |<A HREF="#/ignorecase">/ignorecase</A>|
8. Composing characters |<A HREF="#patterns-composing">patterns-composing</A>|
9. Compare with <A HREF="if_perl.html#Perl">Perl</A> patterns |<A HREF="#perl-patterns">perl-patterns</A>|
10. Highlighting matches |<A HREF="#match-highlight">match-highlight</A>|
==============================================================================
1. Search commands *<A NAME="search-commands"></A><B>search-commands</B>*
*<A NAME="/"></A><B>/</B>*
/{pattern}[/]<CR> Search forward for the [count]'th occurrence of
{pattern} |<A HREF="motion.html#exclusive">exclusive</A>|.
/{pattern}/{offset}<CR> Search forward for the [count]'th occurrence of
{pattern} and go |<A HREF="#{offset}">{offset}</A>| lines up or down.
|<A HREF="motion.html#linewise">linewise</A>|.
*<A NAME="/<CR>"></A><B>/<CR></B>*
<A HREF="#/<CR>">/<CR></A> Search forward for the [count]'th occurrence of the
latest used pattern |<A HREF="#last-pattern">last-pattern</A>| with latest used
|<A HREF="#{offset}">{offset}</A>|.
//{offset}<CR> Search forward for the [count]'th occurrence of the
latest used pattern |<A HREF="#last-pattern">last-pattern</A>| with new
|<A HREF="#{offset}">{offset}</A>|. If {offset} is empty no offset is used.
*<A NAME="?"></A><B>?</B>*
?{pattern}[?]<CR> Search backward for the [count]'th previous
occurrence of {pattern} |<A HREF="motion.html#exclusive">exclusive</A>|.
?{pattern}?{offset}<CR> Search backward for the [count]'th previous
occurrence of {pattern} and go |<A HREF="#{offset}">{offset}</A>| lines up or
down |<A HREF="motion.html#linewise">linewise</A>|.
*<A NAME="?<CR>"></A><B>?<CR></B>*
<A HREF="#?<CR>">?<CR></A> Search backward for the [count]'th occurrence of the
latest used pattern |<A HREF="#last-pattern">last-pattern</A>| with latest used
|<A HREF="#{offset}">{offset}</A>|.
??{offset}<CR> Search backward for the [count]'th occurrence of the
latest used pattern |<A HREF="#last-pattern">last-pattern</A>| with new
|<A HREF="#{offset}">{offset}</A>|. If {offset} is empty no offset is used.
*<A NAME="n"></A><B>n</B>*
<A HREF="#n">n</A> Repeat the latest "<A HREF="#/">/</A>" or "<A HREF="#?">?</A>" <A HREF="intro.html#[count]">[count]</A> times.
If the cursor doesn't move the search is repeated with
<A HREF="intro.html#count">count</A> + 1.
|<A HREF="#last-pattern">last-pattern</A>| {Vi: no count}
*<A NAME="N"></A><B>N</B>*
N Repeat the latest "<A HREF="#/">/</A>" or "<A HREF="#?">?</A>" <A HREF="intro.html#[count]">[count]</A> times in
opposite direction. |<A HREF="#last-pattern">last-pattern</A>| {Vi: no count}
*<A NAME="star"></A><B>star</B>* *<A NAME="E348"></A><B>E348</B>* *<A NAME="E349"></A><B>E349</B>*
* Search forward for the [count]'th occurrence of the
<A HREF="motion.html#word">word</A> nearest to the cursor. The <A HREF="motion.html#word">word</A> used for the
search is the first of:
1. the keyword under the cursor |<A HREF="options.html#'iskeyword'">'iskeyword'</A>|
2. the first keyword after the cursor, in the
current line
3. the non-blank <A HREF="motion.html#word">word</A> under the cursor
4. the first non-blank <A HREF="motion.html#word">word</A> after the cursor,
in the current line
Only whole keywords are searched for, like with the
command "/\<keyword\>". |<A HREF="motion.html#exclusive">exclusive</A>| {not in Vi}
<A HREF="options.html#'ignorecase'">'ignorecase'</A> is used, <A HREF="options.html#'smartcase'">'smartcase'</A> is not.
*<A NAME="#"></A><B>#</B>*
# Same <A HREF="motion.html#as">as</A> "*", but search backward. The pound sign
(character 163) also works. If the "<A HREF="##">#</A>" key works <A HREF="motion.html#as">as</A>
backspace, try using "stty erase <BS>" before starting
Vim (<BS> is <A HREF="motion.html#CTRL-H">CTRL-H</A> or a real backspace). {not in Vi}
*<A NAME="gstar"></A><B>gstar</B>*
g* Like "*", but don't put "\<" and "\>" around the <A HREF="motion.html#word">word</A>.
This makes the search also find matches that are not a
whole <A HREF="motion.html#word">word</A>. {not in Vi}
*<A NAME="g#"></A><B>g#</B>*
<A HREF="#g#">g#</A> Like "<A HREF="##">#</A>", but don't put "\<" and "\>" around the <A HREF="motion.html#word">word</A>.
This makes the search also find matches that are not a
whole <A HREF="motion.html#word">word</A>. {not in Vi}
*<A NAME="gd"></A><B>gd</B>*
<A HREF="#gd">gd</A> Goto local Declaration. When the cursor is on a local
variable, this command will jump to its declaration.
First Vim searches for the start of the current
function, just like "<A HREF="motion.html#[[">[[</A>". If <A HREF="motion.html#it">it</A> is not found the
search stops in line 1. If <A HREF="motion.html#it">it</A> is found, Vim goes back
until a blank line is found. From this position Vim
searches for the keyword under the cursor, like with
"*", but lines that look like a comment are ignored
(see <A HREF="options.html#'comments'">'comments'</A> option).
Note that this is not guaranteed to work, Vim does not
really check the <A HREF="syntax.html#syntax">syntax</A>, <A HREF="motion.html#it">it</A> only searches for a match
with the keyword. If included files also need to be
searched use the commands listed in |<A HREF="tagsrch.html#include-search">include-search</A>|.
After this command |<A HREF="#n">n</A>| searches forward for the next
match (not backward).
{not in Vi}
*<A NAME="gD"></A><B>gD</B>*
<A HREF="#gD">gD</A> Goto global Declaration. When the cursor is on a
global variable that is defined in the file, this
command will jump to its declaration. This works just
like "<A HREF="#gd">gd</A>", except that the search for the keyword
always starts in line 1. {not in Vi}
*<A NAME="1gd"></A><B>1gd</B>*
<A HREF="#1gd">1gd</A> Like "<A HREF="#gd">gd</A>", but ignore matches inside a <A HREF="intro.html#{}">{}</A> block that
ends before the cursor position. {not in Vi}
*<A NAME="1gD"></A><B>1gD</B>*
<A HREF="#1gD">1gD</A> Like "<A HREF="#gD">gD</A>", but ignore matches inside a <A HREF="intro.html#{}">{}</A> block that
ends before the cursor position. {not in Vi}
*<A NAME="CTRL-C"></A><B>CTRL-C</B>*
<A HREF="#CTRL-C">CTRL-C</A> Interrupt current (search) command. Use CTRL-Break on
<A HREF="os_msdos.html#MS-DOS">MS-DOS</A> |<A HREF="os_dos.html#dos-CTRL-Break">dos-CTRL-Break</A>|.
In <A HREF="intro.html#Normal">Normal</A> mode, any pending command is aborted.
*<A NAME=":noh"></A><B>:noh</B>* *<A NAME=":nohlsearch"></A><B>:nohlsearch</B>*
:noh[lsearch] Stop the highlighting for the <A HREF="options.html#'hlsearch'">'hlsearch'</A> option. It
is automatically turned back on when using a search
command, or setting the <A HREF="options.html#'hlsearch'">'hlsearch'</A> option.
This command doesn't work in an <A HREF="autocmd.html#autocommand">autocommand</A>, because
the highlighting state is saved and restored when
executing autocommands |<A HREF="autocmd.html#autocmd-searchpat">autocmd-searchpat</A>|.
Same thing for when invoking a user function.
While typing the search <A HREF="#pattern">pattern</A> the current match will be shown if the
<A HREF="options.html#'incsearch'">'incsearch'</A> option is on. Remember that you still have to finish the search
command with <A HREF="motion.html#<CR>"><CR></A> to actually position the cursor at the displayed match. Or
use <A HREF="intro.html#<Esc>"><Esc></A> to <A HREF="editing.html#abandon">abandon</A> the search.
All matches for the last used search <A HREF="#pattern">pattern</A> will be highlighted if you set
the <A HREF="options.html#'hlsearch'">'hlsearch'</A> option. This can be suspended with the |<A HREF="#:nohlsearch">:nohlsearch</A>| command.
When no match is found you get the error: *<A NAME="E486"></A><B>E486</B>* <A HREF="#Pattern">Pattern</A> not found
Note that for the |<A HREF="repeat.html#:global">:global</A>| command this behaves like a normal message, for <A HREF="intro.html#Vi">Vi</A>
compatibility. For the |<A HREF="change.html#:s">:s</A>| command the "<A HREF="motion.html#e">e</A>" flag can be used to avoid the
error message |<A HREF="change.html#:s_flags">:s_flags</A>|.
*<A NAME="search-offset"></A><B>search-offset</B>* *<A NAME="{offset}"></A><B>{offset}</B>*
These commands search for the specified <A HREF="#pattern">pattern</A>. With "<A HREF="#/">/</A>" and "<A HREF="#?">?</A>" an
additional offset may be given. There are two types of offsets: line offsets
and character offsets. {the character offsets are not in Vi}
The offset gives the cursor position relative to the found match:
[num] [num] lines downwards, in column 1
+[num] [num] lines downwards, in column 1
-[num] [num] lines upwards, in column 1
e[+num] [num] characters to the right of the end of the match
e[-num] [num] characters to the left of the end of the match
s[+num] [num] characters to the right of the start of the match
s[-num] [num] characters to the left of the start of the match
b[+num] [num] identical to s[+num] above (mnemonic: begin)
b[-num] [num] identical to s[-num] above (mnemonic: begin)
;{pattern} perform another search, see |<A HREF="#//;">//;</A>|
If a '<A HREF="motion.html#-">-</A>' or '<A HREF="motion.html#+">+</A>' is given but [num] is omitted, a <A HREF="intro.html#count">count</A> of one will be used.
When including an offset with '<A HREF="motion.html#e">e</A>', the search becomes <A HREF="motion.html#inclusive">inclusive</A> (the
character the cursor lands on is included in operations).
Examples:
<B><FONT COLOR="PURPLE">pattern cursor position </FONT></B>
/test/+1 one line below "test", in column 1
/test/e on the last t of "test"
/test/s+2 on the '<A HREF="change.html#s">s</A>' of "test"
/test/b-3 three characters before "test"
If one of these commands is used after an <A HREF="motion.html#operator">operator</A>, the characters between
the cursor position before and after the search is affected. However, if a
line offset is given, the whole lines between the two cursor positions are
affected.
An example of how to search for matches with a <A HREF="#pattern">pattern</A> and change the match
with another <A HREF="motion.html#word">word</A>:
<B> /foo<CR> find "foo"</B>
<B> c//e<CR> change until end of match</B>
<B> bar<Esc> type replacement</B>
<B> //<CR> go to start of next match</B>
<B> c//e<CR> change until end of match</B>
<B> beep<Esc> type another replacement</B>
<B> etc.</B>
*<A NAME="//;"></A><B>//;</B>* *<A NAME="E386"></A><B>E386</B>*
A very special offset is '<A HREF="motion.html#;">;</A>' followed by another search command. For example:
<B> /test 1/;/test</B>
<B> /test.*/+1;?ing?</B>
The first one first finds the next occurrence of "test 1", and then the first
occurrence of "test" after that.
This is like executing two search commands after each other, except that:
- It can be used <A HREF="motion.html#as">as</A> a single motion command after an <A HREF="motion.html#operator">operator</A>.
- The direction for a following "<A HREF="#n">n</A>" or "<A HREF="#N">N</A>" command comes from the first
search command.
- When an error occurs the cursor is not moved at all.
*<A NAME="last-pattern"></A><B>last-pattern</B>*
The last used <A HREF="#pattern">pattern</A> and offset are remembered. They can be used to repeat
the search, possibly in another direction or with another <A HREF="intro.html#count">count</A>. Note that
two patterns are remembered: One for 'normal' search commands and one for the
substitute command "<A HREF="change.html#:s">:s</A>". Each time an empty <A HREF="#pattern">pattern</A> is given, the previously
used <A HREF="#pattern">pattern</A> is used. However, if there is no previous search command, a
previous substitute <A HREF="#pattern">pattern</A> is used, if possible.
The <A HREF="options.html#'magic'">'magic'</A> option sticks with the last used <A HREF="#pattern">pattern</A>. If you change <A HREF="options.html#'magic'">'magic'</A>,
this will not change how the last used <A HREF="#pattern">pattern</A> will be interpreted.
The <A HREF="options.html#'ignorecase'">'ignorecase'</A> option does not <A HREF="diff.html#do">do</A> this. When <A HREF="options.html#'ignorecase'">'ignorecase'</A> is changed, <A HREF="motion.html#it">it</A>
will result in the <A HREF="#pattern">pattern</A> to match other text.
All matches for the last used search <A HREF="#pattern">pattern</A> will be highlighted if you set
the <A HREF="options.html#'hlsearch'">'hlsearch'</A> option.
To clear the last used search <A HREF="#pattern">pattern</A>:
<B> :let @/ = ""</B>
This will not set the <A HREF="#pattern">pattern</A> to an empty <A HREF="eval.html#string">string</A>, because that would match
everywhere. The <A HREF="#pattern">pattern</A> is really cleared, like when starting Vim.
The search usually skips matches that don't move the cursor. Whether the next
match is found at the next character or after the skipped match depends on the
'c' flag in <A HREF="options.html#'cpoptions'">'cpoptions'</A>. See |<A HREF="options.html#cpo-c">cpo-c</A>|.
with '<A HREF="change.html#c">c</A>' flag: "/..." advances 1 to 3 characters
without '<A HREF="change.html#c">c</A>' flag: "/..." advances 1 character
The unpredictability with the '<A HREF="change.html#c">c</A>' flag is caused by starting the search in the
first column, skipping matches until one is found past the cursor position.
When searching backwards, searching starts at the start of the line, using the
'<A HREF="change.html#c">c</A>' flag in <A HREF="options.html#'cpoptions'">'cpoptions'</A> <A HREF="motion.html#as">as</A> described above. Then the last match before the
cursor position is used.
In <A HREF="intro.html#Vi">Vi</A> the "<A HREF="tagsrch.html#:tag">:tag</A>" command sets the last search <A HREF="#pattern">pattern</A> when the <A HREF="tagsrch.html#tag">tag</A> is searched
for. In Vim this is not done, the previous search <A HREF="#pattern">pattern</A> is still remembered,
unless the '<A HREF="motion.html#t">t</A>' flag is present in <A HREF="options.html#'cpoptions'">'cpoptions'</A>. The search <A HREF="#pattern">pattern</A> is always
put in the search <A HREF="cmdline.html#history">history</A>.
If the <A HREF="options.html#'wrapscan'">'wrapscan'</A> option is on (which is the default), searches wrap around
the end of the buffer. If <A HREF="options.html#'wrapscan'">'wrapscan'</A> is not set, the backward search stops
at the beginning and the forward search stops at the end of the buffer. If
<A HREF="options.html#'wrapscan'">'wrapscan'</A> is set and the <A HREF="#pattern">pattern</A> was not found the error message "<A HREF="#pattern">pattern</A>
not found" is given, and the cursor will not be moved. If <A HREF="options.html#'wrapscan'">'wrapscan'</A> is not
set the message becomes "search hit BOTTOM without match" when searching
forward, or "search hit TOP without match" when searching backward. If
wrapscan is set and the search wraps around the end of the file the message
"search hit TOP, continuing at BOTTOM" or "search hit BOTTOM, continuing at
TOP" is given when searching backwards or forwards respectively. This can be
switched off by setting the '<A HREF="change.html#s">s</A>' flag in the <A HREF="options.html#'shortmess'">'shortmess'</A> option. The highlight
method '<A HREF="motion.html#w">w</A>' is used for this message (default: <A HREF="syntax.html#standout">standout</A>).
*<A NAME="search-range"></A><B>search-range</B>*
You can limit the search command "<A HREF="#/">/</A>" to a certain range of lines by including
\%>l items. For example, to match the <A HREF="motion.html#word">word</A> "limit" below line 199 and above
line 300:
<B> /\%>199l\%<300llimit</B>
Also see |<A HREF="#/\%>l">/\%>l</A>|.
Another way is to use the "<A HREF="change.html#:substitute">:substitute</A>" command with the '<A HREF="change.html#c">c</A>' flag. Example:
<B> :.,300s/Pattern//gc</B>
This command will search from the cursor position until line 300 for
"<A HREF="#Pattern">Pattern</A>". At the match, you will be asked to type a character. Type '<A HREF="repeat.html#q">q</A>' to
stop at this match, type '<A HREF="#n">n</A>' to find the next match.
The "*", "<A HREF="##">#</A>", "g*" and "<A HREF="#g#">g#</A>" commands look for a <A HREF="motion.html#word">word</A> near the cursor in this
order, the first one that is found is used:
- The keyword currently under the cursor.
- The first keyword to the right of the cursor, in the same line.
- The <A HREF="motion.html#WORD">WORD</A> currently under the cursor.
- The first <A HREF="motion.html#WORD">WORD</A> to the right of the cursor, in the same line.
The keyword may only contain letters and characters in <A HREF="options.html#'iskeyword'">'iskeyword'</A>.
The <A HREF="motion.html#WORD">WORD</A> may contain any non-blanks (<Tab>s and/or <Space>s).
Note that if you type with ten fingers, the characters are <A HREF="starting.html#easy">easy</A> to remember:
the "<A HREF="##">#</A>" is under your left hand middle finger (search to the left and up) and
the "*" is under your right hand middle finger (search to the right and down).
(this depends on your keyboard layout though).
==============================================================================
2. The definition of a <A HREF="#pattern">pattern</A> *<A NAME="search-pattern"></A><B>search-pattern</B>* *<A NAME="pattern"></A><B>pattern</B>* *<A NAME="[pattern]"></A><B>[pattern]</B>*
*<A NAME="regular-expression"></A><B>regular-expression</B>* *<A NAME="regexp"></A><B>regexp</B>* *<A NAME="Pattern"></A><B>Pattern</B>*
*<A NAME="E76"></A><B>E76</B>* *<A NAME="E383"></A><B>E383</B>* *<A NAME="E476"></A><B>E476</B>*
For starters, read chapter 27 of the user manual |<A HREF="usr_27.html">usr_27.txt</A>|.
*<A NAME="/bar"></A><B>/bar</B>* *<A NAME="/\bar"></A><B>/\bar</B>* *<A NAME="/pattern"></A><B>/pattern</B>*
1. A <A HREF="#pattern">pattern</A> is one or more branches, separated by "\|". It matches anything
that matches one of the branches. Example: "foo\|beep" matches "foo" and
matches "beep". If more than one branch matches, the first one is used.
<A HREF="#pattern">pattern</A> ::= branch
or branch \| branch
or branch \| branch \| branch
etc.
*<A NAME="/branch"></A><B>/branch</B>* *<A NAME="/\&"></A><B>/\&</B>*
2. A branch is one or more concats, separated by "\&". It matches the last
concat, but only if all the preceding concats also match at the same
position. Examples:
"foobeep\&..." matches "foo" in "foobeep".
".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob"
branch ::= concat
or concat \& concat
or concat \& concat \& concat
etc.
*<A NAME="/concat"></A><B>/concat</B>*
3. A concat is one or more pieces, concatenated. It matches a match for the
first piece, followed by a match for the second piece, etc. Example:
"f[0-9]b", first matches "<A HREF="motion.html#f">f</A>", then a digit and then "<A HREF="motion.html#b">b</A>".
concat ::= piece
or piece piece
or piece piece piece
etc.
*<A NAME="/piece"></A><B>/piece</B>*
4. A piece is an atom, possibly followed by a multi, an indication of how many
times the atom can be matched. Example: "a*" matches any sequence of "<A HREF="insert.html#a">a</A>"
characters: "", "<A HREF="insert.html#a">a</A>", "aa", etc. See |<A HREF="#/multi">/multi</A>|.
piece ::= atom
or atom multi
*<A NAME="/atom"></A><B>/atom</B>*
5. An atom can be one of a long <A HREF="eval.html#list">list</A> of items. Many atoms match one character
in the text. It is often an ordinary character or a character class.
Braces can be used to make a <A HREF="#pattern">pattern</A> into an atom. The "\z(\)" construct
is only for <A HREF="syntax.html#syntax">syntax</A> highlighting.
atom ::= ordinary-atom |<A HREF="#/ordinary-atom">/ordinary-atom</A>|
or \( <A HREF="#pattern">pattern</A> \) |<A HREF="#/\(">/\(</A>|
or \%( <A HREF="#pattern">pattern</A> \) |<A HREF="#/\%(">/\%(</A>|
or \z( <A HREF="#pattern">pattern</A> \) |<A HREF="syntax.html#/\z(">/\z(</A>|
*<A NAME="/\%#="></A><B>/\%#=</B>* *<A NAME="two-engines"></A><B>two-engines</B>* *<A NAME="NFA"></A><B>NFA</B>*
Vim includes two <A HREF="#regexp">regexp</A> engines:
1. An old, backtracking engine that supports everything.
2. A new, <A HREF="#NFA">NFA</A> engine that works much faster on some patterns, possibly slower
on some patterns.
Vim will automatically select the right engine for you. However, if you run
into a problem or want to specifically select one engine or the other, you can
prepend one of the following to the <A HREF="#pattern">pattern</A>:
\%#=0 Force automatic selection. Only has an effect when
<A HREF="options.html#'regexpengine'">'regexpengine'</A> has been set to a non-zero value.
\%#=1 Force using the old engine.
\%#=2 Force using the <A HREF="#NFA">NFA</A> engine.
You can also use the <A HREF="options.html#'regexpengine'">'regexpengine'</A> option to change the default.
*<A NAME="E864"></A><B>E864</B>* *<A NAME="E868"></A><B>E868</B>* *<A NAME="E874"></A><B>E874</B>* *<A NAME="E875"></A><B>E875</B>* *<A NAME="E876"></A><B>E876</B>* *<A NAME="E877"></A><B>E877</B>* *<A NAME="E878"></A><B>E878</B>*
If selecting the <A HREF="#NFA">NFA</A> engine and <A HREF="motion.html#it">it</A> runs into something that is not implemented
the <A HREF="#pattern">pattern</A> will not match. This is only useful when debugging Vim.
==============================================================================
3. Magic *<A NAME="/magic"></A><B>/magic</B>*
Some characters in the <A HREF="#pattern">pattern</A> are taken literally. They match with the same
character in the text. When preceded with a <A HREF="intro.html#backslash">backslash</A> however, these
characters get a special meaning.
Other characters have a special meaning without a <A HREF="intro.html#backslash">backslash</A>. They need to be
preceded with a <A HREF="intro.html#backslash">backslash</A> to match literally.
If a character is taken literally or not depends on the <A HREF="options.html#'magic'">'magic'</A> option and the
items mentioned next.
*<A NAME="/\m"></A><B>/\m</B>* *<A NAME="/\M"></A><B>/\M</B>*
Use of "\m" makes the <A HREF="#pattern">pattern</A> after <A HREF="motion.html#it">it</A> be interpreted <A HREF="motion.html#as">as</A> if <A HREF="options.html#'magic'">'magic'</A> is set,
ignoring the actual value of the <A HREF="options.html#'magic'">'magic'</A> option.
Use of "\M" makes the <A HREF="#pattern">pattern</A> after <A HREF="motion.html#it">it</A> be interpreted <A HREF="motion.html#as">as</A> if <A HREF="options.html#'nomagic'">'nomagic'</A> is used.
*<A NAME="/\v"></A><B>/\v</B>* *<A NAME="/\V"></A><B>/\V</B>*
Use of "\v" means that in the <A HREF="#pattern">pattern</A> after <A HREF="motion.html#it">it</A> all ASCII characters except
'0'-'9', 'a'-'z', 'A'-'Z' and '<A HREF="motion.html#_">_</A>' have a special meaning. "very magic"
Use of "\V" means that in the <A HREF="#pattern">pattern</A> after <A HREF="motion.html#it">it</A> only the <A HREF="intro.html#backslash">backslash</A> and the
terminating character (/ or ?) has a special meaning. "very nomagic"
Examples:
<B><FONT COLOR="PURPLE">after: \v \m \M \V matches </FONT></B>
<A HREF="options.html#'magic'">'magic'</A> <A HREF="options.html#'nomagic'">'nomagic'</A>
$ $ $ \$ matches end-of-line
. . \. \. matches any character
* * \* \* any number of the previous atom
~ ~ \~ \~ latest substitute <A HREF="eval.html#string">string</A>
() \(\) \(\) \(\) grouping into an atom
| \| \| \| separating alternatives
\a \a \a \a alphabetic character
\\ \\ \\ \\ literal <A HREF="intro.html#backslash">backslash</A>
\. \. . . literal dot
\{ { { { literal '<A HREF="motion.html#{">{</A>'
a a a a literal '<A HREF="insert.html#a">a</A>'
{only Vim supports \m, \M, \v and \V}
It is recommended to always keep the <A HREF="options.html#'magic'">'magic'</A> option at the default setting,
which is <A HREF="options.html#'magic'">'magic'</A>. This avoids portability problems. To make a <A HREF="#pattern">pattern</A> immune
to the <A HREF="options.html#'magic'">'magic'</A> option being set or not, put "\m" or "\M" at the start of the
<A HREF="#pattern">pattern</A>.
==============================================================================
4. Overview of <A HREF="#pattern">pattern</A> items *<A NAME="pattern-overview"></A><B>pattern-overview</B>*
*<A NAME="E865"></A><B>E865</B>* *<A NAME="E866"></A><B>E866</B>* *<A NAME="E867"></A><B>E867</B>* *<A NAME="E869"></A><B>E869</B>*
Overview of multi items. *<A NAME="/multi"></A><B>/multi</B>* *<A NAME="E61"></A><B>E61</B>* *<A NAME="E62"></A><B>E62</B>*
More explanation and examples below, follow the links. *<A NAME="E64"></A><B>E64</B>* *<A NAME="E871"></A><B>E871</B>*
<B><FONT COLOR="PURPLE"> multi </FONT></B>
<B><FONT COLOR="PURPLE"> 'magic' 'nomagic' matches of the preceding atom </FONT></B>
|<A HREF="#/star">/star</A>| * \* 0 or more <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible
|<A HREF="#/\+">/\+</A>| \+ \+ 1 or more <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (*)
|<A HREF="#/\=">/\=</A>| \= \= 0 or 1 <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (*)
|<A HREF="#/\?">/\?</A>| \? \? 0 or 1 <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (*)
|<A HREF="#/\{">/\{</A>| \{n,m} \{n,m} <A HREF="#n">n</A> to <A HREF="motion.html#m">m</A> <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (*)
\{n} \{n} <A HREF="#n">n</A> exactly (*)
\{n,} \{n,} at least <A HREF="#n">n</A> <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (*)
\{,m} \{,m} 0 to <A HREF="motion.html#m">m</A> <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (*)
\{} \{} 0 or more <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (same <A HREF="motion.html#as">as</A> *) (*)
|<A HREF="#/\{-">/\{-</A>| \{-n,m} \{-n,m} <A HREF="#n">n</A> to <A HREF="motion.html#m">m</A> <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible (*)
\{-n} \{-n} <A HREF="#n">n</A> exactly (*)
\{-n,} \{-n,} at least <A HREF="#n">n</A> <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible (*)
\{-,m} \{-,m} 0 to <A HREF="motion.html#m">m</A> <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible (*)
\{-} \{-} 0 or more <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible (*)
*<A NAME="E59"></A><B>E59</B>*
|<A HREF="#/\@>">/\@></A>| \@> \@> 1, like matching a whole <A HREF="#pattern">pattern</A> (*)
|<A HREF="#/\@=">/\@=</A>| \@= \@= nothing, requires a match |<A HREF="#/zero-width">/zero-width</A>| (*)
|<A HREF="#/\@!">/\@!</A>| \@! \@! nothing, requires NO match |<A HREF="#/zero-width">/zero-width</A>| (*)
|<A HREF="#/\@<=">/\@<=</A>| \@<= \@<= nothing, requires a match behind |<A HREF="#/zero-width">/zero-width</A>| (*)
|<A HREF="#/\@<!">/\@<!</A>| \@<! \@<! nothing, requires NO match behind |<A HREF="#/zero-width">/zero-width</A>| (*)
(*) {not in Vi}
Overview of ordinary atoms. *<A NAME="/ordinary-atom"></A><B>/ordinary-atom</B>*
More explanation and examples below, follow the links.
<B><FONT COLOR="PURPLE"> ordinary atom </FONT></B>
<B><FONT COLOR="PURPLE"> magic nomagic matches </FONT></B>
|<A HREF="#/^">/^</A>| ^ ^ start-of-line (at start of <A HREF="#pattern">pattern</A>) |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\^">/\^</A>| \^ \^ literal '^'
|<A HREF="#/\_^">/\_^</A>| \_^ \_^ start-of-line (used anywhere) |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/$">/$</A>| $ $ end-of-line (at end of <A HREF="#pattern">pattern</A>) |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\$">/\$</A>| \$ \$ literal '$'
|<A HREF="#/\_$">/\_$</A>| \_$ \_$ end-of-line (used anywhere) |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/.">/.</A>| . \. any single character (not an end-of-line)
|<A HREF="#/\_.">/\_.</A>| \_. \_. any single character or end-of-line
|<A HREF="#/\<">/\<</A>| \< \< beginning of a <A HREF="motion.html#word">word</A> |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\>">/\></A>| \> \> end of a <A HREF="motion.html#word">word</A> |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\zs">/\zs</A>| \zs \zs anything, sets start of match
|<A HREF="#/\ze">/\ze</A>| \ze \ze anything, sets end of match
|<A HREF="#/\%^">/\%^</A>| \%^ \%^ beginning of file |<A HREF="#/zero-width">/zero-width</A>| *<A NAME="E71"></A><B>E71</B>*
|<A HREF="#/\%$">/\%$</A>| \%$ \%$ end of file |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%V">/\%V</A>| \%V \%V inside <A HREF="visual.html#Visual">Visual</A> area |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%#">/\%#</A>| \%# \%# cursor position |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%'m">/\%'m</A>| \%'m \%'m <A HREF="motion.html#mark">mark</A> m position |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%l">/\%l</A>| \%23l \%23l in line 23 |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%c">/\%c</A>| \%23c \%23c in column 23 |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%v">/\%v</A>| \%23v \%23v in virtual column 23 |<A HREF="#/zero-width">/zero-width</A>|
Character classes {not in Vi}: *<A NAME="/character-classes"></A><B>/character-classes</B>*
<B><FONT COLOR="PURPLE"> magic nomagic matches </FONT></B>
|<A HREF="#/\i">/\i</A>| \i \i identifier character (see <A HREF="options.html#'isident'">'isident'</A> option)
|<A HREF="#/\I">/\I</A>| \I \I like "\i", but excluding digits
|<A HREF="#/\k">/\k</A>| \k \k keyword character (see <A HREF="options.html#'iskeyword'">'iskeyword'</A> option)
|<A HREF="#/\K">/\K</A>| \K \K like "\k", but excluding digits
|<A HREF="#/\f">/\f</A>| \f \f file name character (see <A HREF="options.html#'isfname'">'isfname'</A> option)
|<A HREF="#/\F">/\F</A>| \F \F like "\f", but excluding digits
|<A HREF="#/\p">/\p</A>| \p \p printable character (see <A HREF="options.html#'isprint'">'isprint'</A> option)
|<A HREF="#/\P">/\P</A>| \P \P like "\p", but excluding digits
|<A HREF="#/\s">/\s</A>| \s \s <A HREF="#whitespace">whitespace</A> character: <A HREF="motion.html#<Space>"><Space></A> and <A HREF="motion.html#<Tab>"><Tab></A>
|<A HREF="#/\S">/\S</A>| \S \S non-whitespace character; opposite of \s
|<A HREF="#/\d">/\d</A>| \d \d digit: [0-9]
|<A HREF="#/\D">/\D</A>| \D \D non-digit: [^0-9]
|<A HREF="#/\x">/\x</A>| \x \x hex digit: [0-9A-Fa-f]
|<A HREF="#/\X">/\X</A>| \X \X non-hex digit: [^0-9A-Fa-f]
|<A HREF="#/\o">/\o</A>| \o \o <A HREF="eval.html#octal">octal</A> digit: [0-7]
|<A HREF="#/\O">/\O</A>| \O \O non-octal digit: [^0-7]
|<A HREF="#/\w">/\w</A>| \w \w <A HREF="motion.html#word">word</A> character: [0-9A-Za-z_]
|<A HREF="#/\W">/\W</A>| \W \W non-word character: [^0-9A-Za-z_]
|<A HREF="#/\h">/\h</A>| \h \h head of <A HREF="motion.html#word">word</A> character: [A-Za-z_]
|<A HREF="#/\H">/\H</A>| \H \H non-head of <A HREF="motion.html#word">word</A> character: [^A-Za-z_]
|<A HREF="#/\a">/\a</A>| \a \a alphabetic character: [A-Za-z]
|<A HREF="#/\A">/\A</A>| \A \A non-alphabetic character: [^A-Za-z]
|<A HREF="#/\l">/\l</A>| \l \l <A HREF="change.html#lowercase">lowercase</A> character: [a-z]
|<A HREF="#/\L">/\L</A>| \L \L non-lowercase character: [^a-z]
|<A HREF="#/\u">/\u</A>| \u \u <A HREF="change.html#uppercase">uppercase</A> character: [A-Z]
|<A HREF="#/\U">/\U</A>| \U \U non-uppercase character [^A-Z]
|<A HREF="#/\_">/\_</A>| \_x \_x where <A HREF="change.html#x">x</A> is any of the characters above: character
class with end-of-line included
(end of character classes)
<B><FONT COLOR="PURPLE"> magic nomagic matches </FONT></B>
|<A HREF="#/\e">/\e</A>| \e \e <A HREF="intro.html#<Esc>"><Esc></A>
|<A HREF="#/\t">/\t</A>| \t \t <A HREF="motion.html#<Tab>"><Tab></A>
|<A HREF="#/\r">/\r</A>| \r \r <A HREF="motion.html#<CR>"><CR></A>
|<A HREF="#/\b">/\b</A>| \b \b <A HREF="motion.html#<BS>"><BS></A>
|<A HREF="#/\n">/\n</A>| \n \n end-of-line
|<A HREF="#/~">/~</A>| ~ \~ last given substitute <A HREF="eval.html#string">string</A>
|<A HREF="#/\1">/\1</A>| \1 \1 same <A HREF="eval.html#string">string</A> <A HREF="motion.html#as">as</A> matched by first \(\) {not in Vi}
|<A HREF="#/\2">/\2</A>| \2 \2 Like "\1", but uses second \(\)
<A HREF="eval.html#...">...</A>
|<A HREF="#/\9">/\9</A>| \9 \9 Like "\1", but uses ninth \(\)
*<A NAME="E68"></A><B>E68</B>*
|<A HREF="syntax.html#/\z1">/\z1</A>| \z1 \z1 only for <A HREF="syntax.html#syntax">syntax</A> highlighting, see |<A HREF="syntax.html#:syn-ext-match">:syn-ext-match</A>|
<A HREF="eval.html#...">...</A>
|<A HREF="syntax.html#/\z1">/\z1</A>| \z9 \z9 only for <A HREF="syntax.html#syntax">syntax</A> highlighting, see |<A HREF="syntax.html#:syn-ext-match">:syn-ext-match</A>|
<A HREF="change.html#x">x</A> <A HREF="change.html#x">x</A> a character with no special meaning matches itself
|<A HREF="#/[]">/[]</A>| [] \[] any character specified inside the []
|<A HREF="#/\%[]">/\%[]</A>| \%[] \%[] a sequence of optionally matched atoms
|<A HREF="#/\c">/\c</A>| \c \c ignore <A HREF="change.html#case">case</A>, <A HREF="diff.html#do">do</A> not use the <A HREF="options.html#'ignorecase'">'ignorecase'</A> option
|<A HREF="#/\C">/\C</A>| \C \C match <A HREF="change.html#case">case</A>, <A HREF="diff.html#do">do</A> not use the <A HREF="options.html#'ignorecase'">'ignorecase'</A> option
|<A HREF="#/\Z">/\Z</A>| \Z \Z ignore differences in <A HREF="mbyte.html#Unicode">Unicode</A> "combining characters".
Useful when searching voweled Hebrew or <A HREF="arabic.html#Arabic">Arabic</A> text.
<B><FONT COLOR="PURPLE"> magic nomagic matches </FONT></B>
|<A HREF="#/\m">/\m</A>| \m \m <A HREF="options.html#'magic'">'magic'</A> on for the following chars in the <A HREF="#pattern">pattern</A>
|<A HREF="#/\M">/\M</A>| \M \M <A HREF="options.html#'magic'">'magic'</A> off for the following chars in the <A HREF="#pattern">pattern</A>
|<A HREF="#/\v">/\v</A>| \v \v the following chars in the <A HREF="#pattern">pattern</A> are "very magic"
|<A HREF="#/\V">/\V</A>| \V \V the following chars in the <A HREF="#pattern">pattern</A> are "very nomagic"
|<A HREF="#/\%#=">/\%#=</A>| \%#=1 \%#=1 select <A HREF="#regexp">regexp</A> engine |<A HREF="#/zero-width">/zero-width</A>|
|<A HREF="#/\%d">/\%d</A>| \%d \%d match specified decimal character (eg \%d123)
|<A HREF="#/\%x">/\%x</A>| \%x \%x match specified hex character (eg \%x2a)
|<A HREF="#/\%o">/\%o</A>| \%o \%o match specified <A HREF="eval.html#octal">octal</A> character (eg \%o040)
|<A HREF="#/\%u">/\%u</A>| \%u \%u match specified <A HREF="mbyte.html#multibyte">multibyte</A> character (eg \%u20ac)
|<A HREF="#/\%U">/\%U</A>| \%U \%U match specified large <A HREF="mbyte.html#multibyte">multibyte</A> character (eg
\%U12345678)
|<A HREF="#/\%C">/\%C</A>| \%C \%C match any composing characters
<B><FONT COLOR="PURPLE">Example matches </FONT></B>
\<\I\i* or
\<\h\w*
\<[a-zA-Z_][a-zA-Z0-9_]*
An identifier (e.g., in a C program).
\(\.$\|\. \) A period followed by <A HREF="intro.html#<EOL>"><EOL></A> or a space.
[.!?][])"']*\($\|[ ]\) A search <A HREF="#pattern">pattern</A> that finds the end of a <A HREF="motion.html#sentence">sentence</A>,
with almost the same definition <A HREF="motion.html#as">as</A> the "<A HREF="motion.html#)">)</A>" command.
cat\Z Both "cat" and "càt" ("a" followed by 0x0300)
Does not match "càt" (character 0x00e0), even
though <A HREF="motion.html#it">it</A> may look the same.
==============================================================================
5. Multi items *<A NAME="pattern-multi-items"></A><B>pattern-multi-items</B>*
An atom can be followed by an indication of how many times the atom can be
matched and in what way. This is called a multi. See |<A HREF="#/multi">/multi</A>| for an
overview.
*<A NAME="/star"></A><B>/star</B>* *<A NAME="/\star"></A><B>/\star</B>*
* (use \* when <A HREF="options.html#'magic'">'magic'</A> is not set)
Matches 0 or more of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible.
<B><FONT COLOR="PURPLE"> Example 'nomagic' matches </FONT></B>
a* a\* "", "<A HREF="insert.html#a">a</A>", "aa", "aaa", etc.
.* \.\* anything, also an empty <A HREF="eval.html#string">string</A>, no end-of-line
\_.* \_.\* everything up to the end of the buffer
\_.*END \_.\*END everything up to and including the last "END"
in the buffer
Exception: When "*" is used at the start of the <A HREF="#pattern">pattern</A> or just after
"<A HREF="motion.html#^">^</A>" <A HREF="motion.html#it">it</A> matches the <A HREF="#star">star</A> character.
Be aware that <A HREF="repeat.html#repeating">repeating</A> "\_." can match a lot of text and take a long
time. For example, "\_.*END" matches all text from the current
position to the last occurrence of "END" in the file. Since the "*"
will match <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible, this first skips over all lines until
the end of the file and then tries matching "END", backing up one
character at a time.
*<A NAME="/\+"></A><B>/\+</B>*
\+ Matches 1 or more of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible. {not in
Vi}
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
^.\+$ any non-empty line
\s\+ white space of at least one character
*<A NAME="/\="></A><B>/\=</B>*
\= Matches 0 or 1 of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible. {not in Vi}
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
foo\= "fo" and "foo"
*<A NAME="/\?"></A><B>/\?</B>*
\? Just like \=. Cannot be used when searching backwards with the "<A HREF="#?">?</A>"
command. {not in Vi}
*<A NAME="/\{"></A><B>/\{</B>* *<A NAME="E60"></A><B>E60</B>* *<A NAME="E554"></A><B>E554</B>* *<A NAME="E870"></A><B>E870</B>*
\{n,m} Matches <A HREF="#n">n</A> to <A HREF="motion.html#m">m</A> of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible
\{n} Matches <A HREF="#n">n</A> of the preceding atom
\{n,} Matches at least <A HREF="#n">n</A> of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible
\{,m} Matches 0 to <A HREF="motion.html#m">m</A> of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible
\{} Matches 0 or more of the preceding atom, <A HREF="motion.html#as">as</A> many <A HREF="motion.html#as">as</A> possible (like *)
*<A NAME="/\{-"></A><B>/\{-</B>*
\{-n,m} matches <A HREF="#n">n</A> to <A HREF="motion.html#m">m</A> of the preceding atom, <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible
\{-n} matches <A HREF="#n">n</A> of the preceding atom
\{-n,} matches at least <A HREF="#n">n</A> of the preceding atom, <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible
\{-,m} matches 0 to <A HREF="motion.html#m">m</A> of the preceding atom, <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible
\{-} matches 0 or more of the preceding atom, <A HREF="motion.html#as">as</A> few <A HREF="motion.html#as">as</A> possible
{Vi does not have any of these}
<A HREF="#n">n</A> and <A HREF="motion.html#m">m</A> are positive decimal numbers or zero
*<A NAME="non-greedy"></A><B>non-greedy</B>*
If a "<A HREF="motion.html#-">-</A>" appears immediately after the "<A HREF="motion.html#{">{</A>", then a shortest match
first algorithm is used (see example below). In particular, "\{-}" is
the same <A HREF="motion.html#as">as</A> "*" but uses the shortest match first algorithm. BUT: A
match that starts earlier is preferred over a shorter match: "a\{-}b"
matches "aaab" in "xaaab".
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
ab\{2,3}c "abbc" or "abbbc"
a\{5} "aaaaa"
ab\{2,}c "abbc", "abbbc", "abbbbc", etc.
ab\{,3}c "ac", "abc", "abbc" or "abbbc"
a[bc]\{3}d "abbbd", "abbcd", "acbcd", "acccd", etc.
a\(bc\)\{1,2}d "abcd" or "abcbcd"
a[bc]\{-}[cd] "abc" in "abcd"
a[bc]*[cd] "abcd" in "abcd"
The } may optionally be preceded with a <A HREF="intro.html#backslash">backslash</A>: \{n,m\}.
*<A NAME="/\@="></A><B>/\@=</B>*
\@= Matches the preceding atom with zero width. {not in Vi}
Like "(?=pattern)" in <A HREF="if_perl.html#Perl">Perl</A>.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
foo\(bar\)\@= "foo" in "foobar"
foo\(bar\)\@=foo nothing
*<A NAME="/zero-width"></A><B>/zero-width</B>*
When using "\@=" (or "<A HREF="motion.html#^">^</A>", "<A HREF="motion.html#$">$</A>", "\<", "\>") no characters are included
in the match. These items are only used to check if a match can be
made. This can be tricky, because a match with following items will
be done in the same position. The last example above will not match
"foobarfoo", because <A HREF="motion.html#it">it</A> tries match "foo" in the same position where
"<A HREF="motion.html#bar">bar</A>" matched.
Note that using "\&" works the same <A HREF="motion.html#as">as</A> using "\@=": "foo\&.." is the
same <A HREF="motion.html#as">as</A> "\(foo\)\@=..". But using "\&" is easier, you don't need the
braces.
*<A NAME="/\@!"></A><B>/\@!</B>*
\@! Matches with zero width if the preceding atom does NOT match at the
current position. |<A HREF="#/zero-width">/zero-width</A>| {not in Vi}
Like "(?!pattern)" in <A HREF="if_perl.html#Perl">Perl</A>.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
foo\(bar\)\@! any "foo" not followed by "<A HREF="motion.html#bar">bar</A>"
a.\{-}p\@! "<A HREF="insert.html#a">a</A>", "<A HREF="motion.html#ap">ap</A>", "app", "appp", etc. not immediately
followed by a "<A HREF="change.html#p">p</A>"
if \(\(then\)\@!.\)*$ "if " not followed by "then"
Using "\@!" is tricky, because there are many places where a <A HREF="#pattern">pattern</A>
does not match. "a.*p\@!" will match from an "<A HREF="insert.html#a">a</A>" to the end of the
line, because ".*" can match all characters in the line and the "<A HREF="change.html#p">p</A>"
doesn't match at the end of the line. "a.\{-}p\@!" will match any
"<A HREF="insert.html#a">a</A>", "<A HREF="motion.html#ap">ap</A>", "app", etc. that isn't followed by a "<A HREF="change.html#p">p</A>", because the "<A HREF="repeat.html#.">.</A>"
can match a "<A HREF="change.html#p">p</A>" and "p\@!" doesn't match after that.
You can't use "\@!" to look for a non-match before the matching
position: "\(foo\)\@!bar" will match "<A HREF="motion.html#bar">bar</A>" in "foobar", because at the
position where "<A HREF="motion.html#bar">bar</A>" matches, "foo" does not match. To avoid matching
"foobar" you could use "\(foo\)\@!...bar", but that doesn't match a
<A HREF="motion.html#bar">bar</A> at the start of a line. Use "\(foo\)\@<!bar".
Useful example: to find "foo" in a line that does not contain "<A HREF="motion.html#bar">bar</A>":
<B> /^\%(.*bar\)\@!.*\zsfoo</B>
This <A HREF="#pattern">pattern</A> first checks that there is not a single position in the
line where "<A HREF="motion.html#bar">bar</A>" matches. If ".*bar" matches somewhere the \@! will
reject the <A HREF="#pattern">pattern</A>. When there is no match any "foo" will be found.
The "\zs" is to have the match start just before "foo".
*<A NAME="/\@<="></A><B>/\@<=</B>*
\@<= Matches with zero width if the preceding atom matches just before what
follows. |<A HREF="#/zero-width">/zero-width</A>| {not in Vi}
Like "(?<=pattern)" in <A HREF="if_perl.html#Perl">Perl</A>, but Vim allows non-fixed-width patterns.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
\(an\_s\+\)\@<=file "file" after "an" and white space or an
end-of-line
For speed it's often much better to avoid this multi. Try using "\zs"
instead |<A HREF="#/\zs">/\zs</A>|. To match the same <A HREF="motion.html#as">as</A> the above example:
an\_s\+\zsfile
At least set a limit for the look-behind, see below.
"\@<=" and "\@<!" check for matches just before what follows.
Theoretically these matches could start anywhere before this position.
But to limit the time needed, only the line where what follows matches
is searched, and one line before that (if there is one). This should
be sufficient to match most things and not be too slow.
In the old <A HREF="#regexp">regexp</A> engine the part of the <A HREF="#pattern">pattern</A> after "\@<=" and
"\@<!" are checked for a match first, thus things like "\1" don't work
to reference \(\) inside the preceding atom. It does work the other
way around:
<B><FONT COLOR="PURPLE"> Bad example matches </FONT></B>
\%#=1\1\@<=,\([a-z]\+\) ",abc" in "abc,abc"
However, the new <A HREF="#regexp">regexp</A> engine works differently, <A HREF="motion.html#it">it</A> is better to not
rely on this behavior, <A HREF="diff.html#do">do</A> not use \@<= if <A HREF="motion.html#it">it</A> can be avoided:
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
\([a-z]\+\)\zs,\1 ",abc" in "abc,abc"
\@123<=
Like "\@<=" but only look back 123 bytes. This avoids trying lots
of matches that are known to fail and make executing the <A HREF="#pattern">pattern</A> very
slow. Example, check if there is a "<A HREF="change.html#<"><</A>" just before "span":
/<\@1<=span
This will try matching "<A HREF="change.html#<"><</A>" only one byte before "span", which is the
only place that works anyway.
After crossing a line boundary, the limit is relative to the end of
the line. Thus the characters at the start of the line with the match
are not counted (this is just to keep <A HREF="motion.html#it">it</A> simple).
The number zero is the same <A HREF="motion.html#as">as</A> no limit.
*<A NAME="/\@<!"></A><B>/\@<!</B>*
\@<! Matches with zero width if the preceding atom does NOT match just
before what follows. Thus this matches if there is no position in the
current or previous line where the atom matches such that <A HREF="motion.html#it">it</A> ends just
before what follows. |<A HREF="#/zero-width">/zero-width</A>| {not in Vi}
Like "(?<!pattern)" in <A HREF="if_perl.html#Perl">Perl</A>, but Vim allows non-fixed-width patterns.
The match with the preceding atom is made to end just before the match
with what follows, thus an atom that ends in ".*" will work.
Warning: This can be slow (because many positions need to be checked
for a match). Use a limit if you can, see below.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
\(foo\)\@<!bar any "<A HREF="motion.html#bar">bar</A>" that's not in "foobar"
\(\/\/.*\)\@<!in "in" which is not after "<A HREF="version7.html#//">//</A>"
\@123<!
Like "\@<!" but only look back 123 bytes. This avoids trying lots of
matches that are known to fail and make executing the <A HREF="#pattern">pattern</A> very
slow.
*<A NAME="/\@>"></A><B>/\@></B>*
\@> Matches the preceding atom like matching a whole <A HREF="#pattern">pattern</A>. {not in Vi}
Like "(?>pattern)" in <A HREF="if_perl.html#Perl">Perl</A>.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
\(a*\)\@>a nothing (the "a*" takes all the "a"'s, there can't be
another one following)
This matches the preceding atom <A HREF="motion.html#as">as</A> if <A HREF="motion.html#it">it</A> was a <A HREF="#pattern">pattern</A> by itself. If
<A HREF="motion.html#it">it</A> doesn't match, there is no retry with shorter sub-matches or
anything. Observe this difference: "a*b" and "a*ab" both match
"aaab", but in the second <A HREF="change.html#case">case</A> the "a*" matches only the first two
"a"s. "\(a*\)\@>ab" will not match "aaab", because the "a*" matches
the "aaa" (as many "<A HREF="insert.html#a">a</A>"s <A HREF="motion.html#as">as</A> possible), thus the "<A HREF="motion.html#ab">ab</A>" can't match.
==============================================================================
6. Ordinary atoms *<A NAME="pattern-atoms"></A><B>pattern-atoms</B>*
An ordinary atom can be:
*<A NAME="/^"></A><B>/^</B>*
^ At beginning of <A HREF="#pattern">pattern</A> or after "\|", "\(", "\%(" or "\n": matches
start-of-line; at other positions, matches literal '<A HREF="motion.html#^">^</A>'. |<A HREF="#/zero-width">/zero-width</A>|
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
^beep( the start of the C function "beep" (probably).
*<A NAME="/\^"></A><B>/\^</B>*
\^ Matches literal '<A HREF="motion.html#^">^</A>'. Can be used at any position in the <A HREF="#pattern">pattern</A>.
*<A NAME="/\_^"></A><B>/\_^</B>*
\_^ Matches start-of-line. |<A HREF="#/zero-width">/zero-width</A>| Can be used at any position in
the <A HREF="#pattern">pattern</A>.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
\_s*\_^foo white space and blank lines and then "foo" at
start-of-line
*<A NAME="/$"></A><B>/$</B>*
$ At end of <A HREF="#pattern">pattern</A> or in front of "\|", "\)" or "\n" ('magic' on):
matches end-of-line <A HREF="intro.html#<EOL>"><EOL></A>; at other positions, matches literal '<A HREF="motion.html#$">$</A>'.
|<A HREF="#/zero-width">/zero-width</A>|
*<A NAME="/\$"></A><B>/\$</B>*
\$ Matches literal '<A HREF="motion.html#$">$</A>'. Can be used at any position in the <A HREF="#pattern">pattern</A>.
*<A NAME="/\_$"></A><B>/\_$</B>*
\_$ Matches end-of-line. |<A HREF="#/zero-width">/zero-width</A>| Can be used at any position in the
<A HREF="#pattern">pattern</A>. Note that "a\_$b" never matches, since "<A HREF="motion.html#b">b</A>" cannot match an
end-of-line. Use "a\nb" instead |<A HREF="#/\n">/\n</A>|.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
foo\_$\_s* "foo" at end-of-line and following white space and
blank lines
. (with <A HREF="options.html#'nomagic'">'nomagic'</A>: \.) *<A NAME="/."></A><B>/.</B>* *<A NAME="/\."></A><B>/\.</B>*
Matches any single character, but not an end-of-line.
*<A NAME="/\_."></A><B>/\_.</B>*
\_. Matches any single character or end-of-line.
Careful: "\_.*" matches all text to the end of the buffer!
*<A NAME="/\<"></A><B>/\<</B>*
\< Matches the beginning of a <A HREF="motion.html#word">word</A>: The next char is the first char of a
<A HREF="motion.html#word">word</A>. The <A HREF="options.html#'iskeyword'">'iskeyword'</A> option specifies what is a <A HREF="motion.html#word">word</A> character.
|<A HREF="#/zero-width">/zero-width</A>|
*<A NAME="/\>"></A><B>/\></B>*
\> Matches the end of a <A HREF="motion.html#word">word</A>: The previous char is the last char of a
<A HREF="motion.html#word">word</A>. The <A HREF="options.html#'iskeyword'">'iskeyword'</A> option specifies what is a <A HREF="motion.html#word">word</A> character.
|<A HREF="#/zero-width">/zero-width</A>|
*<A NAME="/\zs"></A><B>/\zs</B>*
\zs Matches at any position, and sets the start of the match there: The
next char is the first char of the whole match. |<A HREF="#/zero-width">/zero-width</A>|
Example:
<B> /^\s*\zsif</B>
matches an "if" at the start of a line, ignoring white space.
Can be used multiple times, the last one encountered in a matching
branch is used. Example:
<B> /\(.\{-}\zsFab\)\{3}</B>
Finds the third occurrence of "Fab".
This cannot be followed by a multi. *<A NAME="E888"></A><B>E888</B>*
{not in Vi} {not available when compiled without the |<A HREF="various.html#+syntax">+syntax</A>| feature}
*<A NAME="/\ze"></A><B>/\ze</B>*
\ze Matches at any position, and sets the end of the match there: The
previous char is the last char of the whole match. |<A HREF="#/zero-width">/zero-width</A>|
Can be used multiple times, the last one encountered in a matching
branch is used.
Example: "end\ze\(if\|for\)" matches the "end" in "endif" and
"endfor".
This cannot be followed by a multi. |<A HREF="#E888">E888</A>|
{not in Vi} {not available when compiled without the |<A HREF="various.html#+syntax">+syntax</A>| feature}
*<A NAME="/\%^"></A><B>/\%^</B>* *<A NAME="start-of-file"></A><B>start-of-file</B>*
\%^ Matches start of the file. When matching with a <A HREF="eval.html#string">string</A>, matches the
start of the <A HREF="eval.html#string">string</A>. {not in Vi}
For example, to find the first "VIM" in a file:
<B> /\%^\_.\{-}\zsVIM</B>
*<A NAME="/\%$"></A><B>/\%$</B>* *<A NAME="end-of-file"></A><B>end-of-file</B>*
\%$ Matches end of the file. When matching with a <A HREF="eval.html#string">string</A>, matches the
end of the <A HREF="eval.html#string">string</A>. {not in Vi}
Note that this does NOT find the last "VIM" in a file:
<B> /VIM\_.\{-}\%$</B>
It will find the next VIM, because the part after <A HREF="motion.html#it">it</A> will always
match. This one will find the last "VIM" in the file:
<B> /VIM\ze\(\(VIM\)\@!\_.\)*\%$</B>
This uses |<A HREF="#/\@!">/\@!</A>| to ascertain that "VIM" does NOT match in any
position after the first "VIM".
Searching from the end of the file backwards is easier!
*<A NAME="/\%V"></A><B>/\%V</B>*
\%V Match inside the <A HREF="visual.html#Visual">Visual</A> area. When <A HREF="visual.html#Visual">Visual</A> mode has already been
stopped match in the area that |<A HREF="visual.html#gv">gv</A>| would reselect.
This is a |<A HREF="#/zero-width">/zero-width</A>| match. To make sure the whole <A HREF="#pattern">pattern</A> is
inside the <A HREF="visual.html#Visual">Visual</A> area put <A HREF="motion.html#it">it</A> at the start and just before the end of
the <A HREF="#pattern">pattern</A>, e.g.:
<B> /\%Vfoo.*ba\%Vr</B>
This also works if only "foo bar" was Visually selected. This:
<B> /\%Vfoo.*bar\%V</B>
would match "foo bar" if the <A HREF="visual.html#Visual">Visual</A> selection continues after the "<A HREF="change.html#r">r</A>".
Only works for the current buffer.
*<A NAME="/\%#"></A><B>/\%#</B>* *<A NAME="cursor-position"></A><B>cursor-position</B>*
\%# Matches with the cursor position. Only works when matching in a
buffer displayed in a <A HREF="windows.html#window">window</A>. {not in Vi}
WARNING: When the cursor is moved after the <A HREF="#pattern">pattern</A> was used, the
result becomes invalid. Vim doesn't automatically update the matches.
This is especially relevant for <A HREF="syntax.html#syntax">syntax</A> highlighting and <A HREF="options.html#'hlsearch'">'hlsearch'</A>.
In other words: When the cursor moves the display isn't updated for
this change. An update is done for lines which are changed (the whole
line is updated) or when using the |<A HREF="various.html#CTRL-L">CTRL-L</A>| command (the whole screen
is updated). Example, to highlight the <A HREF="motion.html#word">word</A> under the cursor:
<B> /\k*\%#\k*</B>
When <A HREF="options.html#'hlsearch'">'hlsearch'</A> is set and you move the cursor around and make changes
this will clearly show when the match is updated or not.
*<A NAME="/\%'m"></A><B>/\%'m</B>* *<A NAME="/\%<'m"></A><B>/\%<'m</B>* *<A NAME="/\%>'m"></A><B>/\%>'m</B>*
\%'m Matches with the position of <A HREF="motion.html#mark">mark</A> <A HREF="motion.html#m">m</A>.
\%<'m Matches before the position of <A HREF="motion.html#mark">mark</A> <A HREF="motion.html#m">m</A>.
\%>'m Matches after the position of <A HREF="motion.html#mark">mark</A> <A HREF="motion.html#m">m</A>.
Example, to highlight the text from <A HREF="motion.html#mark">mark</A> 's to 'e:
<B> /.\%>'s.*\%<'e..</B>
Note that two dots are required to include <A HREF="motion.html#mark">mark</A> 'e in the match. That
is because "\%<'e" matches at the character before the 'e <A HREF="motion.html#mark">mark</A>, and
since it's a |<A HREF="#/zero-width">/zero-width</A>| match <A HREF="motion.html#it">it</A> doesn't include that character.
{not in Vi}
WARNING: When the <A HREF="motion.html#mark">mark</A> is moved after the <A HREF="#pattern">pattern</A> was used, the result
becomes invalid. Vim doesn't automatically update the matches.
Similar to moving the cursor for "\%#" |<A HREF="#/\%#">/\%#</A>|.
*<A NAME="/\%l"></A><B>/\%l</B>* *<A NAME="/\%>l"></A><B>/\%>l</B>* *<A NAME="/\%<l"></A><B>/\%<l</B>*
\%23l Matches in a specific line.
\%<23l Matches above a specific line (lower line number).
\%>23l Matches below a specific line (higher line number).
These three can be used to match specific lines in a buffer. The "23"
can be any line number. The first line is 1. {not in Vi}
WARNING: When <A HREF="insert.html#inserting">inserting</A> or <A HREF="change.html#deleting">deleting</A> lines Vim does not automatically
update the matches. This means <A HREF="autocmd.html#Syntax">Syntax</A> highlighting quickly becomes
wrong.
Example, to highlight the line where the cursor currently is:
<B> :exe '/\%' . line(".") . 'l.*'</B>
When <A HREF="options.html#'hlsearch'">'hlsearch'</A> is set and you move the cursor around and make changes
this will clearly show when the match is updated or not.
*<A NAME="/\%c"></A><B>/\%c</B>* *<A NAME="/\%>c"></A><B>/\%>c</B>* *<A NAME="/\%<c"></A><B>/\%<c</B>*
\%23c Matches in a specific column.
\%<23c Matches before a specific column.
\%>23c Matches after a specific column.
These three can be used to match specific columns in a buffer or
<A HREF="eval.html#string">string</A>. The "23" can be any column number. The first column is 1.
Actually, the column is the byte number (thus it's not exactly right
for <A HREF="mbyte.html#multi-byte">multi-byte</A> characters). {not in Vi}
WARNING: When <A HREF="insert.html#inserting">inserting</A> or <A HREF="change.html#deleting">deleting</A> text Vim does not automatically
update the matches. This means <A HREF="autocmd.html#Syntax">Syntax</A> highlighting quickly becomes
wrong.
Example, to highlight the column where the cursor currently is:
<B> :exe '/\%' . col(".") . 'c'</B>
When <A HREF="options.html#'hlsearch'">'hlsearch'</A> is set and you move the cursor around and make changes
this will clearly show when the match is updated or not.
Example for matching a single byte in column 44:
<B> /\%>43c.\%<46c</B>
Note that "\%<46c" matches in column 45 when the "<A HREF="repeat.html#.">.</A>" matches a byte in
column 44.
*<A NAME="/\%v"></A><B>/\%v</B>* *<A NAME="/\%>v"></A><B>/\%>v</B>* *<A NAME="/\%<v"></A><B>/\%<v</B>*
\%23v Matches in a specific virtual column.
\%<23v Matches before a specific virtual column.
\%>23v Matches after a specific virtual column.
These three can be used to match specific virtual columns in a buffer
or <A HREF="eval.html#string">string</A>. When not matching with a buffer in a <A HREF="windows.html#window">window</A>, the option
values of the current <A HREF="windows.html#window">window</A> are used (e.g., <A HREF="options.html#'tabstop'">'tabstop'</A>).
The "23" can be any column number. The first column is 1.
Note that some virtual column positions will never match, because they
are halfway through a <A HREF="intro.html#tab">tab</A> or other character that occupies more than
one screen character. {not in Vi}
WARNING: When <A HREF="insert.html#inserting">inserting</A> or <A HREF="change.html#deleting">deleting</A> text Vim does not automatically
update highlighted matches. This means <A HREF="autocmd.html#Syntax">Syntax</A> highlighting quickly
becomes wrong.
Example, to highlight all the characters after virtual column 72:
<B> /\%>72v.*</B>
When <A HREF="options.html#'hlsearch'">'hlsearch'</A> is set and you move the cursor around and make changes
this will clearly show when the match is updated or not.
To match the text up to column 17:
<B> /^.*\%17v</B>
Column 17 is not included, because this is a |<A HREF="#/zero-width">/zero-width</A>| match. To
include the column use:
<B> /^.*\%17v.</B>
This command does the same thing, but also matches when there is no
character in column 17:
<B> /^.*\%<18v.</B>
Note that without the "<A HREF="motion.html#^">^</A>" to anchor the match in the first column,
this will also highlight column 17:
<B> /.*\%17v</B>
Column 17 is highlighted by <A HREF="options.html#'hlsearch'">'hlsearch'</A> because there is another match
where ".*" matches zero characters.
<A HREF="change.html#<"><</A>
Character classes: {not in Vi}
\i identifier character (see <A HREF="options.html#'isident'">'isident'</A> option) *<A NAME="/\i"></A><B>/\i</B>*
\I like "\i", but excluding digits *<A NAME="/\I"></A><B>/\I</B>*
\k keyword character (see <A HREF="options.html#'iskeyword'">'iskeyword'</A> option) *<A NAME="/\k"></A><B>/\k</B>*
\K like "\k", but excluding digits *<A NAME="/\K"></A><B>/\K</B>*
\f file name character (see <A HREF="options.html#'isfname'">'isfname'</A> option) *<A NAME="/\f"></A><B>/\f</B>*
\F like "\f", but excluding digits *<A NAME="/\F"></A><B>/\F</B>*
\p printable character (see <A HREF="options.html#'isprint'">'isprint'</A> option) *<A NAME="/\p"></A><B>/\p</B>*
\P like "\p", but excluding digits *<A NAME="/\P"></A><B>/\P</B>*
NOTE: the above also work for <A HREF="mbyte.html#multi-byte">multi-byte</A> characters. The ones below only
match ASCII characters, <A HREF="motion.html#as">as</A> indicated by the range.
*<A NAME="whitespace"></A><B>whitespace</B>* *<A NAME="white-space"></A><B>white-space</B>*
\s <A HREF="#whitespace">whitespace</A> character: <A HREF="motion.html#<Space>"><Space></A> and <A HREF="motion.html#<Tab>"><Tab></A> *<A NAME="/\s"></A><B>/\s</B>*
\S non-whitespace character; opposite of \s *<A NAME="/\S"></A><B>/\S</B>*
\d digit: [0-9] *<A NAME="/\d"></A><B>/\d</B>*
\D non-digit: [^0-9] *<A NAME="/\D"></A><B>/\D</B>*
\x hex digit: [0-9A-Fa-f] *<A NAME="/\x"></A><B>/\x</B>*
\X non-hex digit: [^0-9A-Fa-f] *<A NAME="/\X"></A><B>/\X</B>*
\o <A HREF="eval.html#octal">octal</A> digit: [0-7] *<A NAME="/\o"></A><B>/\o</B>*
\O non-octal digit: [^0-7] *<A NAME="/\O"></A><B>/\O</B>*
\w <A HREF="motion.html#word">word</A> character: [0-9A-Za-z_] *<A NAME="/\w"></A><B>/\w</B>*
\W non-word character: [^0-9A-Za-z_] *<A NAME="/\W"></A><B>/\W</B>*
\h head of <A HREF="motion.html#word">word</A> character: [A-Za-z_] *<A NAME="/\h"></A><B>/\h</B>*
\H non-head of <A HREF="motion.html#word">word</A> character: [^A-Za-z_] *<A NAME="/\H"></A><B>/\H</B>*
\a alphabetic character: [A-Za-z] *<A NAME="/\a"></A><B>/\a</B>*
\A non-alphabetic character: [^A-Za-z] *<A NAME="/\A"></A><B>/\A</B>*
\l <A HREF="change.html#lowercase">lowercase</A> character: [a-z] *<A NAME="/\l"></A><B>/\l</B>*
\L non-lowercase character: [^a-z] *<A NAME="/\L"></A><B>/\L</B>*
\u <A HREF="change.html#uppercase">uppercase</A> character: [A-Z] *<A NAME="/\u"></A><B>/\u</B>*
\U non-uppercase character: [^A-Z] *<A NAME="/\U"></A><B>/\U</B>*
NOTE: Using the atom is faster than the <A HREF="motion.html#[]">[]</A> form.
NOTE: <A HREF="options.html#'ignorecase'">'ignorecase'</A>, "\c" and "\C" are not used by character classes.
*<A NAME="/\_"></A><B>/\_</B>* *<A NAME="E63"></A><B>E63</B>* *<A NAME="/\_i"></A><B>/\_i</B>* *<A NAME="/\_I"></A><B>/\_I</B>* *<A NAME="/\_k"></A><B>/\_k</B>* *<A NAME="/\_K"></A><B>/\_K</B>* *<A NAME="/\_f"></A><B>/\_f</B>* *<A NAME="/\_F"></A><B>/\_F</B>*
*<A NAME="/\_p"></A><B>/\_p</B>* *<A NAME="/\_P"></A><B>/\_P</B>* *<A NAME="/\_s"></A><B>/\_s</B>* *<A NAME="/\_S"></A><B>/\_S</B>* *<A NAME="/\_d"></A><B>/\_d</B>* *<A NAME="/\_D"></A><B>/\_D</B>* *<A NAME="/\_x"></A><B>/\_x</B>* *<A NAME="/\_X"></A><B>/\_X</B>*
*<A NAME="/\_o"></A><B>/\_o</B>* *<A NAME="/\_O"></A><B>/\_O</B>* *<A NAME="/\_w"></A><B>/\_w</B>* *<A NAME="/\_W"></A><B>/\_W</B>* *<A NAME="/\_h"></A><B>/\_h</B>* *<A NAME="/\_H"></A><B>/\_H</B>* *<A NAME="/\_a"></A><B>/\_a</B>* *<A NAME="/\_A"></A><B>/\_A</B>*
*<A NAME="/\_l"></A><B>/\_l</B>* *<A NAME="/\_L"></A><B>/\_L</B>* *<A NAME="/\_u"></A><B>/\_u</B>* *<A NAME="/\_U"></A><B>/\_U</B>*
\_x Where "<A HREF="change.html#x">x</A>" is any of the characters above: The character class with
end-of-line added
(end of character classes)
\e matches <A HREF="intro.html#<Esc>"><Esc></A> *<A NAME="/\e"></A><B>/\e</B>*
\t matches <A HREF="motion.html#<Tab>"><Tab></A> *<A NAME="/\t"></A><B>/\t</B>*
\r matches <A HREF="motion.html#<CR>"><CR></A> *<A NAME="/\r"></A><B>/\r</B>*
\b matches <A HREF="motion.html#<BS>"><BS></A> *<A NAME="/\b"></A><B>/\b</B>*
\n matches an end-of-line *<A NAME="/\n"></A><B>/\n</B>*
When matching in a <A HREF="eval.html#string">string</A> instead of buffer text a literal newline
character is matched.
~ matches the last given substitute <A HREF="eval.html#string">string</A> *<A NAME="/~"></A><B>/~</B>* *<A NAME="/\~"></A><B>/\~</B>*
\(\) A <A HREF="#pattern">pattern</A> enclosed by escaped parentheses. *<A NAME="/\("></A><B>/\(</B>* *<A NAME="/\(\)"></A><B>/\(\)</B>* *<A NAME="/\)"></A><B>/\)</B>*
E.g., "\(^a\)" matches '<A HREF="insert.html#a">a</A>' at the start of a line.
*<A NAME="E51"></A><B>E51</B>* *<A NAME="E54"></A><B>E54</B>* *<A NAME="E55"></A><B>E55</B>* *<A NAME="E872"></A><B>E872</B>* *<A NAME="E873"></A><B>E873</B>*
\1 Matches the same <A HREF="eval.html#string">string</A> that was matched by *<A NAME="/\1"></A><B>/\1</B>* *<A NAME="E65"></A><B>E65</B>*
the first sub-expression in \( and \). {not in Vi}
Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc.
\2 Like "\1", but uses second sub-expression, *<A NAME="/\2"></A><B>/\2</B>*
<A HREF="eval.html#...">...</A> *<A NAME="/\3"></A><B>/\3</B>*
\9 Like "\1", but uses ninth sub-expression. *<A NAME="/\9"></A><B>/\9</B>*
Note: The numbering of groups is done based on which "\(" comes first
in the <A HREF="#pattern">pattern</A> (going left to right), NOT based on what is matched
first.
\%(\) A <A HREF="#pattern">pattern</A> enclosed by escaped parentheses. *<A NAME="/\%(\)"></A><B>/\%(\)</B>* *<A NAME="/\%("></A><B>/\%(</B>* *<A NAME="E53"></A><B>E53</B>*
Just like \(\), but without counting <A HREF="motion.html#it">it</A> <A HREF="motion.html#as">as</A> a sub-expression. This
allows using more groups and it's a little bit faster.
{not in Vi}
<A HREF="change.html#x">x</A> A single character, with no special meaning, matches itself
*<A NAME="/\"></A><B>/\</B>* *<A NAME="/\\"></A><B>/\\</B>*
\x A <A HREF="intro.html#backslash">backslash</A> followed by a single character, with no special meaning,
is reserved for future expansions
<A HREF="motion.html#[]">[]</A> (with <A HREF="options.html#'nomagic'">'nomagic'</A>: \[]) *<A NAME="/[]"></A><B>/[]</B>* *<A NAME="/\[]"></A><B>/\[]</B>* *<A NAME="/\_[]"></A><B>/\_[]</B>* *<A NAME="/collection"></A><B>/collection</B>*
\_[]
A collection. This is a sequence of characters enclosed in brackets.
It matches any single character in the collection.
<B><FONT COLOR="PURPLE"> Example matches </FONT></B>
[xyz] any '<A HREF="change.html#x">x</A>', '<A HREF="change.html#y">y</A>' or '<A HREF="index.html#z">z</A>'
[a-zA-Z]$ any alphabetic character at the end of a line
\c[a-z]$ same
[А-яЁё] <A HREF="russian.html#Russian">Russian</A> alphabet (with <A HREF="mbyte.html#utf-8">utf-8</A> and cp1251)
*<A NAME="/[\n]"></A><B>/[\n]</B>*
With "\_" prepended the collection also includes the end-of-line.
The same can be done by including "\n" in the collection. The
end-of-line is also matched when the collection starts with "<A HREF="motion.html#^">^</A>"! Thus
"\_[^ab]" matches the end-of-line and any character but "<A HREF="insert.html#a">a</A>" and "<A HREF="motion.html#b">b</A>".
This makes <A HREF="motion.html#it">it</A> <A HREF="intro.html#Vi">Vi</A> compatible: Without the "\_" or "\n" the collection
does not match an end-of-line.
*<A NAME="E769"></A><B>E769</B>*
When the '<A HREF="index.html#]">]</A>' is not there Vim will not give an error message but
assume no collection is used. Useful to search for '<A HREF="index.html#[">[</A>'. However, you
<A HREF="diff.html#do">do</A> get <A HREF="#E769">E769</A> for internal searching. And be aware that in a
`:substitute` command the whole command becomes the <A HREF="#pattern">pattern</A>. E.g.
":s/[/x/" searches for "[/x" and replaces <A HREF="motion.html#it">it</A> with nothing. It does
not search for "<A HREF="index.html#[">[</A>" and replaces <A HREF="motion.html#it">it</A> with "<A HREF="change.html#x">x</A>"!
*<A NAME="E944"></A><B>E944</B>* *<A NAME="E945"></A><B>E945</B>*
If the sequence begins with "<A HREF="motion.html#^">^</A>", <A HREF="motion.html#it">it</A> matches any single character NOT
in the collection: "[^xyz]" matches anything but '<A HREF="change.html#x">x</A>', '<A HREF="change.html#y">y</A>' and '<A HREF="index.html#z">z</A>'.
- If two characters in the sequence are separated by '<A HREF="motion.html#-">-</A>', this is
shorthand for the full <A HREF="eval.html#list">list</A> of ASCII characters between them. E.g.,
"[0-9]" matches any decimal digit. If the starting character exceeds
the ending character, e.g. [c-a], <A HREF="#E944">E944</A> occurs. Non-ASCII characters
can be used, but the character values must not be more than 256 apart
in the old <A HREF="#regexp">regexp</A> engine. For example, searching by [\u3000-\u4000]
after setting re=1 emits a <A HREF="#E945">E945</A> error. Prepending \%#=2 will fix <A HREF="motion.html#it">it</A>.
- A character class <A HREF="eval.html#expression">expression</A> is evaluated to the set of characters
belonging to that character class. The following character classes
are supported:
<B><FONT COLOR="PURPLE"> Name Func Contents </FONT></B>
*<A NAME="[:alnum:]"></A><B>[:alnum:]</B>* <A HREF="#[:alnum:]">[:alnum:]</A> isalnum ASCII letters and digits
*<A NAME="[:alpha:]"></A><B>[:alpha:]</B>* <A HREF="#[:alpha:]">[:alpha:]</A> isalpha ASCII letters
*<A NAME="[:blank:]"></A><B>[:blank:]</B>* <A HREF="#[:blank:]">[:blank:]</A> space and <A HREF="intro.html#tab">tab</A>
*<A NAME="[:cntrl:]"></A><B>[:cntrl:]</B>* <A HREF="#[:cntrl:]">[:cntrl:]</A> iscntrl ASCII <A HREF="intro.html#control">control</A> characters
*<A NAME="[:digit:]"></A><B>[:digit:]</B>* <A HREF="#[:digit:]">[:digit:]</A> decimal digits '<A HREF="motion.html#0">0</A>' to '9'
*<A NAME="[:graph:]"></A><B>[:graph:]</B>* <A HREF="#[:graph:]">[:graph:]</A> isgraph ASCII printable characters excluding
space
*<A NAME="[:lower:]"></A><B>[:lower:]</B>* <A HREF="#[:lower:]">[:lower:]</A> (1) <A HREF="change.html#lowercase">lowercase</A> letters (all letters when
<A HREF="options.html#'ignorecase'">'ignorecase'</A> is used)
*<A NAME="[:print:]"></A><B>[:print:]</B>* <A HREF="#[:print:]">[:print:]</A> (2) printable characters including space
*<A NAME="[:punct:]"></A><B>[:punct:]</B>* <A HREF="#[:punct:]">[:punct:]</A> ispunct ASCII punctuation characters
*<A NAME="[:space:]"></A><B>[:space:]</B>* <A HREF="#[:space:]">[:space:]</A> <A HREF="#whitespace">whitespace</A> characters: space, <A HREF="intro.html#tab">tab</A>, CR,
NL, vertical <A HREF="intro.html#tab">tab</A>, form feed
*<A NAME="[:upper:]"></A><B>[:upper:]</B>* <A HREF="#[:upper:]">[:upper:]</A> (3) <A HREF="change.html#uppercase">uppercase</A> letters (all letters when
<A HREF="options.html#'ignorecase'">'ignorecase'</A> is used)
*<A NAME="[:xdigit:]"></A><B>[:xdigit:]</B>* <A HREF="#[:xdigit:]">[:xdigit:]</A> hexadecimal digits: 0-9, a-f, A-F
*<A NAME="[:return:]"></A><B>[:return:]</B>* <A HREF="#[:return:]">[:return:]</A> the <A HREF="motion.html#<CR>"><CR></A> character
*<A NAME="[:tab:]"></A><B>[:tab:]</B>* <A HREF="#[:tab:]">[:tab:]</A> the <A HREF="motion.html#<Tab>"><Tab></A> character
*<A NAME="[:escape:]"></A><B>[:escape:]</B>* <A HREF="#[:escape:]">[:escape:]</A> the <A HREF="intro.html#<Esc>"><Esc></A> character
*<A NAME="[:backspace:]"></A><B>[:backspace:]</B>* <A HREF="#[:backspace:]">[:backspace:]</A> the <A HREF="motion.html#<BS>"><BS></A> character
The brackets in character class expressions are additional to the
brackets delimiting a collection. For example, the following is a
plausible <A HREF="#pattern">pattern</A> for a UNIX filename: "[-./[:alnum:]_~]\+" That is,
a <A HREF="eval.html#list">list</A> of at least one character, each of which is either '<A HREF="motion.html#-">-</A>', '<A HREF="repeat.html#.">.</A>',
'<A HREF="#/">/</A>', alphabetic, numeric, '<A HREF="motion.html#_">_</A>' or '<A HREF="change.html#~">~</A>'.
These items only work for 8-bit characters, except <A HREF="#[:lower:]">[:lower:]</A> and
<A HREF="#[:upper:]">[:upper:]</A> also work for <A HREF="mbyte.html#multi-byte">multi-byte</A> characters when using the new
<A HREF="#regexp">regexp</A> engine. See |<A HREF="#two-engines">two-engines</A>|. In the future these items may
work for <A HREF="mbyte.html#multi-byte">multi-byte</A> characters. For now, to get all "alpha"
characters you can use: [[:lower:][:upper:]].
The "Func" column shows what library function is used. The
implementation depends on the system. Otherwise:
(1) Uses islower() for ASCII and Vim builtin rules for other
characters when built with the |<A HREF="various.html#+multi_byte">+multi_byte</A>| feature.
(2) Uses Vim builtin rules
(3) As with (1) but using isupper()
*<A NAME="/[[="></A><B>/[[=</B>* *<A NAME="[==]"></A><B>[==]</B>*
- An equivalence class. This means that characters are matched that
have almost the same meaning, e.g., when ignoring accents. This
only works for <A HREF="mbyte.html#Unicode">Unicode</A>, latin1 and latin9. The form is:
[=a=]
*<A NAME="/[[."></A><B>/[[.</B>* *<A NAME="[..]"></A><B>[..]</B>*
- A collation element. This currently simply accepts a single
character in the form:
[.a.]
*<A NAME="/\]"></A><B>/\]</B>*
- To include a literal '<A HREF="index.html#]">]</A>', '<A HREF="motion.html#^">^</A>', '<A HREF="motion.html#-">-</A>' or '\' in the collection, put a
<A HREF="intro.html#backslash">backslash</A> before <A HREF="motion.html#it">it</A>: "[xyz\]]", "[\^xyz]", "[xy\-z]" and "[xyz\\]".
(Note: POSIX does not support the use of a <A HREF="intro.html#backslash">backslash</A> this way). For
'<A HREF="index.html#]">]</A>' you can also make <A HREF="motion.html#it">it</A> the first character (following a possible
"^"): "[]xyz]" or "[^]xyz]" {not in Vi}.
For '<A HREF="motion.html#-">-</A>' you can also make <A HREF="motion.html#it">it</A> the first or last character: "[-xyz]",
"[^-xyz]" or "[xyz-]". For '\' you can also let <A HREF="motion.html#it">it</A> be followed by
any character that's not in "^]-\bdertnoUux". "[\xyz]" matches '\',
'<A HREF="change.html#x">x</A>', '<A HREF="change.html#y">y</A>' and '<A HREF="index.html#z">z</A>'. It's better to use "\\" though, future expansions
may use other characters after '\'.
- Omitting the trailing ] is not considered an error. "<A HREF="motion.html#[]">[]</A>" works like
"[]]", <A HREF="motion.html#it">it</A> matches the '<A HREF="index.html#]">]</A>' character.
- The following translations are accepted when the '<A HREF="motion.html#l">l</A>' flag is not
included in <A HREF="options.html#'cpoptions'">'cpoptions'</A> {not in Vi}:
\e <A HREF="intro.html#<Esc>"><Esc></A>
\t <A HREF="motion.html#<Tab>"><Tab></A>
\r <A HREF="motion.html#<CR>"><CR></A> (NOT end-of-line!)
\b <A HREF="motion.html#<BS>"><BS></A>
\n line break, see above |<A HREF="#/[\n]">/[\n]</A>|
\d123 decimal number of character
\o40 <A HREF="eval.html#octal">octal</A> number of character up to 0377
\x20 hexadecimal number of character up to 0xff
\u20AC hex. number of <A HREF="mbyte.html#multibyte">multibyte</A> character up to 0xffff
\U1234 hex. number of <A HREF="mbyte.html#multibyte">multibyte</A> character up to 0xffffffff
NOTE: The other <A HREF="intro.html#backslash">backslash</A> codes mentioned above <A HREF="diff.html#do">do</A> not work inside
<A HREF="motion.html#[]">[]</A>!
- Matching with a collection can be slow, because each character in
the text has to be compared with each character in the collection.
Use one of the other atoms above when possible. Example: "\d" is
much faster than "[0-9]" and matches the same characters.
*<A NAME="/\%[]"></A><B>/\%[]</B>* *<A NAME="E69"></A><B>E69</B>* *<A NAME="E70"></A><B>E70</B>* *<A NAME="E369"></A><B>E369</B>*
\%[] A sequence of optionally matched atoms. This always matches.
It matches <A HREF="motion.html#as">as</A> much of the <A HREF="eval.html#list">list</A> of atoms <A HREF="motion.html#it">it</A> contains <A HREF="motion.html#as">as</A> possible. Thus
<A HREF="motion.html#it">it</A> stops at the first atom that doesn't match. For example:
<B> /r\%[ead]</B>
matches "<A HREF="change.html#r">r</A>", "re", "rea" or "read". The longest that matches is used.
To match the <A HREF="intro.html#Ex">Ex</A> command "function", where "fu" is required and
"nction" is optional, this would work:
<B> /\<fu\%[nction]\></B>
The end-of-word atom "\>" is used to avoid matching "fu" in "full".
It gets more complicated when the atoms are not ordinary characters.
You don't often have to use <A HREF="motion.html#it">it</A>, but <A HREF="motion.html#it">it</A> is possible. Example:
<B> /\<r\%[[eo]ad]\></B>
Matches the words "<A HREF="change.html#r">r</A>", "re", "ro", "rea", "roa", "read" and "road".
There can be no \(\), \%(\) or \z(\) items inside the <A HREF="motion.html#[]">[]</A> and \%[] does
not nest.
To include a "<A HREF="index.html#[">[</A>" use "[[]" and for "<A HREF="index.html#]">]</A>" use []]", e.g.,:
<B> /index\%[[[]0[]]]</B>
matches "index" "index[", "index[0" and "index[0]".
{not available when compiled without the |<A HREF="various.html#+syntax">+syntax</A>| feature}
*<A NAME="/\%d"></A><B>/\%d</B>* *<A NAME="/\%x"></A><B>/\%x</B>* *<A NAME="/\%o"></A><B>/\%o</B>* *<A NAME="/\%u"></A><B>/\%u</B>* *<A NAME="/\%U"></A><B>/\%U</B>* *<A NAME="E678"></A><B>E678</B>*
\%d123 Matches the character specified with a decimal number. Must be
followed by a non-digit.
\%o40 Matches the character specified with an <A HREF="eval.html#octal">octal</A> number up to 0377.
Numbers below 040 must be followed by a non-octal digit or a non-digit.
\%x2a Matches the character specified with up to two hexadecimal characters.
\%u20AC Matches the character specified with up to four hexadecimal
characters.
\%U1234abcd Matches the character specified with up to eight hexadecimal
characters.
==============================================================================
7. Ignoring <A HREF="change.html#case">case</A> in a <A HREF="#pattern">pattern</A> *<A NAME="/ignorecase"></A><B>/ignorecase</B>*
If the <A HREF="options.html#'ignorecase'">'ignorecase'</A> option is on, the <A HREF="change.html#case">case</A> of normal letters is ignored.
<A HREF="options.html#'smartcase'">'smartcase'</A> can be set to ignore <A HREF="change.html#case">case</A> when the <A HREF="#pattern">pattern</A> contains <A HREF="change.html#lowercase">lowercase</A>
letters only.
*<A NAME="/\c"></A><B>/\c</B>* *<A NAME="/\C"></A><B>/\C</B>*
When "\c" appears anywhere in the <A HREF="#pattern">pattern</A>, the whole <A HREF="#pattern">pattern</A> is handled like
<A HREF="options.html#'ignorecase'">'ignorecase'</A> is on. The actual value of <A HREF="options.html#'ignorecase'">'ignorecase'</A> and <A HREF="options.html#'smartcase'">'smartcase'</A> is
ignored. "\C" does the opposite: Force matching <A HREF="change.html#case">case</A> for the whole <A HREF="#pattern">pattern</A>.
{only Vim supports \c and \C}
Note that <A HREF="options.html#'ignorecase'">'ignorecase'</A>, "\c" and "\C" are not used for the character classes.
Examples:
<B><FONT COLOR="PURPLE"> pattern 'ignorecase' 'smartcase' matches </FONT></B>
foo off - foo
foo on - foo Foo FOO
Foo on off foo Foo FOO
Foo on on Foo
\cfoo - - foo Foo FOO
foo\C - - foo
Technical detail: *<A NAME="NL-used-for-Nul"></A><B>NL-used-for-Nul</B>*
<A HREF="intro.html#<Nul>"><Nul></A> characters in the file are stored <A HREF="motion.html#as">as</A> <A HREF="motion.html#<NL>"><NL></A> in memory. In the display
they are shown <A HREF="motion.html#as">as</A> "^@". The translation is done when reading and <A HREF="editing.html#writing">writing</A>
files. To match a <A HREF="intro.html#<Nul>"><Nul></A> with a search <A HREF="#pattern">pattern</A> you can just enter CTRL-@ or
"<A HREF="visual.html#CTRL-V">CTRL-V</A> 000". This is probably just what you expect. Internally the
character is replaced with a <A HREF="motion.html#<NL>"><NL></A> in the search <A HREF="#pattern">pattern</A>. What is unusual is
that typing <A HREF="visual.html#CTRL-V">CTRL-V</A> <A HREF="motion.html#CTRL-J">CTRL-J</A> also inserts a <A HREF="motion.html#<NL>"><NL></A>, thus also searches for a <A HREF="intro.html#<Nul>"><Nul></A>
in the file. {Vi cannot handle <A HREF="intro.html#<Nul>"><Nul></A> characters in the file at all}
*<A NAME="CR-used-for-NL"></A><B>CR-used-for-NL</B>*
When <A HREF="options.html#'fileformat'">'fileformat'</A> is "<A HREF="os_mac.html#mac">mac</A>", <A HREF="motion.html#<NL>"><NL></A> characters in the file are stored <A HREF="motion.html#as">as</A> <A HREF="motion.html#<CR>"><CR></A>
characters internally. In the text they are shown <A HREF="motion.html#as">as</A> "^J". Otherwise this
works similar to the usage of <A HREF="motion.html#<NL>"><NL></A> for a <A HREF="intro.html#<Nul>"><Nul></A>.
When working with <A HREF="eval.html#expression">expression</A> evaluation, a <A HREF="motion.html#<NL>"><NL></A> character in the <A HREF="#pattern">pattern</A>
matches a <A HREF="motion.html#<NL>"><NL></A> in the <A HREF="eval.html#string">string</A>. The use of "\n" (backslash <A HREF="#n">n</A>) to match a <A HREF="motion.html#<NL>"><NL></A>
doesn't work there, <A HREF="motion.html#it">it</A> only works to match text in the buffer.
*<A NAME="pattern-multi-byte"></A><B>pattern-multi-byte</B>*
Patterns will also work with <A HREF="mbyte.html#multi-byte">multi-byte</A> characters, mostly <A HREF="motion.html#as">as</A> you would
expect. But invalid bytes may cause trouble, a <A HREF="#pattern">pattern</A> with an invalid byte
will probably never match.
==============================================================================
8. Composing characters *<A NAME="patterns-composing"></A><B>patterns-composing</B>*
*<A NAME="/\Z"></A><B>/\Z</B>*
When "\Z" appears anywhere in the <A HREF="#pattern">pattern</A>, all composing characters are
ignored. Thus only the base characters need to match, the composing
characters may be different and the number of composing characters may differ.
Only relevant when <A HREF="options.html#'encoding'">'encoding'</A> is "<A HREF="mbyte.html#utf-8">utf-8</A>".
Exception: If the <A HREF="#pattern">pattern</A> starts with one or more composing characters, these
must match.
*<A NAME="/\%C"></A><B>/\%C</B>*
Use "\%C" to skip any composing characters. For example, the <A HREF="#pattern">pattern</A> "<A HREF="insert.html#a">a</A>" does
not match in "càt" (where the a has the composing character 0x0300), but
"a\%C" does. Note that this does not match "cát" (where the á is character
0xe1, <A HREF="motion.html#it">it</A> does not have a compositing character). It does match "cat" (where
the a is just an <A HREF="motion.html#a)">a)</A>.
When a composing character appears at the start of the <A HREF="#pattern">pattern</A> of after an
item that doesn't include the composing character, a match is found at any
character that includes this composing character.
When using a dot and a composing character, this works the same <A HREF="motion.html#as">as</A> the
composing character by itself, except that <A HREF="motion.html#it">it</A> doesn't matter what comes before
this.
The order of composing characters does not matter. Also, the text may have
more composing characters than the <A HREF="#pattern">pattern</A>, <A HREF="motion.html#it">it</A> still matches. But all
composing characters in the <A HREF="#pattern">pattern</A> must be found in the text.
Suppose <A HREF="motion.html#B">B</A> is a base character and <A HREF="change.html#x">x</A> and <A HREF="change.html#y">y</A> are composing characters:
<B><FONT COLOR="PURPLE"> pattern text match </FONT></B>
Bxy Bxy yes (perfect match)
Bxy Byx yes (order ignored)
Bxy By no (x missing)
Bxy Bx no (y missing)
Bx Bx yes (perfect match)
Bx By no (x missing)
Bx Bxy yes (extra <A HREF="change.html#y">y</A> ignored)
Bx Byx yes (extra <A HREF="change.html#y">y</A> ignored)
==============================================================================
9. Compare with <A HREF="if_perl.html#Perl">Perl</A> patterns *<A NAME="perl-patterns"></A><B>perl-patterns</B>*
Vim's regexes are most similar to Perl's, in terms of what you can <A HREF="diff.html#do">do</A>. The
difference between them is mostly just <A HREF="intro.html#notation">notation</A>; here's a summary of where
they differ:
<B><FONT COLOR="PURPLE">Capability in Vimspeak in Perlspeak </FONT></B>
force <A HREF="change.html#case">case</A> insensitivity \c (?i)
force <A HREF="change.html#case">case</A> sensitivity \C (?-i)
backref-less grouping \%(atom\) (?:atom)
conservative quantifiers \{-n,m} *?, +?, ??, <A HREF="intro.html#{}">{}</A>?
0-width match atom\@= (?=atom)
0-width non-match atom\@! (?!atom)
0-width preceding match atom\@<= (?<=atom)
0-width preceding non-match atom\@<! (?<!atom)
match without retry atom\@> (?>atom)
Vim and <A HREF="if_perl.html#Perl">Perl</A> handle newline characters inside a <A HREF="eval.html#string">string</A> a bit differently:
In <A HREF="if_perl.html#Perl">Perl</A>, ^ and $ only match at the very beginning and end of the text,
by default, but you can set the '<A HREF="motion.html#m">m</A>' flag, which lets them match at
embedded newlines <A HREF="motion.html#as">as</A> well. You can also set the '<A HREF="change.html#s">s</A>' flag, which causes
a . to match newlines <A HREF="motion.html#as">as</A> well. (Both these flags can be changed inside
a <A HREF="#pattern">pattern</A> using the same <A HREF="syntax.html#syntax">syntax</A> used for the <A HREF="insert.html#i">i</A> flag above, BTW.)
On the other hand, Vim's ^ and $ always match at embedded newlines, and
you get two separate atoms, \%^ and \%$, which only match at the very
start and end of the text, respectively. Vim solves the second problem
by giving you the \_ "modifier": put <A HREF="motion.html#it">it</A> in front of a . or a character
class, and they will match newlines <A HREF="motion.html#as">as</A> well.
Finally, these constructs are unique to <A HREF="if_perl.html#Perl">Perl</A>:
- execution of arbitrary code in the regex: (?{perl code})
- conditional expressions: (?(condition)true-expr|false-expr)
...and these are unique to Vim:
- <A HREF="change.html#changing">changing</A> the magic-ness of a <A HREF="#pattern">pattern</A>: \v \V \m \M
(very useful for avoiding backslashitis)
- sequence of optionally matching atoms: \%[atoms]
- \& (which is to \| what "and" is to "or"; <A HREF="motion.html#it">it</A> forces several branches
to match at one spot)
- matching lines/columns by number: \%5l \%5c \%5v
- setting the start and end of the match: \zs \ze
==============================================================================
10. Highlighting matches *<A NAME="match-highlight"></A><B>match-highlight</B>*
*<A NAME=":mat"></A><B>:mat</B>* *<A NAME=":match"></A><B>:match</B>*
:mat[ch] {group} /{pattern}/
Define a <A HREF="#pattern">pattern</A> to highlight in the current <A HREF="windows.html#window">window</A>. It will
be highlighted with {group}. Example:
<B> :highlight MyGroup ctermbg=green guibg=green</B>
<B> :match MyGroup /TODO/</B>
Instead of <A HREF="version7.html#//">//</A> any character can be used to <A HREF="motion.html#mark">mark</A> the start and
end of the {pattern}. Watch out for using special characters,
such <A HREF="motion.html#as">as</A> '"'' and '|'.
{group} must exist at the moment this command is executed.
The {group} highlighting still applies when a character is
to be highlighted for <A HREF="options.html#'hlsearch'">'hlsearch'</A>, <A HREF="motion.html#as">as</A> the highlighting for
matches is given higher priority than that of <A HREF="options.html#'hlsearch'">'hlsearch'</A>.
<A HREF="autocmd.html#Syntax">Syntax</A> highlighting (see <A HREF="options.html#'syntax'">'syntax'</A>) is also overruled by
matches.
Note that highlighting the last used search <A HREF="#pattern">pattern</A> with
<A HREF="options.html#'hlsearch'">'hlsearch'</A> is used in all <A HREF="windows.html#windows">windows</A>, while the <A HREF="#pattern">pattern</A> defined
with "<A HREF="#:match">:match</A>" only exists in the current <A HREF="windows.html#window">window</A>. It is kept
when switching to another buffer.
<A HREF="options.html#'ignorecase'">'ignorecase'</A> does not apply, use |<A HREF="#/\c">/\c</A>| in the <A HREF="#pattern">pattern</A> to
ignore <A HREF="change.html#case">case</A>. Otherwise <A HREF="change.html#case">case</A> is not ignored.
<A HREF="options.html#'redrawtime'">'redrawtime'</A> defines the maximum time searched for <A HREF="#pattern">pattern</A>
matches.
When matching end-of-line and Vim redraws only part of the
display you may get unexpected results. That is because Vim
looks for a match in the line where redrawing starts.
Also see |<A HREF="eval.html#matcharg()">matcharg()</A>| and |<A HREF="eval.html#getmatches()">getmatches()</A>|. The former returns
the highlight group and <A HREF="#pattern">pattern</A> of a previous |<A HREF="#:match">:match</A>|
command. The latter returns a <A HREF="eval.html#list">list</A> with highlight groups and
patterns defined by both |<A HREF="eval.html#matchadd()">matchadd()</A>| and |<A HREF="#:match">:match</A>|.
Highlighting matches using |<A HREF="#:match">:match</A>| are limited to three
matches (aside from |<A HREF="#:match">:match</A>|, |<A HREF="#:2match">:2match</A>| and |<A HREF="#:3match">:3match</A>| are
available). |<A HREF="eval.html#matchadd()">matchadd()</A>| does not have this limitation and in
addition makes <A HREF="motion.html#it">it</A> possible to prioritize matches.
Another example, which highlights all characters in virtual
column 72 and more:
<B> :highlight rightMargin term=bold ctermfg=blue guifg=blue</B>
<B> :match rightMargin /.\%>72v/</B>
To highlight all character that are in virtual column 7:
<B> :highlight col8 ctermbg=grey guibg=grey</B>
<B> :match col8 /\%<8v.\%>7v/</B>
Note the use of two items to also match a character that
occupies more than one virtual column, such <A HREF="motion.html#as">as</A> a TAB.
:mat[ch]
:mat[ch] none
Clear a previously defined match <A HREF="#pattern">pattern</A>.
:2mat[ch] {group} /{pattern}/ *<A NAME=":2match"></A><B>:2match</B>*
:2mat[ch]
:2mat[ch] none
:3mat[ch] {group} /{pattern}/ *<A NAME=":3match"></A><B>:3match</B>*
:3mat[ch]
:3mat[ch] none
Just like |<A HREF="#:match">:match</A>| above, but set a separate match. Thus
there can be three matches active at the same time. The match
with the lowest number has priority if several match at the
same position.
The "<A HREF="#:3match">:3match</A>" command is used by the |<A HREF="pi_paren.html#matchparen">matchparen</A>| <A HREF="usr_05.html#plugin">plugin</A>. You
are suggested to use "<A HREF="#:match">:match</A>" for manual matching and
"<A HREF="#:2match">:2match</A>" for another <A HREF="usr_05.html#plugin">plugin</A>.
<A HREF="#top">top</A> - <A HREF="index.html">main help file</A>
</PRE>
</BODY>
</HTML>
|