How can I evaluate Ruby code on-the-fly when you are writing it?

This is what it looks like:

5 + 5 # => 10

Take a look at the IRuby kernel for Jupyter / IPython and ipython-vimception. If you must do it in Vim itself you might try the vim-ipython plugin, but in my experience this part doesn't work very well.


If you want to evaluate a single line you can do this with a macro simply :

qq$hy:r! ruby -e '<C-r>"'<CR>

Decomposing :

qq                " record a new macro
v$hy              " select the current line minus the ^m
:r!               " prepare to read a command
ruby -e '<C-r>"'  " call ruby inline mode executing
<CR>              " execute the whole thing

You now have the result on the new line, feel free to customize :)

  • 2
    The problem is, it has to evaluate the whole file. And replace # => on every line. – firedev Jul 7 '15 at 10:14
  • 1
    that is right, but for quick evaluation of a single line (as I first understand the question) this should work, I edited my answer – nobe4 Jul 7 '15 at 10:16

Thanks @tomstuart:

I use https://github.com/t9md/vim-ruby-xmpfilter with xmpfilter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.