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 Mar 10, 2016 12:26PM 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 29setlocal 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 177 " Vim-R-plugin: 178 runtime r-plugin/functions.vim 179endif 180 181syn match rDollar display contained "\$" 182syn match rDollar display contained "@" 183 184" List elements will not be highlighted as functions: 185syn match rLstElmt "\$[a-zA-Z0-9\\._]*" contains=rDollar 186syn match rLstElmt "@[a-zA-Z0-9\\._]*" contains=rDollar 187 188" Functions that may add new objects 189syn keyword rPreProc library require attach detach source 190 191if &filetype == "rhelp" 192 syn match rHelpIdent '\\method' 193 syn match rHelpIdent '\\S4method' 194endif 195 196" Type 197syn keyword rType array category character complex double function integer list logical matrix numeric vector data.frame 198 199" Name of object with spaces 200if &filetype != "rmd" && &filetype != "rrst" 201 syn region rNameWSpace start="`" end="`" 202endif 203 204if &filetype == "rhelp" 205 syn match rhPreProc "^#ifdef.*" 206 syn match rhPreProc "^#endif.*" 207 syn match rhSection "\\dontrun\>" 208endif 209 210if exists("r_syn_minlines") 211 exe "syn sync minlines=" . r_syn_minlines 212else 213 syn sync minlines=40 214endif 215 216" Define the default highlighting. 217hi def link rAssign Statement 218hi def link rBoolean Boolean 219hi def link rBraceError Error 220hi def link rComment Comment 221hi def link rCommentTodo Todo 222hi def link rComplex Number 223hi def link rConditional Conditional 224hi def link rConstant Constant 225hi def link rCurlyError Error 226hi def link rDelimiter Delimiter 227hi def link rDollar SpecialChar 228hi def link rError Error 229hi def link rFloat Float 230hi def link rFunction Function 231hi def link rHelpIdent Identifier 232hi def link rhPreProc PreProc 233hi def link rhSection PreCondit 234hi def link rInteger Number 235hi def link rLstElmt Normal 236hi def link rNameWSpace Normal 237hi def link rNumber Number 238hi def link rOperator Operator 239hi def link rOpError Error 240hi def link rParenError Error 241hi def link rPreProc PreProc 242hi def link rRepeat Repeat 243hi def link rSpecial SpecialChar 244hi def link rStatement Statement 245hi def link rString String 246hi def link rStrError Error 247hi def link rType Type 248if g:r_hl_roxygen 249 hi def link rOKeyword Title 250 hi def link rOBlock Comment 251 hi def link rOTitle Title 252 hi def link rOCommentKey Comment 253 hi def link rOExamples SpecialComment 254endif 255 256 257let b:current_syntax="r" 258 259" vim: ts=8 sw=2 260