Speed Up Debugging With Viline

This is a practical hack to speed up your coding-debugging cycles:

Most programming languages tell you that some error occurred in some file on line 666 like so:

Blah, blah. Some error in /some/file.foo:666. Blah. 

Viline is a simple bash function that lets you copy and paste the file:linenumber combo from error messages as an argument to vi.

Vi will then start with the cursor at the offending line. Handy, eh? :-)

To use viline, add the following to your .bashrc:

1
2
3
4
    # viline: start vi with file:line
    function f_viline {  vim $(sed -r 's/:([0-9]+)$/ +\1/'<<<$1); }
    alias viline=f_viline
    alias vi=f_viline

The alias for vi itself is optional, myself, I never give vi any arguments but filenames, so this is pretty safe for me. Otherwise just type viline instead of vi when you want to edit a file with a file:line style argument.

Comments