Skip to content

Instantly share code, notes, and snippets.

@Kuniwak
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kuniwak/fcde7564a0f56c8661c6 to your computer and use it in GitHub Desktop.
Save Kuniwak/fcde7564a0f56c8661c6 to your computer and use it in GitHub Desktop.
QuickRun + NeoRspec の設定例
" NeoBundle ---------------------------------------------------------------- {{{
" call neobundle#begin(___) ... call neobundle#end() の間に置いてください
" Vim でコマンドを実行して結果を表示するプラグイン「QuickRun」をインストール
NeoBundle 'thinca/vim-quickrun'
" テストを実行中、vimの動作をブロックしないようにするために「vimproc」をインストール
NeoBundle 'Shougo/vimproc'
" rspec の一部のテストだけ実行できるプラグイン「neorspec」をインストール
NeoBundle 'alpaca-tc/neorspec.vim', { 'depends' : 'tpope/vim-rails' }
" -------------------------------------------------------------------------- }}}
" QuickRun ----------------------------------------------------------------- {{{
" QuickRunの設定オブジェクトをつくる
let g:quickrun_config = {}
" すべてのファイルタイプで vimproc をつかってコマンドを実行する
let g:quickrun_config['_'] = {
\ 'runner': 'vimproc',
\ 'runner/vimproc/updatetime' : 100
\ }
" 通常の rspec 用の設定
let g:quickrun_config['ruby.rspec'] = {
\ 'command': 'bundle',
\ 'cmdopt': 'exec rspec',
\ }
" 新規ファイル/開くファイルの名前が ~_spec.rb のとき、ファイルタイプを ruby.rspec にする
augroup my_rspec
autocmd!
autocmd BufEnter *_spec.rb set filetype=ruby.rspec
augroup END
" normal モードのとき <Leader>r で QuickRun を実行(rspec の場合はテストを実行)
nnoremap <Leader>r :<C-u>QuickRun<CR>
" -------------------------------------------------------------------------- }}}
" NeoRspec ----------------------------------------------------------------- {{{
" neorspec 用の設定関数を定義
function! s:load_neorspec_settings()
" ~_spec.rb という名前のファイルを開いたとき、拡張子を ruby.rspec にする
set filetype=ruby.rspec
" normal モードのとき、<Leader>rc で現在の行の specを 実行
nnoremap <buffer><Leader>rc :<C-U>RSpecCurrent<CR>
" normal モードのとき、<Leader>rn で現在の行の最寄りの specを 実行
nnoremap <buffer><Leader>rn :<C-U>RSpecNearest<CR>
" normal モードのとき、<Leader>rn で全ての specを 実行
nnoremap <buffer><Leader>ra :<C-U>RSpecAll<CR>
endfunction
" neorspec 用の autocmd を定義
augroup my_neorspec
autocmd!
" ~_spec.rb という名前のファイルを開いたとき、neorspec 用の設定を読み込む
autocmd BufEnter *_spec.rb call s:load_neorspec_settings()
augroup END
" neorspec で実行するコマンドを QuickRun にする(その際、ruby.neorspec という
" ファイルタイプの設定を使って実行する)
let g:neorspec_command = 'QuickRun ruby.neorspec'
" neorspec 用の QuickRun の設定(neorspec が生成する tempfile を使う)
let g:quickrun_config['ruby.neorspec'] = {
\ 'command': 'bundle',
\ 'cmdopt': 'exec rspec',
\ 'tempfile': '{spec}',
\ }
" -------------------------------------------------------------------------- }}}
" vim: fdm=marker et ts=2 sw=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment