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