Every once in a while I will be using Pry to test some code and I make a spelling mistake. By “every once in a while”, I mean ever freakin day.
pry > puts "Helo Wurld"
At this point, assuming you have executed the line by pressing return, you have a few options:
Note: Don’t retype the whole command, use edit!
pry > edit
By default, Pry will launch Nano with your previous command prepopulated in the editor. You can then edit and save the command. Once you exit, the command will run in Pry. This becomes increadibily helpful for lengthy multiline statements and blocks of code.
Wouldn’t it be nice if you could use the edit command with your favorite editor? My current preference is Vim. There are 2 ways to make this a reality:
Updating the $EDITOR environment variable will impact more than just Pry, so use it with caution. In my case, I want to use Vim wherever possible, so I have added the following line to my ~/.bashrc file.
Pry.config.editor = "vim"
I hope this helps.