Roku BrightScript Syntax Highlighting in Vim · Sep 19, 03:12 AM by Dylan Doxey
I don't know how everyone else is editing their BrightScript code, but I want to use vim.
1 ' ********************************************************************
2 ' ** Sample PlayVideo App
3 ' ** Copyright (c) 2009 Roku Inc. All Rights Reserved.
4 ' ********************************************************************
5
6 Sub Main()
7 'initialize theme attributes like titles, logos and overhang color
8 initTheme()
9
10 'display a fake screen while the real one initializes. this screen
11 'has to live for the duration of the whole app to prevent flashing
12 'back to the roku home screen.
13 screenFacade = CreateObject("roPosterScreen")
14 screenFacade.show()
15
16 itemMpeg4 = { ContentType:"episode"
17 SDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
18 HDPosterUrl:"file://pkg:/images/DanGilbert.jpg"
19 IsHD:False
20 HDBranded:False
21 ShortDescriptionLine1:"Dan Gilbert asks, Why are we happy?"
22 ShortDescriptionLine2:""
23 Description:"Harvard psychologist Dan Gilbert says our beliefs about what will make us happy are often wrong -- a premise he supports with intriguing research, and explains in his accessible and unexpectedly funny book, Stumbling on Happiness."
24 Rating:"NR"
25 StarRating:"80"
...
Unfortunately there's no syntax highlighting defined for Roku BrightScript. So I wrote my own.
The procedure goes roughly in two steps.
- create: /usr/share/vim/vim72/syntax/brs.vim
- add brs to: /usr/share/vim/vim72/filetype.vim
I've never created a vim syntax file before, so I decided to use the vb.vim syntax file as starter code. That served as a decent foundation to hack around and learn how the syntax file syntax works. While I was hacking the syntax file I kept a .brs program open in another instance of vim so that I could periodically reload the buffer (:e!) to see the effect of my changes. After all the hacking and experimentation, my brs.vim didn't very much resemble the vb.vim that I'd started with.
What I learned about the way the syntax file works:
- There are a number of predefined categories of syntax which map to distinct highlight colors.
- The syntax file defines keyword and pattern lists which are then related to any of the predefined syntax categories.
- The patterns can be regexes such as . matches any character. (So use "\." if you want the . character to match.)
- The syntax file has a lot of sophisticated capability which I didn't explore.
Adding the correct entry in filetype.vim was as simple as adding:
au BufNewFile,BufRead *.brs setf brs
Here's my brs.vim if you'd like to take a look for yourself (last updated July 2011).

Commenting is closed for this article.
