1" Vim syntax file 2" Language: R (GNU S) 3" Maintainer: Vaidotas Zemlys <[email protected]> 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 7 8" First maintainer Tom Payne <[email protected]> 9" Modified to make syntax less colourful and added the highlighting of 10" R assignment arrow 11 12" For version 5.x: Clear all syntax items 13" For version 6.x: Quit when a syntax file was already loaded 14if version < 600 15 syntax clear 16elseif exists("b:current_syntax") 17 finish 18endif 19 20if version >= 600 21 setlocal iskeyword=@,48-57,_,. 22else 23 set iskeyword=@,48-57,_,. 24endif 25 26syn case match 27 28" Comment 29syn match rComment /\#.*/ 30 31" Constant 32" string enclosed in double quotes 33syn region rString start=/"/ skip=/\\\\\|\\"/ end=/"/ 34" string enclosed in single quotes 35syn region rString start=/'/ skip=/\\\\\|\\'/ end=/'/ 36" number with no fractional part or exponent 37syn match rNumber /\d\+/ 38" floating point number with integer and fractional parts and optional exponent 39syn match rFloat /\d\+\.\d*\([Ee][-+]\=\d\+\)\=/ 40" floating point number with no integer part and optional exponent 41syn match rFloat /\.\d\+\([Ee][-+]\=\d\+\)\=/ 42" floating point number with no fractional part and optional exponent 43syn match rFloat /\d\+[Ee][-+]\=\d\+/ 44 45" Identifier 46" identifier with leading letter and optional following keyword characters 47syn match rIdentifier /\a\k*/ 48" identifier with leading period, one or more digits, and at least one non-digit keyword character 49syn match rIdentifier /\.\d*\K\k*/ 50 51" Statement 52syn keyword rStatement break next return 53syn keyword rConditional if else 54syn keyword rRepeat for in repeat while 55 56" Constant 57syn keyword rConstant LETTERS letters month.ab month.name pi 58syn keyword rConstant NULL 59syn keyword rBoolean FALSE TRUE 60syn keyword rNumber NA 61syn match rArrow /<\{1,2}-/ 62 63" Type 64syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame 65 66" Special 67syn match rDelimiter /[,;:]/ 68 69" Error 70syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError 71syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError 72syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError 73syn match rError /[)\]}]/ 74syn match rBraceError /[)}]/ contained 75syn match rCurlyError /[)\]]/ contained 76syn match rParenError /[\]}]/ contained 77 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 81if version >= 508 || !exists("did_r_syn_inits") 82 if version < 508 83 let did_r_syn_inits = 1 84 command -nargs=+ HiLink hi link <args> 85 else 86 command -nargs=+ HiLink hi def link <args> 87 endif 88 HiLink rComment Comment 89 HiLink rConstant Constant 90 HiLink rString String 91 HiLink rNumber Number 92 HiLink rBoolean Boolean 93 HiLink rFloat Float 94 HiLink rStatement Statement 95 HiLink rConditional Conditional 96 HiLink rRepeat Repeat 97 HiLink rIdentifier Normal 98 HiLink rArrow Statement 99 HiLink rType Type 100 HiLink rDelimiter Delimiter 101 HiLink rError Error 102 HiLink rBraceError Error 103 HiLink rCurlyError Error 104 HiLink rParenError Error 105 delcommand HiLink 106endif 107 108let b:current_syntax="r" 109 110" vim: ts=8 sw=2 111 112