3 " Maintainer: Vaidotas Zemlys <zemlys@gmail.com>
4 " Last Change: 2006 Apr 30
5 " Filenames: *.R *.Rout *.r *.Rhistory *.Rt *.Rout.save *.Rout.fail
6 " URL: http://uosis.mif.vu.lt/~zemlys/vim-syntax/r.vim
8 " First maintainer Tom Payne <tom@tompayne.org>
9 " Modified to make syntax less colourful and added the highlighting of
12 " For version 5.x: Clear all syntax items
13 " For version 6.x: Quit when a syntax file was already loaded
16 elseif exists("b:current_syntax")
21 setlocal iskeyword=@,48-57,_,.
23 set iskeyword=@,48-57,_,.
29 syn match rComment /\#.*/
32 " string enclosed in double quotes
33 syn region rString start=/"/ skip=/\\\\\|\\"/ end=/"/
34 " string enclosed in single quotes
35 syn region rString start=/'/ skip=/\\\\\|\\'/ end=/'/
36 " number with no fractional part or exponent
37 syn match rNumber /\d\+/
38 " floating point number with integer and fractional parts and optional exponent
39 syn match rFloat /\d\+\.\d*\([Ee][-+]\=\d\+\)\=/
40 " floating point number with no integer part and optional exponent
41 syn match rFloat /\.\d\+\([Ee][-+]\=\d\+\)\=/
42 " floating point number with no fractional part and optional exponent
43 syn match rFloat /\d\+[Ee][-+]\=\d\+/
46 " identifier with leading letter and optional following keyword characters
47 syn match rIdentifier /\a\k*/
48 " identifier with leading period, one or more digits, and at least one non-digit keyword character
49 syn match rIdentifier /\.\d*\K\k*/
52 syn keyword rStatement break next return
53 syn keyword rConditional if else
54 syn keyword rRepeat for in repeat while
57 syn keyword rConstant LETTERS letters month.ab month.name pi
58 syn keyword rConstant NULL
59 syn keyword rBoolean FALSE TRUE
60 syn keyword rNumber NA
61 syn match rArrow /<\{1,2}-/
64 syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame
67 syn match rDelimiter /[,;:]/
70 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError
71 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError
72 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError
73 syn match rError /[)\]}]/
74 syn match rBraceError /[)}]/ contained
75 syn match rCurlyError /[)\]]/ contained
76 syn match rParenError /[\]}]/ contained
78 " Define the default highlighting.
79 " For version 5.7 and earlier: only when not done already
80 " For version 5.8 and later: only when an item doesn't have highlighting yet
81 if version >= 508 || !exists("did_r_syn_inits")
83 let did_r_syn_inits = 1
84 command -nargs=+ HiLink hi link <args>
86 command -nargs=+ HiLink hi def link <args>
88 HiLink rComment Comment
89 HiLink rConstant Constant
92 HiLink rBoolean Boolean
94 HiLink rStatement Statement
95 HiLink rConditional Conditional
97 HiLink rIdentifier Normal
98 HiLink rArrow Statement
100 HiLink rDelimiter Delimiter
102 HiLink rBraceError Error
103 HiLink rCurlyError Error
104 HiLink rParenError Error
108 let b:current_syntax="r"