usr_44.txt (28933B)
1 *usr_44.txt* Nvim 2 3 4 VIM USER MANUAL by Bram Moolenaar 5 6 7 Your own syntax highlighted 8 9 10 Vim comes with highlighting for a couple of hundred different file types. If 11 the file you are editing isn't included, read this chapter to find out how to 12 get this type of file highlighted. Also see |:syn-define| in the reference 13 manual. 14 15 |44.1| Basic syntax commands 16 |44.2| Keywords 17 |44.3| Matches 18 |44.4| Regions 19 |44.5| Nested items 20 |44.6| Following groups 21 |44.7| Other arguments 22 |44.8| Clusters 23 |44.9| Including another syntax file 24 |44.10| Synchronizing 25 |44.11| Installing a syntax file 26 |44.12| Portable syntax file layout 27 28 Next chapter: |usr_45.txt| Select your language 29 Previous chapter: |usr_43.txt| Using filetypes 30 Table of contents: |usr_toc.txt| 31 32 ============================================================================== 33 *44.1* Basic syntax commands 34 35 Using an existing syntax file to start with will save you a lot of time. Try 36 finding a syntax file in $VIMRUNTIME/syntax for a language that is similar. 37 These files will also show you the normal layout of a syntax file. To 38 understand it, you need to read the following. 39 40 Let's start with the basic arguments. Before we start defining any new 41 syntax, we need to clear out any old definitions: > 42 43 :syntax clear 44 45 This isn't required in the final syntax file, but very useful when 46 experimenting. 47 48 There are more simplifications in this chapter. If you are writing a syntax 49 file to be used by others, read all the way through the end to find out the 50 details. 51 52 53 LISTING DEFINED ITEMS 54 55 To check which syntax items are currently defined, use this command: > 56 57 :syntax 58 59 You can use this to check which items have actually been defined. Quite 60 useful when you are experimenting with a new syntax file. It also shows the 61 colors used for each item, which helps to find out what is what. 62 To list the items in a specific syntax group use: > 63 64 :syntax list {group-name} 65 66 This also can be used to list clusters (explained in |44.8|). Just include 67 the @ in the name. 68 69 70 MATCHING CASE 71 72 Some languages are not case sensitive, such as Pascal. Others, such as C, are 73 case sensitive. You need to tell which type you have with the following 74 commands: > 75 :syntax case match 76 :syntax case ignore 77 78 The "match" argument means that Vim will match the case of syntax elements. 79 Therefore, "int" differs from "Int" and "INT". If the "ignore" argument is 80 used, the following are equivalent: "Procedure", "PROCEDURE" and "procedure". 81 The ":syntax case" commands can appear anywhere in a syntax file and affect 82 the syntax definitions that follow. In most cases, you have only one ":syntax 83 case" command in your syntax file; if you work with an unusual language that 84 contains both case-sensitive and non-case-sensitive elements, however, you can 85 scatter the ":syntax case" command throughout the file. 86 87 ============================================================================== 88 *44.2* Keywords 89 90 The most basic syntax elements are keywords. To define a keyword, use the 91 following form: > 92 93 :syntax keyword {group} {keyword} ... 94 95 The {group} is the name of a syntax group. With the ":highlight" command you 96 can assign colors to a {group}. The {keyword} argument is an actual keyword. 97 Here are a few examples: > 98 99 :syntax keyword xType int long char 100 :syntax keyword xStatement if then else endif 101 102 This example uses the group names "xType" and "xStatement". By convention, 103 each group name is prefixed by the filetype for the language being defined. 104 This example defines syntax for the x language (eXample language without an 105 interesting name). In a syntax file for "csh" scripts the name "cshType" 106 would be used. Thus the prefix is equal to the value of 'filetype'. 107 These commands cause the words "int", "long" and "char" to be highlighted 108 one way and the words "if", "then", "else" and "endif" to be highlighted 109 another way. Now you need to connect the x group names to standard Vim 110 names. You do this with the following commands: > 111 112 :highlight link xType Type 113 :highlight link xStatement Statement 114 115 This tells Vim to highlight "xType" like "Type" and "xStatement" like 116 "Statement". See |group-name| for the standard names. 117 118 119 UNUSUAL KEYWORDS 120 121 The characters used in a keyword must be in the 'iskeyword' option. If you 122 use another character, the word will never match. Vim doesn't give a warning 123 message for this. 124 The x language uses the '-' character in keywords. This is how it's done: 125 > 126 :setlocal iskeyword+=- 127 :syntax keyword xStatement when-not 128 129 The ":setlocal" command is used to change 'iskeyword' only for the current 130 buffer. Still it does change the behavior of commands like "w" and "*". If 131 that is not wanted, don't define a keyword but use a match (explained in the 132 next section). 133 134 The x language allows for abbreviations. For example, "next" can be 135 abbreviated to "n", "ne" or "nex". You can define them by using this command: 136 > 137 :syntax keyword xStatement n[ext] 138 139 This doesn't match "nextone", keywords always match whole words only. 140 141 ============================================================================== 142 *44.3* Matches 143 144 Consider defining something a bit more complex. You want to match ordinary 145 identifiers. To do this, you define a match syntax item. This one matches 146 any word consisting of only lowercase letters: > 147 148 :syntax match xIdentifier /\<\l\+\>/ 149 < 150 Note: 151 Keywords overrule any other syntax item. Thus the keywords "if", 152 "then", etc., will be keywords, as defined with the ":syntax keyword" 153 commands above, even though they also match the pattern for 154 xIdentifier. 155 156 The part at the end is a pattern, like it's used for searching. The // is 157 used to surround the pattern (like how it's done in a ":substitute" command). 158 You can use any other character, like a plus or a quote. 159 160 Now define a match for a comment. In the x language it is anything from # to 161 the end of a line: > 162 163 :syntax match xComment /#.*/ 164 165 Since you can use any search pattern, you can highlight very complex things 166 with a match item. See |pattern| for help on search patterns. 167 168 ============================================================================== 169 *44.4* Regions 170 171 In the example x language, strings are enclosed in double quotation marks ("). 172 To highlight strings you define a region. You need a region start (double 173 quote) and a region end (double quote). The definition is as follows: > 174 175 :syntax region xString start=/"/ end=/"/ 176 177 The "start" and "end" directives define the patterns used to find the start 178 and end of the region. But what about strings that look like this? 179 180 "A string with a double quote (\") in it" ~ 181 182 This creates a problem: The double quotation marks in the middle of the string 183 will end the region. You need to tell Vim to skip over any escaped double 184 quotes in the string. Do this with the skip keyword: > 185 186 :syntax region xString start=/"/ skip=/\\"/ end=/"/ 187 188 The double backslash matches a single backslash, since the backslash is a 189 special character in search patterns. 190 191 When to use a region instead of a match? The main difference is that a match 192 item is a single pattern, which must match as a whole. A region starts as 193 soon as the "start" pattern matches. Whether the "end" pattern is found or 194 not doesn't matter. Thus when the item depends on the "end" pattern to match, 195 you cannot use a region. Otherwise, regions are often simpler to define. And 196 it is easier to use nested items, as is explained in the next section. 197 198 ============================================================================== 199 *44.5* Nested items 200 201 Take a look at this comment: 202 203 %Get input TODO: Skip white space ~ 204 205 You want to highlight TODO in big yellow letters, even though it is in a 206 comment that is highlighted blue. To let Vim know about this, you define the 207 following syntax groups: > 208 209 :syntax keyword xTodo TODO contained 210 :syntax match xComment /%.*/ contains=xTodo 211 212 In the first line, the "contained" argument tells Vim that this keyword can 213 exist only inside another syntax item. The next line has "contains=xTodo". 214 This indicates that the xTodo syntax element is inside it. The result is that 215 the comment line as a whole is matched with "xComment" and made blue. The 216 word TODO inside it is matched by xTodo and highlighted yellow (highlighting 217 for xTodo was setup for this). 218 219 220 RECURSIVE NESTING 221 222 The x language defines code blocks in curly braces. And a code block may 223 contain other code blocks. This can be defined this way: > 224 225 :syntax region xBlock start=/{/ end=/}/ contains=xBlock 226 227 Suppose you have this text: 228 229 while i < b { ~ 230 if a { ~ 231 b = c; ~ 232 } ~ 233 } ~ 234 235 First a xBlock starts at the { in the first line. In the second line another 236 { is found. Since we are inside a xBlock item, and it contains itself, a 237 nested xBlock item will start here. Thus the "b = c" line is inside the 238 second level xBlock region. Then a } is found in the next line, which matches 239 with the end pattern of the region. This ends the nested xBlock. Because the 240 } is included in the nested region, it is hidden from the first xBlock region. 241 Then at the last } the first xBlock region ends. 242 243 244 KEEPING THE END 245 246 Consider the following two syntax items: > 247 248 :syntax region xComment start=/%/ end=/$/ contained 249 :syntax region xPreProc start=/#/ end=/$/ contains=xComment 250 251 You define a comment as anything from % to the end of the line. A 252 preprocessor directive is anything from # to the end of the line. Because you 253 can have a comment on a preprocessor line, the preprocessor definition 254 includes a "contains=xComment" argument. Now look what happens with this 255 text: 256 257 #define X = Y % Comment text ~ 258 int foo = 1; ~ 259 260 What you see is that the second line is also highlighted as xPreProc. The 261 preprocessor directive should end at the end of the line. That is why 262 you have used "end=/$/". So what is going wrong? 263 The problem is the contained comment. The comment starts with % and ends 264 at the end of the line. After the comment ends, the preprocessor syntax 265 continues. This is after the end of the line has been seen, so the next 266 line is included as well. 267 To avoid this problem and to avoid a contained syntax item eating a needed 268 end of line, use the "keepend" argument. This takes care of 269 the double end-of-line matching: > 270 271 :syntax region xComment start=/%/ end=/$/ contained 272 :syntax region xPreProc start=/#/ end=/$/ contains=xComment keepend 273 274 275 CONTAINING MANY ITEMS 276 277 You can use the contains argument to specify that everything can be contained. 278 For example: > 279 280 :syntax region xList start=/\[/ end=/\]/ contains=ALL 281 282 All syntax items will be contained in this one. It also contains itself, but 283 not at the same position (that would cause an endless loop). 284 You can specify that some groups are not contained. Thus contain all 285 groups but the ones that are listed: 286 > 287 :syntax region xList start=/\[/ end=/\]/ contains=ALLBUT,xString 288 289 With the "TOP" item you can include all items that don't have a "contained" 290 argument. "CONTAINED" is used to only include items with a "contained" 291 argument. See |:syn-contains| for the details. 292 293 ============================================================================== 294 *44.6* Following groups 295 296 The x language has statements in this form: 297 298 if (condition) then ~ 299 300 You want to highlight the three items differently. But "(condition)" and 301 "then" might also appear in other places, where they get different 302 highlighting. This is how you can do this: > 303 304 :syntax match xIf /if/ nextgroup=xIfCondition skipwhite 305 :syntax match xIfCondition /([^)]*)/ contained nextgroup=xThen skipwhite 306 :syntax match xThen /then/ contained 307 308 The "nextgroup" argument specifies which item can come next. This is not 309 required. If none of the items that are specified are found, nothing happens. 310 For example, in this text: 311 312 if not (condition) then ~ 313 314 The "if" is matched by xIf. "not" doesn't match the specified nextgroup 315 xIfCondition, thus only the "if" is highlighted. 316 317 The "skipwhite" argument tells Vim that white space (spaces and tabs) may 318 appear in between the items. Similar arguments are "skipnl", which allows a 319 line break in between the items, and "skipempty", which allows empty lines. 320 Notice that "skipnl" doesn't skip an empty line, something must match after 321 the line break. 322 323 ============================================================================== 324 *44.7* Other arguments 325 326 MATCHGROUP 327 328 When you define a region, the entire region is highlighted according to the 329 group name specified. To highlight the text enclosed in parentheses () with 330 the group xInside, for example, use the following command: > 331 332 :syntax region xInside start=/(/ end=/)/ 333 334 Suppose, that you want to highlight the parentheses differently. You can do 335 this with a lot of convoluted region statements, or you can use the 336 "matchgroup" argument. This tells Vim to highlight the start and end of a 337 region with a different highlight group (in this case, the xParen group): > 338 339 :syntax region xInside matchgroup=xParen start=/(/ end=/)/ 340 341 The "matchgroup" argument applies to the start or end match that comes after 342 it. In the previous example both start and end are highlighted with xParen. 343 To highlight the end with xParenEnd: > 344 345 :syntax region xInside matchgroup=xParen start=/(/ 346 \ matchgroup=xParenEnd end=/)/ 347 348 A side effect of using "matchgroup" is that contained items will not match in 349 the start or end of the region. The example for "transparent" uses this. 350 351 352 TRANSPARENT 353 354 In a C language file you would like to highlight the () text after a "while" 355 differently from the () text after a "for". In both of these there can be 356 nested () items, which should be highlighted in the same way. You must make 357 sure the () highlighting stops at the matching ). This is one way to do this: 358 > 359 :syntax region cWhile matchgroup=cWhile start=/while\s*(/ end=/)/ 360 \ contains=cCondNest 361 :syntax region cFor matchgroup=cFor start=/for\s*(/ end=/)/ 362 \ contains=cCondNest 363 :syntax region cCondNest start=/(/ end=/)/ contained transparent 364 365 Now you can give cWhile and cFor different highlighting. The cCondNest item 366 can appear in either of them, but take over the highlighting of the item it is 367 contained in. The "transparent" argument causes this. 368 Notice that the "matchgroup" argument has the same group as the item 369 itself. Why define it then? Well, the side effect of using a matchgroup is 370 that contained items are not found in the match with the start item then. 371 This avoids that the cCondNest group matches the ( just after the "while" or 372 "for". If this would happen, it would span the whole text until the matching 373 ) and the region would continue after it. Now cCondNest only matches after 374 the match with the start pattern, thus after the first (. 375 376 377 OFFSETS 378 379 Suppose you want to define a region for the text between ( and ) after an 380 "if". But you don't want to include the "if" or the ( and ). You can do this 381 by specifying offsets for the patterns. Example: > 382 383 :syntax region xCond start=/if\s*(/ms=e+1 end=/)/me=s-1 384 385 The offset for the start pattern is "ms=e+1". "ms" stands for Match Start. 386 This defines an offset for the start of the match. Normally the match starts 387 where the pattern matches. "e+1" means that the match now starts at the end 388 of the pattern match, and then one character further. 389 The offset for the end pattern is "me=s-1". "me" stands for Match End. 390 "s-1" means the start of the pattern match and then one character back. The 391 result is that in this text: 392 393 if (foo == bar) ~ 394 395 Only the text "foo == bar" will be highlighted as xCond. 396 397 More about offsets here: |:syn-pattern-offset|. 398 399 400 ONELINE 401 402 The "oneline" argument indicates that the region does not cross a line 403 boundary. For example: > 404 405 :syntax region xIfThen start=/if/ end=/then/ oneline 406 407 This defines a region that starts at "if" and ends at "then". But if there is 408 no "then" after the "if", the region doesn't match. 409 410 Note: 411 When using "oneline" the region doesn't start if the end pattern 412 doesn't match in the same line. Without "oneline" Vim does _not_ 413 check if there is a match for the end pattern. The region starts even 414 when the end pattern doesn't match in the rest of the file. 415 416 417 CONTINUATION LINES AND AVOIDING THEM 418 419 Things now become a little more complex. Let's define a preprocessor line. 420 This starts with a # in the first column and continues until the end of the 421 line. A line that ends with \ makes the next line a continuation line. The 422 way you handle this is to allow the syntax item to contain a continuation 423 pattern: > 424 425 :syntax region xPreProc start=/^#/ end=/$/ contains=xLineContinue 426 :syntax match xLineContinue "\\$" contained 427 428 In this case, although xPreProc normally matches a single line, the group 429 contained in it (namely xLineContinue) lets it go on for more than one line. 430 For example, it would match both of these lines: 431 432 #define SPAM spam spam spam \ ~ 433 bacon and spam ~ 434 435 In this case, this is what you want. If it is not what you want, you can call 436 for the region to be on a single line by adding "excludenl" to the contained 437 pattern. For example, you want to highlight "end" in xPreProc, but only at 438 the end of the line. To avoid making the xPreProc continue on the next line, 439 like xLineContinue does, use "excludenl" like this: > 440 441 :syntax region xPreProc start=/^#/ end=/$/ 442 \ contains=xLineContinue,xPreProcEnd 443 :syntax match xPreProcEnd excludenl /end$/ contained 444 :syntax match xLineContinue "\\$" contained 445 446 "excludenl" must be placed before the pattern. Since "xLineContinue" doesn't 447 have "excludenl", a match with it will extend xPreProc to the next line as 448 before. 449 450 ============================================================================== 451 *44.8* Clusters 452 453 One of the things you will notice as you start to write a syntax file is that 454 you wind up generating a lot of syntax groups. Vim enables you to define a 455 collection of syntax groups called a cluster. 456 Suppose you have a language that contains for loops, if statements, while 457 loops, and functions. Each of them contains the same syntax elements: numbers 458 and identifiers. You define them like this: > 459 460 :syntax match xFor /^for.*/ contains=xNumber,xIdent 461 :syntax match xIf /^if.*/ contains=xNumber,xIdent 462 :syntax match xWhile /^while.*/ contains=xNumber,xIdent 463 464 You have to repeat the same "contains=" every time. If you want to add 465 another contained item, you have to add it three times. Syntax clusters 466 simplify these definitions by enabling you to have one cluster stand for 467 several syntax groups. 468 To define a cluster for the two items that the three groups contain, use 469 the following command: > 470 471 :syntax cluster xState contains=xNumber,xIdent 472 473 Clusters are used inside other syntax items just like any syntax group. 474 Their names start with @. Thus, you can define the three groups like this: > 475 476 :syntax match xFor /^for.*/ contains=@xState 477 :syntax match xIf /^if.*/ contains=@xState 478 :syntax match xWhile /^while.*/ contains=@xState 479 480 You can add new group names to this cluster with the "add" argument: > 481 482 :syntax cluster xState add=xString 483 484 You can remove syntax groups from this list as well: > 485 486 :syntax cluster xState remove=xNumber 487 488 ============================================================================== 489 *44.9* Including another syntax file 490 491 The C++ language syntax is a superset of the C language. Because you do not 492 want to write two syntax files, you can have the C++ syntax file read in the 493 one for C by using the following command: > 494 495 :runtime! syntax/c.vim 496 497 The ":runtime!" command searches 'runtimepath' for all "syntax/c.vim" files. 498 This makes the C parts of the C++ syntax be defined like for C files. If you 499 have replaced the c.vim syntax file, or added items with an extra file, these 500 will be loaded as well. 501 After loading the C syntax items the specific C++ items can be defined. 502 For example, add keywords that are not used in C: > 503 504 :syntax keyword cppStatement new delete this friend using 505 506 This works just like in any other syntax file. 507 508 Now consider the Perl language. A Perl script consists of two distinct parts: 509 a documentation section in POD format, and a program written in Perl itself. 510 The POD section starts with "=head" and ends with "=cut". 511 You want to define the POD syntax in one file, and use it from the Perl 512 syntax file. The ":syntax include" command reads in a syntax file and stores 513 the elements it defined in a syntax cluster. For Perl, the statements are as 514 follows: > 515 516 :syntax include @Pod <script>:p:h/pod.vim 517 :syntax region perlPOD start=/^=head/ end=/^=cut/ contains=@Pod 518 519 When "=head" is found in a Perl file, the perlPOD region starts. In this 520 region the @Pod cluster is contained. All the items defined as top-level 521 items in the pod.vim syntax files will match here. When "=cut" is found, the 522 region ends and we go back to the items defined in the Perl file. 523 The ":syntax include" command is clever enough to ignore a ":syntax clear" 524 command in the included file. And an argument such as "contains=ALL" will 525 only contain items defined in the included file, not in the file that includes 526 it. 527 The "<script>:p:h/" part uses the name of the current file (<script>), 528 expands it to a full path (:p) and then takes the head (:h). This results in 529 the directory name of the file. This causes the pod.vim file in the same 530 directory to be included. 531 532 ============================================================================== 533 *44.10* Synchronizing 534 535 Compilers have it easy. They start at the beginning of a file and parse it 536 straight through. Vim does not have it so easy. It must start in the middle, 537 where the editing is being done. So how does it tell where it is? 538 The secret is the ":syntax sync" command. This tells Vim how to figure out 539 where it is. For example, the following command tells Vim to scan backward 540 for the beginning or end of a C-style comment and begin syntax coloring from 541 there: > 542 543 :syntax sync ccomment 544 545 You can tune this processing with some arguments. The "minlines" argument 546 tells Vim the minimum number of lines to look backward, and "maxlines" tells 547 the editor the maximum number of lines to scan. 548 For example, the following command tells Vim to look at least 10 lines 549 before the top of the screen: > 550 551 :syntax sync ccomment minlines=10 maxlines=500 552 553 If it cannot figure out where it is in that space, it starts looking farther 554 and farther back until it figures out what to do. But it looks no farther 555 back than 500 lines. (A large "maxlines" slows down processing. A small one 556 might cause synchronization to fail.) 557 To make synchronizing go a bit faster, tell Vim which syntax items can be 558 skipped. Every match and region that only needs to be used when actually 559 displaying text can be given the "display" argument. 560 By default, the comment to be found will be colored as part of the Comment 561 syntax group. If you want to color things another way, you can specify a 562 different syntax group: > 563 564 :syntax sync ccomment xAltComment 565 566 If your programming language does not have C-style comments in it, you can try 567 another method of synchronization. The simplest way is to tell Vim to space 568 back a number of lines and try to figure out things from there. The following 569 command tells Vim to go back 150 lines and start parsing from there: > 570 571 :syntax sync minlines=150 572 573 A large "minlines" value can make Vim slower, especially when scrolling 574 backwards in the file. 575 Finally, you can specify a syntax group to look for by using this command: 576 > 577 :syntax sync match {sync-group-name} 578 \ grouphere {group-name} {pattern} 579 580 This tells Vim that when it sees {pattern} the syntax group named {group-name} 581 begins just after the pattern given. The {sync-group-name} is used to give a 582 name to this synchronization specification. For example, the sh scripting 583 language begins an if statement with "if" and ends it with "fi": 584 585 if [ --f file.txt ] ; then ~ 586 echo "File exists" ~ 587 fi ~ 588 589 To define a "grouphere" directive for this syntax, you use the following 590 command: > 591 592 :syntax sync match shIfSync grouphere shIf "\<if\>" 593 594 The "groupthere" argument tells Vim that the pattern ends a group. For 595 example, the end of the if/fi group is as follows: > 596 597 :syntax sync match shIfSync groupthere NONE "\<fi\>" 598 599 In this example, the NONE tells Vim that you are not in any special syntax 600 region. In particular, you are not inside an if block. 601 602 You also can define matches and regions that are with no "grouphere" or 603 "groupthere" arguments. These groups are for syntax groups skipped during 604 synchronization. For example, the following skips over anything inside {}, 605 even if it would normally match another synchronization method: > 606 607 :syntax sync match xSpecial /{.*}/ 608 609 More about synchronizing in the reference manual: |:syn-sync|. 610 611 ============================================================================== 612 *44.11* Installing a syntax file 613 614 When your new syntax file is ready to be used, drop it in a "syntax" directory 615 in 'runtimepath'. For Unix that would be "~/.config/nvim/syntax". 616 The name of the syntax file must be equal to the file type, with ".vim" 617 added. Thus for the x language, the full path of the file would be: 618 619 ~/.config/nvim/syntax/x.vim ~ 620 621 You must also make the file type be recognized. See |43.2|. 622 623 If your file works well, you might want to make it available to other Vim 624 users. First read the next section to make sure your file works well for 625 others. Then e-mail it to the Vim maintainer: <maintainer@vim.org>. Also 626 explain how the filetype can be detected. With a bit of luck your file will 627 be included in the next Vim version! 628 629 630 ADDING TO AN EXISTING SYNTAX FILE 631 632 We were assuming you were adding a completely new syntax file. When an 633 existing syntax file works, but is missing some items, you can add items in a 634 separate file. That avoids changing the distributed syntax file, which will 635 be lost when installing a new version of Vim. 636 Write syntax commands in your file, possibly using group names from the 637 existing syntax. For example, to add new variable types to the C syntax file: 638 > 639 :syntax keyword cType off_t uint 640 641 Write the file with the same name as the original syntax file. In this case 642 "c.vim". Place it in a directory near the end of 'runtimepath'. This makes 643 it loaded after the original syntax file. For Unix this would be: 644 645 ~/.config/nvim/after/syntax/c.vim ~ 646 647 ============================================================================== 648 *44.12* Portable syntax file layout 649 650 Wouldn't it be nice if all Vim users exchange syntax files? To make this 651 possible, the syntax file must follow a few guidelines. 652 653 Start with a header that explains what the syntax file is for, who maintains 654 it and when it was last updated. Don't include too much information about 655 changes history, not many people will read it. Example: > 656 657 " Vim syntax file 658 " Language: C 659 " Maintainer: Bram Moolenaar <Bram@vim.org> 660 " Last Change: 2001 Jun 18 661 " Remark: Included by the C++ syntax. 662 663 Use the same layout as the other syntax files. Using an existing syntax file 664 as an example will save you a lot of time. 665 666 Choose a good, descriptive name for your syntax file. Use lowercase letters 667 and digits. Don't make it too long, it is used in many places: The name of 668 the syntax file "name.vim", 'filetype', b:current_syntax and the start of each 669 syntax group (nameType, nameStatement, nameString, etc). 670 671 Start with a check for "b:current_syntax". If it is defined, some other 672 syntax file, earlier in 'runtimepath' was already loaded: > 673 674 if exists("b:current_syntax") 675 finish 676 endif 677 678 Set "b:current_syntax" to the name of the syntax at the end. Don't forget 679 that included files do this too, you might have to reset "b:current_syntax" if 680 you include two files. 681 682 Do not include anything that is a user preference. Don't set 'tabstop', 683 'expandtab', etc. These belong in a filetype plugin. 684 685 Do not include mappings or abbreviations. Only include setting 'iskeyword' if 686 it is really necessary for recognizing keywords. 687 688 To allow users select their own preferred colors, make a different group name 689 for every kind of highlighted item. Then link each of them to one of the 690 standard highlight groups. That will make it work with every color scheme. 691 If you select specific colors it will look bad with some color schemes. And 692 don't forget that some people use a different background color, or have only 693 eight colors available. 694 695 For the linking use "hi def link", so that the user can select different 696 highlighting before your syntax file is loaded. Example: > 697 698 hi def link nameString String 699 hi def link nameNumber Number 700 hi def link nameCommand Statement 701 ... etc ... 702 703 Add the "display" argument to items that are not used when syncing, to speed 704 up scrolling backwards and CTRL-L. 705 706 ============================================================================== 707 708 Next chapter: |usr_45.txt| Select your language 709 710 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: