Vim のタイピング中に音をカチャカチャターン!と鳴らしたくなり、こちら を参考にやってみたが、vim-sound がうまく動作せず、工夫してみた。
.vimrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | " function function! PlaySE(name) silent! exec '!afplay ~/Dropbox/vim/sound/' . a:name . '.wav &' endfunction " 補完を閉じる autocmd CompleteDone * call PlaySE("shift") " バッファ移動 autocmd BufEnter * call PlaySE("switch") " 入力 autocmd InsertCharPre * call PlaySE("input") " 保存 autocmd BufWrite * call PlaySE("save") " インサートモード IN / OUT autocmd InsertEnter * call PlaySE("in") autocmd InsertLeave * call PlaySE("out") |
ランダム設定
例えば、input-0.wav, input-1.wav, input-2.wav の 3ファイルの SE を用意していた場合、入力時 (autocmd InsertCharPre) にランダムでそれらの SE を再生させる方法を紹介。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function! s:Rand(max) redir @n ruby << EOF rmax = VIM::evaluate("a:max") rmax = nil if rmax == "" printf rand(rmax).to_s EOF redir END let @n = strpart(@n, 1, strlen(@n) - 1) return @b endfunction " Random Play function! RandPlaySE(name) silent! exec '!afplay ~/Dropbox/vim/sound/d/' . a:name . '-' . s:Rand(2) . '.wav &' endfunction |
sound
こちらの Typewriter の SE かっこいいよ!
SOURCR:
パーマリンク