1" Vim syntax file 2" Language: R (GNU S) 3" Maintainer: Jakson Aquino <[email protected]> 4" Former Maintainers: Vaidotas Zemlys <[email protected]> 5" Tom Payne <[email protected]> 6" Last Change: Wed Jul 09, 2014 10:29PM 7" Filenames: *.R *.r *.Rhistory *.Rt 8" 9" NOTE: The highlighting of R functions is defined in the 10" r-plugin/functions.vim, which is part of vim-r-plugin2: 11" http://www.vim.org/scripts/script.php?script_id=2628 12" 13" CONFIGURATION: 14" syntax folding can be turned on by 15" 16" let r_syntax_folding = 1 17" 18" Some lines of code were borrowed from Zhuojun Chen. 19 20if exists("b:current_syntax") 21 finish 22endif 23 24setlocal iskeyword=@,48-57,_,. 25 26if exists("g:r_syntax_folding") 27 setlocal foldmethod=syntax 28endif 29 30syn case match 31 32" Comment 33syn match rCommentTodo contained "\(BUG\|FIXME\|NOTE\|TODO\):" 34syn match rComment contains=@Spell,rCommentTodo "#.*" 35 36" Roxygen 37syn match rOKeyword contained "@\(param\|return\|name\|rdname\|examples\|include\|docType\)" 38syn match rOKeyword contained "@\(S3method\|TODO\|aliases\|alias\|assignee\|author\|callGraphDepth\|callGraph\)" 39syn match rOKeyword contained "@\(callGraphPrimitives\|concept\|exportClass\|exportMethod\|exportPattern\|export\|formals\)" 40syn match rOKeyword contained "@\(format\|importClassesFrom\|importFrom\|importMethodsFrom\|import\|keywords\)" 41syn match rOKeyword contained "@\(method\|noRd\|note\|references\|seealso\|setClass\|slot\|source\|title\|usage\)" 42syn match rOKeyword contained "@\(family\|template\|templateVar\|description\|details\|inheritsParams\)" 43syn match rOComment contains=@Spell,rOKeyword "#'.*" 44 45 46if &filetype == "rhelp" 47 " string enclosed in double quotes 48 syn region rString contains=rSpecial,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/ 49 " string enclosed in single quotes 50 syn region rString contains=rSpecial,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/ 51else 52 " string enclosed in double quotes 53 syn region rString contains=rSpecial,rStrError,@Spell start=/"/ skip=/\\\\\|\\"/ end=/"/ 54 " string enclosed in single quotes 55 syn region rString contains=rSpecial,rStrError,@Spell start=/'/ skip=/\\\\\|\\'/ end=/'/ 56endif 57 58syn match rStrError display contained "\\." 59 60 61" New line, carriage return, tab, backspace, bell, feed, vertical tab, backslash 62syn match rSpecial display contained "\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\" 63 64" Hexadecimal and Octal digits 65syn match rSpecial display contained "\\\(x\x\{1,2}\|[0-8]\{1,3}\)" 66 67" Unicode characters 68syn match rSpecial display contained "\\u\x\{1,4}" 69syn match rSpecial display contained "\\U\x\{1,8}" 70syn match rSpecial display contained "\\u{\x\{1,4}}" 71syn match rSpecial display contained "\\U{\x\{1,8}}" 72 73" Statement 74syn keyword rStatement break next return 75syn keyword rConditional if else 76syn keyword rRepeat for in repeat while 77 78" Constant (not really) 79syn keyword rConstant T F LETTERS letters month.abb month.name pi 80syn keyword rConstant R.version.string 81 82syn keyword rNumber NA_integer_ NA_real_ NA_complex_ NA_character_ 83 84" Constants 85syn keyword rConstant NULL 86syn keyword rBoolean FALSE TRUE 87syn keyword rNumber NA Inf NaN 88 89" integer 90syn match rInteger "\<\d\+L" 91syn match rInteger "\<0x\([0-9]\|[a-f]\|[A-F]\)\+L" 92syn match rInteger "\<\d\+[Ee]+\=\d\+L" 93 94" number with no fractional part or exponent 95syn match rNumber "\<\d\+\>" 96" hexadecimal number 97syn match rNumber "\<0x\([0-9]\|[a-f]\|[A-F]\)\+" 98 99" floating point number with integer and fractional parts and optional exponent 100syn match rFloat "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=" 101" floating point number with no integer part and optional exponent 102syn match rFloat "\<\.\d\+\([Ee][-+]\=\d\+\)\=" 103" floating point number with no fractional part and optional exponent 104syn match rFloat "\<\d\+[Ee][-+]\=\d\+" 105 106" complex number 107syn match rComplex "\<\d\+i" 108syn match rComplex "\<\d\++\d\+i" 109syn match rComplex "\<0x\([0-9]\|[a-f]\|[A-F]\)\+i" 110syn match rComplex "\<\d\+\.\d*\([Ee][-+]\=\d\+\)\=i" 111syn match rComplex "\<\.\d\+\([Ee][-+]\=\d\+\)\=i" 112syn match rComplex "\<\d\+[Ee][-+]\=\d\+i" 113 114syn match rOperator "&" 115syn match rOperator '-' 116syn match rOperator '\*' 117syn match rOperator '+' 118syn match rOperator '=' 119if &filetype != "rmd" && &filetype != "rrst" 120 syn match rOperator "[|!<>^~/:]" 121else 122 syn match rOperator "[|!<>^~`/:]" 123endif 124syn match rOperator "%\{2}\|%\S\{-}%" 125syn match rOpError '\*\{3}' 126syn match rOpError '//' 127syn match rOpError '&&&' 128syn match rOpError '|||' 129syn match rOpError '<<' 130syn match rOpError '>>' 131 132syn match rArrow "<\{1,2}-" 133syn match rArrow "->\{1,2}" 134 135" Special 136syn match rDelimiter "[,;:]" 137 138" Error 139if exists("g:r_syntax_folding") 140 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError fold 141 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError fold 142 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError fold 143else 144 syn region rRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rError,rBraceError,rCurlyError 145 syn region rRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rError,rBraceError,rParenError 146 syn region rRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rError,rCurlyError,rParenError 147endif 148 149syn match rError "[)\]}]" 150syn match rBraceError "[)}]" contained 151syn match rCurlyError "[)\]]" contained 152syn match rParenError "[\]}]" contained 153 154" Source list of R functions. The list is produced by the Vim-R-plugin 155" http://www.vim.org/scripts/script.php?script_id=2628 156runtime r-plugin/functions.vim 157 158syn match rDollar display contained "\$" 159syn match rDollar display contained "@" 160 161" List elements will not be highlighted as functions: 162syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar 163syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar 164 165" Functions that may add new objects 166syn keyword rPreProc library require attach detach source 167 168if &filetype == "rhelp" 169 syn match rHelpIdent '\\method' 170 syn match rHelpIdent '\\S4method' 171endif 172 173" Type 174syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame 175 176" Name of object with spaces 177if &filetype != "rmd" && &filetype != "rrst" 178 syn region rNameWSpace start="`" end="`" 179endif 180 181if &filetype == "rhelp" 182 syn match rhPreProc "^#ifdef.*" 183 syn match rhPreProc "^#endif.*" 184 syn match rhSection "\\dontrun\>" 185endif 186 187" Define the default highlighting. 188hi def link rArrow Statement 189hi def link rBoolean Boolean 190hi def link rBraceError Error 191hi def link rComment Comment 192hi def link rCommentTodo Todo 193hi def link rOComment Comment 194hi def link rComplex Number 195hi def link rConditional Conditional 196hi def link rConstant Constant 197hi def link rCurlyError Error 198hi def link rDelimiter Delimiter 199hi def link rDollar SpecialChar 200hi def link rError Error 201hi def link rFloat Float 202hi def link rFunction Function 203hi def link rHelpIdent Identifier 204hi def link rhPreProc PreProc 205hi def link rhSection PreCondit 206hi def link rInteger Number 207hi def link rLstElmt Normal 208hi def link rNameWSpace Normal 209hi def link rNumber Number 210hi def link rOperator Operator 211hi def link rOpError Error 212hi def link rParenError Error 213hi def link rPreProc PreProc 214hi def link rRepeat Repeat 215hi def link rSpecial SpecialChar 216hi def link rStatement Statement 217hi def link rString String 218hi def link rStrError Error 219hi def link rType Type 220hi def link rOKeyword Title 221 222let b:current_syntax="r" 223 224" vim: ts=8 sw=2 225