-
-
Save vampirechicken/93eb949e37c5f8e696f8 to your computer and use it in GitHub Desktop.
Simplify opening vim to a desired line number determined by 'grep -rn', perl error messages, perl debugger file:line indicators, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my ($file, $line_num); | |
if (@ARGV == 3) { | |
$file = $ARGV[0]; | |
$line_num = $ARGV[2]; | |
} | |
else { | |
my $line = $ARGV[0]; | |
($file, $line_num) = split(/(?: line |:)/, $line, 3); | |
} | |
$line_num =~ s/\D$//; | |
unless ($line_num =~ qr/^\d+$/) { | |
die "That's not a line number!"; | |
} | |
exec '/usr/bin/vim', "+${line_num}", $file; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after a 'grep -rn' over mutliple files, the output looks like:
Often, you'll want to edit one of those lines, and you'll want your editor to jump to the desired line at startup.
copy the output line up through the line number (up to the first whitespace after the line number), and feed it to vil as a comand line parameter.
vil will pull the line number off the end, and exec vim with the desired line number on the command line. I you were to type the command yourself, it would be:
Perl error messages (and any others) or the form:
are now supported by vil.
Saves a few clicks and a few keystrokes.