vimでgolang (あるいは他の言語) のquickfix errorformat を利用する (Debian)

Vimは、組み込みでいくつかの言語のコンパイル設定ファイルを持っている。 Debian, Vim 8.1なら、/usr/share/vim/vim81/compiler の下に ${言語名}.vim というファイルが置いてある。golangなら /usr/share/vim/vim81/compiler/go.vim。このPATHは runtimepathpackpath を見ればみつかる。

これを読み込むことで (拡張子で自動で読んでくれるわけではないらしい?) quickfix errorformatが適用される。

:compiler!  go.vim

必要があれば autcmd などで拡張子毎の設定をしておくと良さそう。

その他

:help compiler によると

What the command actually does is the following:
- Delete the "current_compiler" and "b:current_compiler" variables.
- Define the "CompilerSet" user command.  With "!" it does ":set", without "!"
  it does ":setlocal".
- Execute ":runtime! compiler/{name}.vim".  The plugins are expected to set
  options with "CompilerSet" and set the "current_compiler" variable to the
  name of the compiler.
- Delete the "CompilerSet" user command.
- Set "b:current_compiler" to the value of "current_compiler".
- Without "!" the old value of "current_compiler" is restored.

compiler/{name}.vim を読んでみると、makeprg (:make が発効されたときのコマンド)とerrorformat が設定されているようだ。 errorformatを自分で書くときののexampleとしても役立つ。

参考

  • :help runtime
  • :help compiler
  • :help current_compiler
  • :help makeprg