2
2

More than 5 years have passed since last update.

ファイルの種類に応じてref/perldocとref/pydocとref/refeを呼びわける

Last updated at Posted at 2012-04-27

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()
2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2