Skip to content

Instantly share code, notes, and snippets.

@code-later
Created July 18, 2012 15:49
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 code-later/3137064 to your computer and use it in GitHub Desktop.
Save code-later/3137064 to your computer and use it in GitHub Desktop.
Run Ruby from a Vim buffer
autocmd FileType ruby compiler ruby
function Run()
let executable=b:current_compiler
if !getbufvar("%", "&saved")
let tmpfile = tempname()
silent! exe "write " . tmpfile . ".rb"
endif
let filename=expand('%:p')
" Create the previewwindow if doesn't exist
if ! &previewwindow
pedit /tmp/_vim_previewwindow
endif
" Change to the previewwindow
silent! wincmd P
" Run the file with and switch back to the previous window
execute "%d|silent 0r!" . executable . " '" . filename . "'"
wincmd p
endfunction
map <Leader>r :call Run()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment