Last active
December 20, 2015 11:29
-
-
Save xim/6123691 to your computer and use it in GitHub Desktop.
Vim function for your .bashrc. Turns "vim file1:42 file2:1337" into "/usr/bin/vim file1 file2 -S (script that moves the cursor to the correct line)"
This file contains hidden or 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
# vim file:34 otherfile:1337 -> Open files at respective lines. And in tabs! | |
vim() { | |
declare -a args | |
let fcount=0 | |
hit_dashdash= | |
for arg in "$@" ;do | |
if [[ "$arg" =~ ^- && ! "$hit_dashdash" ]] ;then | |
args+=("$arg") | |
[[ "$arg" = "--" ]] && hit_dashdash=1 | |
continue | |
fi | |
let fcount+=1 | |
if [[ "$arg" =~ : && -e "${arg%:*}" && "${arg##*:}" =~ ^[0-9]+*$ ]] ;then | |
args+=("${arg%:*}") | |
lines[$fcount]=${arg##*:} | |
else | |
args+=("$arg") | |
fi | |
done | |
script=$'tab all\ntablast\n' | |
while [[ $fcount -gt 0 ]] ;do | |
script+="${lines[$fcount]}"$'\n' | |
let fcount-=1 | |
[[ $fcount -gt 0 ]] && script+=$'tabprev\n' | |
done | |
`type -P vim` -S <(echo "$script") "${args[@]}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added optional column support aswell: https://github.com/dottr/dottr/blob/master/yolk/vim-open-files-at-lines.zsh