When working with Ruby, I often need to insert
binding.pry to trouble-shoot a problem. I got tired of typing this all the time so some time back I created a mapping in my .vimrc to handle this:
nnoremap <Leader>,upry Obinding.pry<ESC> nnoremap <Leader>,dpry obinding.pry<ESC>
Now inserting the code was a simple
<Leader> is a comma)
Here’s the code, hoping it’s useful to someone else.
First, determine the debugging statement required, based on the filetype setting: I also realized that our Cucmber step
Then I pry could also use the same treatment.
Then define the new mapping
nnoremap <Leader>,upry :execute "normal " . "O" . SetPry()<ESC> nnoremap <Leader>,dpry :execute "normal " . "o" . SetPry()<ESC>
Now I can use the same command, regardless of the language, and vim is smart enough to just do the right thing.