Skip to content

Instantly share code, notes, and snippets.

@adfinlay
Created October 21, 2015 10:24
Show Gist options
  • Save adfinlay/830e237016eb973b598f to your computer and use it in GitHub Desktop.
Save adfinlay/830e237016eb973b598f to your computer and use it in GitHub Desktop.
Have vim inspect command history
vim () {
last_command=$(history | tail -n 2 | head -n 1)
if [[ $last_command =~ 'git grep' ]] && [[ "$*" =~ :[0-9]+:$ ]]; then
line_number=$(echo $* | awk -F: '{print $(NF-1)}')
/usr/bin/vim +${line_number} ${*%:${line_number}:}
else
/usr/bin/vim $*
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment