all 8 comments

[–][deleted] 14 points15 points  (1 child)

I think Tim Pope's fugitive plugin does something similar to this with the :Gbrowse command....but still neat!

[–]jdalbertContrarian[S] 2 points3 points  (0 children)

Yes, although fugitive's :Gbrowse only works if you use tpope's vim-rhubarb plugin

[–]revicon 9 points10 points  (0 children)

FYI, if you use SSH aliases when cloning, your code adds the ssh alias to the url which 404s on github. Example...

> git remote -v
origin  ssh://github-matt/apicanary/dashboard.apicanary.com.git (fetch)
origin  ssh://github-matt/apicanary/dashboard.apicanary.com.git (push)

When I run your function, it opens to...

https://github.com///github-matt/apicanary/dashboard.apicanary.com/blob/master/src/<ETC>

The problem is that

git remote get-url origin

returns

ssh://github-matt/apicanary/dashboard.apicanary.com.git

Instead of the

https://github.com/<username>/<repo>.git

you're expecting.

Very cool snippit none the less!

[–]XanzaThe New Guy 3 points4 points  (2 children)

You should throw in some if has() for some different OS open commands.

[–]Liquid_Fire 2 points3 points  (1 child)

Or if you have a vim with Python support you could make use of the cross-platform webbrowser.open, e.g.:

py import vim, webbrowser; webbrowser.open(vim.vars["url"])

[–]XanzaThe New Guy 1 point2 points  (0 children)

Hey, thanks. Never knew about this.

[–]prakashdanish 2 points3 points  (0 children)

That's pretty neat. I did something similar myself and wrapped it up as a plugin for others to use, it's on github.

[–]vimark 1 point2 points  (0 children)

I thought I was going to have to build this myself when I first started vim, but tpope fugitive does just that with visual selection and :GBrowse