Skip to content

Instantly share code, notes, and snippets.

@alanocallaghan
Last active May 4, 2018 13:48
Show Gist options
  • Save alanocallaghan/baa182c11eb458ef978d47d5dac6d079 to your computer and use it in GitHub Desktop.
Save alanocallaghan/baa182c11eb458ef978d47d5dac6d079 to your computer and use it in GitHub Desktop.
Place this in your `~/.nanorc` for great R syntax highlighting in the only console editor I can be bothered to learn. Thanks to the author and editor for providing it in the first place.
############################################
# Syntax highlighting for R #
# by Stephen Haptonstahl #
# March 15, 2009 #
# http://srh.ucdavis.edu/drupal/node/20 #
# edited by Mike Miller #
# Placed on GitHub by Alan O'Callaghan #
# (could no longer find the original) #
############################################
syntax "R" "\.R$"
# reserved words
color brightyellow "\b(if|else|repeat|while|function|for|in|next|break|TRUE|T|FALSE|F|NULL|Inf|NaN|NA|NA_integer_|NA_real_|NA_complex_|NA_character_|\.\.\.)\b"
color brightyellow "\.\.[0-9]"
color brightred "\b(require|library)\b"
# logicals
color brightgreen "(==|<=|>=|!=|!|<|>|\||\|\||&|&&|%in%|%%|%\*%|%/%|%o%|%x%)"
# strings
color cyan "'[^']*'"
color cyan ""[^"]*""
# "
# variable definitions
color blue "^.*?<-"
color yellow start="[$@%]" end="[[:alnum:]]*"
# function definitions
color magenta "\<([A-Za-z0-9\.]+)\>\("
# parameters -- not working yet
# icolor brightblue "[^,\(=]*=(?:[^=])"
# danger!
color black,red "(stop|warning|return)"
color red " = "
color yellow "[(){}[;|<>]"
color yellow "\]"
color brightred "<-"
## Comment highlighting
color brightblack "#.*$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment