DEV Community

Cadu Ribeiro
Cadu Ribeiro

Posted on • Originally published at thecode.pub on

3 3

Evaluate your ruby code directly from VIM

When I am writing code, usually I want to evaluate some piece of code. I used to do the following actions:

  • Copy and paste my code to IRB (or run my ruby script file directly from the terminal).
  • When using tmux, send my code directly from vim to tmux with the vim-tmux-runner plugin.

The first option needs an extra work of copying and pasting content. I prefer the second option, but sometimes I forgot to attach the VTR pane and get errors.

Now I’m using https://github.com/JoshCheek/seeing_is_believing along with https://github.com/t9md/vim-ruby-xmpfilter plugin

I set my .vimrc with the following content (I use Plug to manage my dependencies):

Plug 't9md/vim-ruby-xmpfilter'

" Enable seeing-is-believing mappings only for Ruby
let g:xmpfilter\_cmd = "seeing\_is\_believing"

autocmd FileType ruby nmap \<buffer\> \<F4\> \<Plug\>(seeing\_is\_believing-mark)
autocmd FileType ruby xmap \<buffer\> \<F4\> \<Plug\>(seeing\_is\_believing-mark)
autocmd FileType ruby imap \<buffer\> \<F4\> \<Plug\>(seeing\_is\_believing-mark)

autocmd FileType ruby nmap \<buffer\> \<F6\> \<Plug\>(seeing\_is\_believing-clean)
autocmd FileType ruby xmap \<buffer\> \<F6\> \<Plug\>(seeing\_is\_believing-clean)
autocmd FileType ruby imap \<buffer\> \<F6\> \<Plug\>(seeing\_is\_believing-clean)

autocmd FileType ruby nmap \<buffer\> \<F5\> \<Plug\>(seeing\_is\_believing-run)
autocmd FileType ruby xmap \<buffer\> \<F5\> \<Plug\>(seeing\_is\_believing-run)
autocmd FileType ruby imap \<buffer\> \<F5\> \<Plug\>(seeing\_is\_believing-run)
Enter fullscreen mode Exit fullscreen mode

Now I can visual select my code, use F4 to mark and that line will be evaluated, press F5 and get the result of that code. After, I can clean all marks with F6 .

Cheers,

🍻


Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay