Created
July 18, 2012 15:49
-
-
Save code-later/3137064 to your computer and use it in GitHub Desktop.
Run Ruby from a Vim buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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