Last active
January 20, 2019 07:53
-
-
Save iboard/11140216 to your computer and use it in GitHub Desktop.
Run the current line in vim with rspec
This file contains hidden or 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
" Call rspec from vim | |
" Apr 21st, 2014 Andi Altendorfer <[email protected]>, License MIT | |
" | |
" RunCurrentLine() ... evaluate current line with ruby-interpreter and append " output to the end of the line | |
" RunCurrentFile() ... evaluate current file with ruby-interpreter and append " output to the end of the file | |
" | |
" Copy this file to your ./vim/pluglin directory | |
function! RunCurrentLine () | |
exec "normal! $F#D" | |
let _current_line = getline(".") | |
let _cmd = matchstr( _current_line, '^puts' ) | |
let cmd = _current_line | |
if empty(_cmd) | |
let cmd = "puts " . _current_line | |
endif | |
exec "r! ruby -e" . shellescape( cmd ) | |
exec "normal! kA # => \eJ" | |
endfunction | |
function! RunCurrentFile () | |
exec "normal! :$\no__END__\n\e" | |
exec "normal! :0\n/^__END__$\nVGxo__END__\n\e" | |
let cmd = expand('%:p') | |
exec "r! ruby " . shellescape(cmd) | |
endfunction | |
map <c-j>rb :call RunCurrentLine()<CR> | |
map <c-j>rB :call RunCurrentFile()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment