Skip to content

Instantly share code, notes, and snippets.

@wezm
Created September 20, 2015 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wezm/f18e3ec540e7b59337fc to your computer and use it in GitHub Desktop.
Save wezm/f18e3ec540e7b59337fc to your computer and use it in GitHub Desktop.
Zsh function to extract line number from a path and open the file in vim at that line
# This will open files at the specified line in vim if the last argument
# matches filename:line. E.g. app/models/user.rb:123
function v() {
last_arg="${@: -1}"
parts=("${(s/:/)last_arg}")
file=$parts[1]
line_number=$parts[2]
if [[ $line_number -gt 0 ]]; then
vim "+$line_number" "$file"
else
vim $@
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment