1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 23:28:02 +00:00

Add View The Current File In GitHub as a Vim til

This commit is contained in:
jbranchaud
2021-12-16 12:28:11 -06:00
parent 4045d97d63
commit f532b604eb
2 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
# View The Current File In GitHub
Sometimes when I'm browsing some code in Vim, I'll want to open up the a file
in GitHub. This is usually so that I can grab a URL to share as a point of
reference in a conversation.
To do this, I run [`vim-fugitive`](https://github.com/tpope/vim-fugitive)'s
`:Gbrowse` which will open up the current file for the current commit on the
current branch.
This works great if your current branch is the `main` branch. Or if your
current branch has previously been pushed up as a remote. It doesn't work so
well if you are on a local-only feature branch. You'll get the classic Star
Wars themed GitHub 404 page.
There is a handy workaround. You can specify the branch and file you want when
you run the command.
```
:Gbrowse main:app/models/user.rb
```
That will open the specified file (`app/models/user.rb`) as it exists on the
specified branch (`main`).
A shorthand of that for the current file looks like this:
```
:Gbrowse main:%
```