Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

SyntaxHighlighter Vimscript brush and Blackboard theme

Here on Vimcasts.org, I use Alex Gorbatchev’s SyntaxHighlighter to colorize the code excerpts. I couldn’t find a syntax ‘brush’ for Vimscript, so I wrote my own. I also created a color theme based on the Blackboard scheme that I use in Vim (and TextMate).

I have published the Vimscript brush and Blackboard theme on github. You can find them here:

I created these two files, but everything else in the project is by Alex Gorbatchev and the SyntaxHighligher community. The project is not hosted on github, otherwise I would have forked it.

Vimscript keywords

The Vimscript brush includes a large list of keywords. I copied this list from Vim’s own syntax file, which you can open up in Vim by running :edit $VIMRUNTIME/syntax/vim.vim. When defining syntax files for Vim, you can use a form of shorthand, e.g. e[dit], which is equivalent to including both e and edit. The SyntaxHighligher doesn’t understand this convention, so I had to expand all of these abbreviations into longhand. I wrote a little ruby script that does this for me. Here’s the gist of it:

list = ['abc[lear]', 'argu[ment]', 'bel[owright]']
pattern = /(\w+)(\[(\w+)\])?/
output = []
list.each do |token|
  if token =~ pattern
    output << $1 if $1.length > 1
    if $3
      output << $1 + $3
puts output.join(' ')

Since I first created the Vimscript brush, I have occasionally pruned the list of keywords. Although it might be handy that you can type :e instead of spelling out :edit in full, I don’t really want the letter e to be considered a keyword.

This is a matter of taste, but I have come accross other situations where the shorthand actually caused problems. For example, if I want to include an angle bracket character (common in Vimscript when creating keymappings), I have to encode the < character to it’s HTML entity &lt;. I found that the syntax highlighter would identify lt as a keyword (being shorthand for ltag), breaking the HTML entity up into something like &<code class="keyword">lt</code>;. As a result, the angle bracket would instead appear spelled out as an HTML entity, with lt highlighted as a keyword!

This makes a good case for removing lt from the list of keywords. It is quite possible that there are other keywords in the list which could cause similar problems, as yet unencountered. If you try out the Vimscript brush and discover any of these problems, please let me know. Or better still, fork the project, fix it, and send me a pull request on Github.


Level-up your Vim


Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify


Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..