How do I open the current file on GitHub directly from Vim?
Answer
:GBrowse
Explanation
The vim-fugitive plugin combined with vim-rhubarb (for GitHub support) provides the :GBrowse command, which opens the current file on your repository's web hosting provider directly in your browser. This is invaluable for sharing links to specific lines of code with teammates or quickly jumping to the web UI for a pull request review.
How it works
With any file in a Git repository open in Vim, run:
:GBrowse
This opens your default browser to the file on GitHub (or GitLab, Bitbucket, etc., with the appropriate companion plugin).
Opening specific lines
You can highlight specific lines by selecting them in visual mode first:
- Enter visual mode with
V - Select the lines you want to highlight
- Run
:GBrowse
The resulting URL will include the line range as a fragment (e.g., #L10-L25), making it perfect for sharing in code reviews, issues, or chat.
Copying the URL without opening
If you just want the URL on your clipboard without opening a browser, use the bang variant:
:GBrowse!
This copies the URL to your clipboard so you can paste it into a pull request comment, Slack message, or issue tracker.
Browsing commits and blobs
You can browse any Git object, not just the current file:
:GBrowse " current file at current branch
:GBrowse HEAD~3:% " current file as of 3 commits ago
:GBrowse main:% " current file on the main branch
:GBrowse abc1234 " a specific commit by hash
From the blame buffer
Run :Git blame first, then press <CR> on a commit to open it, and run :GBrowse to view that specific commit on GitHub. This is a fast workflow for tracing a change and sharing it.
Required companion plugins
| Hosting Provider | Plugin |
|---|---|
| GitHub | vim-rhubarb |
| GitLab | fugitive-gitlab.vim |
| Bitbucket | vim-fubitive |
| Sourcehut | srht.vim |
Tips
- Use
:GBrowse!in visual mode to copy a permalink with line numbers directly to your clipboard :GBrowseworks from the fugitive status buffer (:Git) too — press<CR>on a file, then:GBrowse- The generated URLs use the current commit SHA, so they remain stable even after new pushes