Awhile back I read Ovid’s 2010 post Method Extraction in Vim. I suspected I could use it but I never followed through.
At work we recently formed a book club that is reading through Fowler’s Refactoring. As a result, one of my coworkers mentioned that he was looking for an Extract Method tool for Perl in Vim. I was reminded of Ovid’s post and decided to finally follow up on it.
I ended up basing my implementation on one of the commenters’ suggestions; which referenced Crossing the Rubicon. Again or more specifically Jesse Vincent’s extract. After trying out extract I decide I wanted to tweak a few things and ended up making a lot of changes to clean it up. Feature-wise not much changed except some minor improvements in the whitespace of the extracted method and the removal of a non-core dependency. My modified version is available as a Gist if anyone is interested.
Then I added Ovid’s mapping in my
vnoremap <leader>sub :! perl-extract<CR>
So far all I have used it for was in cleanup itself. ;-)