blob: cf4bba84f6acfb8d857c941e0e3e84b4f920d8bd [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: BibTeX (bibliographic database format for (La)TeX)
3" Maintainer: Bernd Feige <Bernd.Feige@gmx.net>
4" Filenames: *.bib
Bram Moolenaar251e1912011-06-19 05:09:16 +02005" Last Change: Mar 23, 2011
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7" Thanks to those who pointed out problems with this file or supplied fixes!
8
9" Initialization
10" ==============
11" For version 5.x: Clear all syntax items
12" For version 6.x: Quit when a syntax file was already loaded
13if version < 600
14 syntax clear
15elseif exists("b:current_syntax")
16 finish
17endif
18
19" Ignore case
20syn case ignore
21
22" Keywords
23" ========
24syn keyword bibType contained article book booklet conference inbook
25syn keyword bibType contained incollection inproceedings manual
26syn keyword bibType contained mastersthesis misc phdthesis
27syn keyword bibType contained proceedings techreport unpublished
28syn keyword bibType contained string
29
30syn keyword bibEntryKw contained address annote author booktitle chapter
31syn keyword bibEntryKw contained crossref edition editor howpublished
32syn keyword bibEntryKw contained institution journal key month note
33syn keyword bibEntryKw contained number organization pages publisher
34syn keyword bibEntryKw contained school series title type volume year
35" Non-standard:
36syn keyword bibNSEntryKw contained abstract isbn issn keywords url
Bram Moolenaar251e1912011-06-19 05:09:16 +020037" AMS mref http://www.ams.org/mref
38syn keyword bibNSEntryKw contained mrclass mrnumber mrreviewer fjournal coden
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
40" Clusters
41" ========
42syn cluster bibVarContents contains=bibUnescapedSpecial,bibBrace,bibParen
43" This cluster is empty but things can be added externally:
44"syn cluster bibCommentContents
45
46" Matches
47" =======
48syn match bibUnescapedSpecial contained /[^\\][%&]/hs=s+1
49syn match bibKey contained /\s*[^ \t}="]\+,/hs=s,he=e-1 nextgroup=bibField
50syn match bibVariable contained /[^{}," \t=]/
Bram Moolenaar8aff23a2005-08-19 20:40:30 +000051syn region bibComment start=/./ end=/^\s*@/me=e-1 contains=@bibCommentContents nextgroup=bibEntry
Bram Moolenaar071d4272004-06-13 20:20:40 +000052syn region bibQuote contained start=/"/ end=/"/ skip=/\(\\"\)/ contains=@bibVarContents
53syn region bibBrace contained start=/{/ end=/}/ skip=/\(\\[{}]\)/ contains=@bibVarContents
54syn region bibParen contained start=/(/ end=/)/ skip=/\(\\[()]\)/ contains=@bibVarContents
55syn region bibField contained start="\S\+\s*=\s*" end=/[}),]/me=e-1 contains=bibEntryKw,bibNSEntryKw,bibBrace,bibParen,bibQuote,bibVariable
56syn region bibEntryData contained start=/[{(]/ms=e+1 end=/[})]/me=e-1 contains=bibKey,bibField
57" Actually, 5.8 <= Vim < 6.0 would ignore the `fold' keyword anyway, but Vim<5.8 would produce
58" an error, so we explicitly distinguish versions with and without folding functionality:
59if version < 600
Bram Moolenaar251e1912011-06-19 05:09:16 +020060 syn region bibEntry start=/@\S\+\s*[{(]/ end=/^\s*[})]/ transparent contains=bibType,bibEntryData nextgroup=bibComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000061else
Bram Moolenaar251e1912011-06-19 05:09:16 +020062 syn region bibEntry start=/@\S\+\s*[{(]/ end=/^\s*[})]/ transparent fold contains=bibType,bibEntryData nextgroup=bibComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000063endif
Bram Moolenaar251e1912011-06-19 05:09:16 +020064syn region bibComment2 start=/@Comment\s*[{(]/ end=/^\s*[})]/me=e-1 contains=@bibCommentContents nextgroup=bibEntry
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
66" Synchronization
67" ===============
68syn sync match All grouphere bibEntry /^\s*@/
69syn sync maxlines=200
70syn sync minlines=50
71
72" Highlighting defaults
73" =====================
74" Define the default highlighting.
75" For version 5.7 and earlier: only when not done already
76" For version 5.8 and later: only when an item doesn't have highlighting yet
77if version >= 508 || !exists("did_bib_syn_inits")
78 if version < 508
79 let did_bib_syn_inits = 1
80 command -nargs=+ HiLink hi link <args>
81 else
82 command -nargs=+ HiLink hi def link <args>
83 endif
84 HiLink bibType Identifier
85 HiLink bibEntryKw Statement
86 HiLink bibNSEntryKw PreProc
87 HiLink bibKey Special
88 HiLink bibVariable Constant
89 HiLink bibUnescapedSpecial Error
90 HiLink bibComment Comment
Bram Moolenaar8aff23a2005-08-19 20:40:30 +000091 HiLink bibComment2 Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 delcommand HiLink
93endif
94
95let b:current_syntax = "bib"