blob: f84d5ca95a5d834b9e0d6f1efbbcede8bcec450f [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 Moolenaar76f3b1a2014-03-27 22:30:07 +01005" Last Change: 2014 Mar 26
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
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010019let s:cpo_save = &cpo
20set cpo&vim
21
Bram Moolenaar071d4272004-06-13 20:20:40 +000022" Ignore case
23syn case ignore
24
25" Keywords
26" ========
27syn keyword bibType contained article book booklet conference inbook
28syn keyword bibType contained incollection inproceedings manual
29syn keyword bibType contained mastersthesis misc phdthesis
30syn keyword bibType contained proceedings techreport unpublished
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +010031syn keyword bibType contained string preamble
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33syn keyword bibEntryKw contained address annote author booktitle chapter
34syn keyword bibEntryKw contained crossref edition editor howpublished
35syn keyword bibEntryKw contained institution journal key month note
36syn keyword bibEntryKw contained number organization pages publisher
37syn keyword bibEntryKw contained school series title type volume year
38" Non-standard:
39syn keyword bibNSEntryKw contained abstract isbn issn keywords url
Bram Moolenaar251e1912011-06-19 05:09:16 +020040" AMS mref http://www.ams.org/mref
41syn keyword bibNSEntryKw contained mrclass mrnumber mrreviewer fjournal coden
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
43" Clusters
44" ========
45syn cluster bibVarContents contains=bibUnescapedSpecial,bibBrace,bibParen
46" This cluster is empty but things can be added externally:
47"syn cluster bibCommentContents
48
49" Matches
50" =======
51syn match bibUnescapedSpecial contained /[^\\][%&]/hs=s+1
52syn match bibKey contained /\s*[^ \t}="]\+,/hs=s,he=e-1 nextgroup=bibField
53syn match bibVariable contained /[^{}," \t=]/
Bram Moolenaar8aff23a2005-08-19 20:40:30 +000054syn region bibComment start=/./ end=/^\s*@/me=e-1 contains=@bibCommentContents nextgroup=bibEntry
Bram Moolenaar071d4272004-06-13 20:20:40 +000055syn region bibQuote contained start=/"/ end=/"/ skip=/\(\\"\)/ contains=@bibVarContents
56syn region bibBrace contained start=/{/ end=/}/ skip=/\(\\[{}]\)/ contains=@bibVarContents
57syn region bibParen contained start=/(/ end=/)/ skip=/\(\\[()]\)/ contains=@bibVarContents
58syn region bibField contained start="\S\+\s*=\s*" end=/[}),]/me=e-1 contains=bibEntryKw,bibNSEntryKw,bibBrace,bibParen,bibQuote,bibVariable
59syn region bibEntryData contained start=/[{(]/ms=e+1 end=/[})]/me=e-1 contains=bibKey,bibField
60" Actually, 5.8 <= Vim < 6.0 would ignore the `fold' keyword anyway, but Vim<5.8 would produce
61" an error, so we explicitly distinguish versions with and without folding functionality:
62if version < 600
Bram Moolenaar251e1912011-06-19 05:09:16 +020063 syn region bibEntry start=/@\S\+\s*[{(]/ end=/^\s*[})]/ transparent contains=bibType,bibEntryData nextgroup=bibComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000064else
Bram Moolenaar251e1912011-06-19 05:09:16 +020065 syn region bibEntry start=/@\S\+\s*[{(]/ end=/^\s*[})]/ transparent fold contains=bibType,bibEntryData nextgroup=bibComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000066endif
Bram Moolenaar251e1912011-06-19 05:09:16 +020067syn region bibComment2 start=/@Comment\s*[{(]/ end=/^\s*[})]/me=e-1 contains=@bibCommentContents nextgroup=bibEntry
Bram Moolenaar071d4272004-06-13 20:20:40 +000068
69" Synchronization
70" ===============
71syn sync match All grouphere bibEntry /^\s*@/
72syn sync maxlines=200
73syn sync minlines=50
74
75" Highlighting defaults
76" =====================
77" Define the default highlighting.
78" For version 5.7 and earlier: only when not done already
79" For version 5.8 and later: only when an item doesn't have highlighting yet
80if version >= 508 || !exists("did_bib_syn_inits")
81 if version < 508
82 let did_bib_syn_inits = 1
83 command -nargs=+ HiLink hi link <args>
84 else
85 command -nargs=+ HiLink hi def link <args>
86 endif
87 HiLink bibType Identifier
88 HiLink bibEntryKw Statement
89 HiLink bibNSEntryKw PreProc
90 HiLink bibKey Special
91 HiLink bibVariable Constant
92 HiLink bibUnescapedSpecial Error
93 HiLink bibComment Comment
Bram Moolenaar8aff23a2005-08-19 20:40:30 +000094 HiLink bibComment2 Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +000095 delcommand HiLink
96endif
97
98let b:current_syntax = "bib"
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010099
100let &cpo = s:cpo_save
101unlet s:cpo_save