LoginSignup
0
0

More than 5 years have passed since last update.

【vimめも】bundle exec ruby を使用してquickrunでのruby実行

Posted at

はじめに

tempファイルにてrubyを試せるようにしており、簡単に動作確認などをできるようにしていましたが
bundleのおかげでgemのrequireがうまくいかない!!ってなったので
bundle exec rubyを使ってquickrunを実行できるようにコマンドを作りました

これが元の設定

let g:quickrun_config= {
  \   '_': {
  \     'runner': 'vimproc',
  \     'runner/vimproc/updatetime' : 60,
  \     'outputter/error/success' : 'buffer',
  \     'outputter/error/error'   : 'quickfix',
  \     'outputter/buffer/split': ':botright 8sp',
  \     'hook/time/enable': '1'
  \    },
  \   'bundle_ruby': {
  \     "vimproc/sleep"    : 0,
  \     "outputter/buffer/into" : 1
  \   }
  \ }

bundle_rubyを実行する専用コマンドを定義

必ず1回はQuickRunBundleRuby に引数を渡す必要がある
=> なければエラー

1回渡せば次回からは前回の値をそのまま使用する

再度渡せば、設定値を変更して実行

function! s:bundle_ruby(...)
  if !exists("g:my_quickrun_config")
    let g:my_quickrun_config = {}
  endif

  if exists("a:1")
    let g:my_quickrun_config["bundle_gem_path"] = a:1
  elseif !has_key(g:my_quickrun_config, "bundle_gem_path")
    echom "require temporary bundle_gemfile_dir path"
    return
  endif

  echom "env BUNDLE_GEMFILE=". g:my_quickrun_config["bundle_gem_path"]. "/Gemfile bundle exec ruby %o %s:p "
  let g:quickrun_config["bundle_ruby"]["exec"] = "env BUNDLE_GEMFILE=". g:my_quickrun_config["bundle_gem_path"]. "/Gemfile bundle exec ruby %o %s:p "
  exe "QuickRun bundle_ruby"
endfunction
command! -nargs=? QuickRunBundleRuby call s:bundle_ruby(<f-args>)

めでたしめでたし

0
0
0

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
0
0