R and VIM

Syntax Highlighting and Indenting

I modified the existing R vim syntax file, and created a vim R indent file since R's indention in vim was broken. Below are the attachments.

Installation instructions:
  • From a terminal run the command: mkdir -p ~/.vim/indent ~/.vim/syntax
  • Move indent-r.vim to ~/.vim/indent/ and rename it to r.vim (Ex: mv indent-r.vim ~/.vim/indent/r.vim)
  • Move syntax-r.vim to ~/.vim/syntax/ and rename it to r.vim (Ex: mv syntax-r.vim ~/.vim/syntax/r.vim)

The syntax file currently defines highlighting for most (if not all) functions from the base, stats, graphics, tools, methods, and utils packages. Fixed to include primitive and internal statements. There may be duplicates; also there is some concern about the file size, since syntax files are generally supposed to be small. (Works fine on my machine though. -- JeremyStephens)

For the bleeding edge version of these files, here's a link to JeremyStephens' subversion repository (assuming his computer is on and ip address hasn't changed).

Filetype detection

Vim includes syntax highlighting for two other languages that use the .r and .R file extensions. Vim searches up to the first 50 lines of a file and checks the comment syntax to determine whether it is R or Rexx. If no comments are found, it defaults to Rexx. This can be annoying for starting a new script. If you want .r and .R to ALWAYS be associated with R syntax, put au BufNewFile,BufRead .r,.R  setf r in your ~/.vim/filetype.vim (alternatively, you can use the same line in ~/.vim/ftdetect/r.vim).

Other Tips

* Put syn match rArrow /->\{1,2}/ in ~/.vim/after/syntax/r.vim to match the right arrow. The default syntax highlighting for R that comes with Vim only includes the left arrow.
Topic attachments
I Attachment Action Size Date Who Comment
indent-r.vimvim indent-r.vim manage 1.0 K 09 Sep 2005 - 12:54 JeremyStephens VIM indent file for R
syntax-r.vimvim syntax-r.vim manage 46.5 K 13 Sep 2005 - 10:38 JeremyStephens VIM syntax file for R
Edit | Attach | Print version | History: r7 < r6 < r5 < r4 | Backlinks | View wiki text | Edit WikiText | More topic actions...
Topic revision: r6 - 21 Sep 2006, WillGray
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback