eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

Can we trigger some .vimrc editing frenzy? Chapter (n): ruby-run-and-vsplit.

A quick & dirty run-and-show-output-in-vsplit-window script for vim. Definitely not as refined as the xmp decorator, and it cannot expand test assertions automagically, but I'll give it a try in my .vimrc.

Some minor details to make it more palatable:

  • works in insert, normal, visual mode, and DWIM
  • doesn't overwrite the original file, doesn't use fixed tempfiles
  • preserves the cursor position, and you're placed back in the source file
  • most importantly: killing the new window is as easy as creating it in the first place (F7 to open, S-F7 to close), and it won't break the minibufexpl (which you should be using)

(hmm some aggregators can't show the following animation) vim-ruby-eval.gif

vimscript

cat >> ~/.vimrc

   
   function! Ruby_eval_vsplit() range
let src = tempname()
let dst = tempname()
execute ": " . a:firstline . "," . a:lastline . "w " . src
execute ":silent ! ruby " . src . " > " . dst . " 2>&1 "
execute ":redraw!"
execute ":vsplit"
execute "normal \<C-W>l"
execute ":e! " . dst
execute "normal \<C-W>h"
   endfunction
   
   vmap <silent> <F7> :call Ruby_eval_vsplit()<cr>
   nmap <silent> <F7> mzggVG<F7>`z
   imap <silent> <F7> <ESC><F7>a
   map <silent> <S-F7> <C-W>l:bw<cr>
   imap <silent> <S-F7> <ESC><S-F7>a
   

^D

.vimrc snippets are always ugly; this is indeed no exception.


Last modified:2006/04/28 09:47:27
Keyword(s):[subpar] [blog] [frontpage] [ruby] [vim] [vsplit] [snippet] [vimrc]
References:[Ruby support for Vim]