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