18 Feb 2013

Toggling Pry in Ruby Script

I’ve been using the daylights out of Pry ever since learning about it ~ 1 year ago. I’ve also been evangelizing about it to anyone who will listen:

@_zph Thanks for reading!And thanks for teaching me tmux and pry.Been trying them here and there - still very shaky with tmux.

— Steve Jackson (@stevejxsn) February 16, 2013

The most recent way that I’m using Pry is by dropping the following line into anywhere that I need to work with:require 'pry'; binding.pry

But adding that to scripts and then deleting it becomes repetitive. So here’s a little Vim function that that toggles my Pry statement. If the current line matches the Pry snipped, the line’s deleted. If the current line doesn’t match the snippet, then the snippet is added at the cursor. ( It’s best used on a blank line until I make the function more robust. )

Special thanks go to @Banisterfiend for all his hard work on the Pry gem. It makes my Ruby life a much happier experience. If you’ve benefited from his hard work, please consider a donation @ the following link.

Also, special thanks to Tim Pope. Reading his vim-fugitive code gave me the syntax hint on how to make this work.