My new vim command

Ovid on 2007-03-26T14:11:27

Thanks to smylers for helping me work out the new vim command I have.

The problem is that when I'm working on Test::Class tests, I often only want to run one test method. So I wrote ,tc0 (test class off) and ,tc1 (test class on) mappings:

noremap ,tc0 :%s/^\s*sub\s\+\w\+[^:]*:.*Test.*{.*$/& ;return;
noremap ,tc1 :%s/^\v(\s*sub\s+\w+[^:]*:.*Test.*\{.*) ;return;/\1/

Those look OK (the second one is subtly different syntax as I'm in the process of rewriting this), but there's a bug. Basically, the first one adds a 'return' at the beginning of test methods, forcing them to skip. I manually remove the return for the test method I want and when I'm done, I run ,tc1 to remove those return statements. However, they break if I have any setup, teardown, startup or shutdown methods. However, before I fix that, I wanted to solve a long-standing problem I have. I keep changing my .vimrc and forgetting to source that file. The following line in your .vimrc will automatically source it once you've written out any changes.

" automatically source the .vimrc file if I change it
au! BufWritePost .vimrc source %

Update: It looks like the vim mappings I wanted were as follows:

noremap ,tc0 :%s/^\v\s*sub\s+\w+[^:]*:.*Tests?\s*(\(\s*(no_plan\|\d+)\s*\))?\s*\{.*$/& ;return;
noremap ,tc1 :%s/^\v(\s*sub\s+\w+[^:]*:.*Test.*\{.*) ;return;/\1/