Created
September 20, 2015 03:00
-
-
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 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
# 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