Posts Tagged ‘Vim’

Amending vim syntax

In Compilers this semester, we’re making heavy use of a powerful Scheme¬†match macro which includes a ,[Cata -> Id] syntax for inline calls to helper functions.¬†However, the default vim syntax highlighting for Scheme flags -> as a syntax error, because it is an invalid identifier. It also fails to syntax-highlight match itself, and a number of other helpful macros that we’re using, like define-who.

To get around this problem without write access to the actual syntax file itself (located at /usr/share/vim/vim72/syntax/scheme.vim in the burrow) you can simply create an additional syntax file called ~/.vim/after/syntax/scheme.vim. This file will be automatically loaded after the default Scheme syntax, whenever a Schemely buffer is loaded. I put the following lines in my file:

syn keyword schemeSyntax define-who match ->
syntax region schemeMultilineComment start=/#|/ end=/|#/ contains=schemeMultilineComment

This also fixes the problem that, in the default Scheme mode, #| and |# are not treated as comment delimiters. Of course, you can add any personal macros to the list of syntax keywords.

One last problem: I’m using Aaron Hsu’s ChezWEB framework, and he uses .w as the extension for ChezWEB source files, which ought to be highlighted as Scheme source. Add this line to ~/.vimrc to load Scheme syntax whenever a .w buffer is loaded:

au BufNewFile,BufRead *.w set filetype=scheme