Uniteからvim-refを呼び出すことができるけど、いちいち:Unite ref/perldoc
とか打つの面倒だし、かと言ってperldocとpydocに別々のキーマッピングをするのも嫌なので、perlのソースを開いている時はref/perldoc
を開き、pythonの時はref/pydoc
を開くようにしたかった。
追記:ベターな方法
&filetype
で現在のファイルタイプを参照できることが分かったので以下のように変更した
.vimrc
function! UniteRefDoc()
if &filetype =~ 'perl'
Unite ref/perldoc
elseif &filetype =~ 'python'
Unite ref/pydo
elseif &filetype =~ 'ruby'
Unite ref/refe
endif
endfunction
nnoremap <silent> <space>u<space> :<C-u>call UniteRefDoc()<CR>
昔の内容
perlとpythonのバッファから入ったり出たりするタイミングでマッピングを上書きしているだけ。
vim-scriptに明るくないので、もっといい方法があればコメント下さい!
.vimrc
function! s:unite_ref_clear()
noremap <space>u<space> <Nop>
endfunction
function! s:unite_ref_perldoc()
noremap <silent> <space>u<space> :<C-u>Unite ref/perldoc<CR>
endfunction
function! s:unite_ref_pydoc()
noremap <silent> <space>u<space> :<C-u>Unite ref/pydoc<CR>
endfunction
autocmd BufEnter *.pl call s:unite_ref_perldoc()
autocmd BufLeave *.pl call s:unite_ref_clear()
autocmd BufEnter *.py call s:unite_ref_pydoc()
autocmd BufLeave *.py call s:unite_ref_clear()