Skip to content

Instantly share code, notes, and snippets.

@Phlogistique
Created March 12, 2012 17:15
Show Gist options
  • Save Phlogistique/2023440 to your computer and use it in GitHub Desktop.
Save Phlogistique/2023440 to your computer and use it in GitHub Desktop.
Open vim at specified line
#!/usr/bin/env ruby1.9.1
require 'shellwords'
files = []
opts = []
ARGV.each do |f|
if File.exists? f
files << [f, nil]
elsif f =~ /(.+):(.+?):?$/
if File.exists? $1
files << [$1, $2]
else
$stderr.puts %(WARNING: file #$1 does not exist, treating "#{f}" as an option)
opts << f
end
else
opts << f
end
end
cmd = ["vim", *opts]
if files.empty?
elsif files.length == 1
file = files.first
cmd << file[0]
cmd << "+" + file[1] if file[1]
else
plus = []
files.each do |file|
plus << "tabe #{file[0].shellescape}"
plus << file[1] if file[1]
end
cmd << "+" + plus.join(' | ') << "+tabr|q"
end
exec *cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment