消えた g:unite_enable_ignore_case と g:unite_enable_smart_case とその代替

この記事の内容は誤っていました。最後に正しい情報が追記してあります。



私の要望により unite.vim から g:unite_enable_ignore_case オプションと g:unite_enable_smart_case オプションが削除された。
責任取って、なんで消えたのかと代わりの設定方法について解説してみる。

なぜ消えたのか

これらはグローバルオプションのため、別名のバッファで別の設定を使うことができない。
例えば、ファイルを開く用のバッファでは ignorecase で tag を開く用のバッファでは noignorecase ってことができない。
unite バッファを開くたびに値を書き換えるという手もあるけど、unite バッファを複数同時に開くと破綻する。まあ複数同時に開く人はそうそういないと思うけど、どちらにしても根本的な解決策ではない。

今後はどう設定すればいいのか

FileType unite で直接 ignorecase と smartcase を設定する。unite は専用のバッファを開くので、直接オプションを変えてしまってもまったく問題ない。これならバッファ毎に値を保持できる。
vimrc でやる例*1

autocmd FileType unite setlocal ignorecase smartcase

ftplugin でやる例

" after/ftplugin/unite.vim
setlocal ignorecase smartcase
let s:context = unite#get_context()
if s:context.buffer_name ==# 'files'
  " ファイル選択時は smartcase を使わない
  setlocal nosmartcase
endif

ftplugin の方がいろいろやりやすいので個人的にはこっち推奨。
と言うか unite はカスタマイズすればするほど味が出るので ftplugin ない人はこの機会に作ってみるといいよ!



追記

この記事をドヤ顔で書いた後で、'ignorecase' オプションと 'smartcase' オプションは実はグローバルオプションだったので根本的に無意味という残念すぎる事実が発覚。初歩的すぎるミスで泣きそうです。
で、Shougo さんに報告したところ、対策をしてくれました。ありがとうございます!

今後はどう設定すればいいのか

バッファ名のオプションに ignorecase と smartcase が追加されたので、unite#set_buffer_name_option() を使って設定すればいいです。

" vimrc
" デフォルトでは ignorecase と smartcase を使う
call unite#set_buffer_name_option('default', 'ignorecase', 1)
call unite#set_buffer_name_option('default', 'smartcase', 1)
" ファイル選択時は smartcase を使わない
call unite#set_buffer_name_option('files', 'smartcase', 0)

何も設定しなければ 'ignorecase' と 'smartcase' の値が直接使われる。

*1:augroupは省略