Vim で Scala のシンタックスハイライト(カラースキーマ)を使う

基礎的知識として、Mac とか Ubuntu の vi は vim です。つまりふつーに vi コマンドで拡張子が .scala のファイルを開いた場合に、Scala 用のシンタックスカラーになってくれるようにする設定方法です。

Scala 2.9 をインストールする

MacBook Air 使ってるので、MacPorts でインストール

$ sudo port install scala29

Scala のインストールディレクトリに Vim用の便利設定ファイル一式があるのでこれを使います。

$ ll /opt/local/share/scala-2.9/misc/scala-tool-support/vim/
total 8
-rw-r--r--  1 root  admin  1040 Aug 30 01:44 README
drwxr-xr-x  3 root  admin   102 Nov 23 23:58 ftdetect
drwxr-xr-x  3 root  admin   102 Nov 23 23:58 indent
drwxr-xr-x  3 root  admin   102 Nov 23 23:58 plugin
drwxr-xr-x  3 root  admin   102 Nov 23 23:58 syntax

使い方は README ファイルに書いてあります。

$ cat /opt/local/share/scala-2.9/misc/scala-tool-support/vim/README 
From Stefan Matthias Aust's website (http://www.3plus4.de/scala/):

* How to use it

The Vim editor (http://www.vim.org/) can be customized using the
following two resources located either in your home directory or
in some system-specific directory:

    .vimrc  is the main configuration file; it should at least
            contain the command "syn on" to enable syntax
            hightlighting

    .vim    is the Vim configuration directory; it contains scripts
            (http://www.vim.org/scripts/) in predefined locations.
            The support files for Scala are contained in the three
            directories "indent", "syntax" and "ftdetect"; simply
            copy them to your Vim configuration directory.

Vim searchs for user-specific resources at the following locations:

    - under Linux, Solaris, etc. usually /home/<username>/.vimrc
    - under Mac OS X: /Users/<username>/.vimrc
    - under Windows:  %HOMEDRIVE%%HOMEPATH%\_vimrc

* Thanks

scala.vim was contributed by Stefan Matthias Aust (nobody@3plus4.de)

要点は2つ。

  • ~/.vimrc を作成して、"syn on" って書く
  • ~/.vimディレクトリの中に Vim用の便利設定ファイル一式を突っ込む

Vim の設定

.vimrc を作成します

$ vi ~/.vimrc
syn on

Vim用の便利設定ファイル一式をコピー

$ cp -rp /opt/local/share/scala-2.9/misc/scala-tool-support/vim/* ~/.vim/

上手にできました

ちょーど Play2.0 のサンプル試してたので、開いてみます。

$ vi ~/git/Play20/samples/scala/helloworld/app/controllers/Application.scala