Keeping it Small and Simple


Getting scala syntax hightlighting to work in vim

Filed under: Vim — Tags: , , — Lorenzo E. Danielsson @ 13:44

If you want vim to be able to syntax highlight and indent scala source files you can

First of all go here and you will see three sub-directories: ftdetect, indent and syntax.

Each one of the sub-directories contains a file called scala.vim. Download them. Notice that if you save them one after the other they will overwrite one another, so you might want to give them names like scala-ftd.vim, scala-ind.vim and scala-syn.vim.

If you only want your user to have scala filetype support, you can move the files into ~/.vim. Make sure the directories ~/.vim/ftdetect, ~/.vim/indent and ~/.vim/syntax all exist then:

mv scala-ftd.vim ~/.vim/ftdetect/scala.vim
mv scala-ind.vim ~/.vim/indent/scala.vim
mv scala-syn.vim ~/.vim/syntax/scala.vim

This is a good solution if you don’t have root access on the system. If you do and you want all your users to have access to scala filetype detection, do the following instead:

mv scala-ftd.vim /usr/share/vim/addons/ftdetect/scala.vim
mv scala-ind.vim /usr/share/vim/addons/indent/scala.vim
mv scala-syn.vim /usr/share/vim/addons/syntax/scala.vim

What if it doesn’t work?

I grabbed my scala vim files from a different location and they refused to work. Looking at :set output in vim I saw that there was garbage at the end of the filetype name (scala^M instead of scala). If this happens to you you can solve it by converting line-endings from DOS to UNIX. There are about 100,000,000 ways to do this, including writing your own little script in **your favorite language**, but the simplest possible solution might be this:

% su
[enter root password]
# aptitutde install tofrodos
# exit
% cd ~/.vim/ftdetect/scala.vim
% fromdos scala.vim

Make sure you invoke fromdos on the other two scala.vim files as well. Once that is done, scala filetype support should work.


  1. Thanks for the tip. Works like a charm.

    Comment by HRJ — 2008.02.09 @ 12:58

  2. I find myself searching for this tip everytime I move to a new workstation.

    I have now bundled these files as a tar archive available here:

    Comment by HRJ — 2008.07.22 @ 07:55

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: