1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +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

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1171 TILs and counting..._
_1172 TILs and counting..._
---
@@ -1321,6 +1321,7 @@ _1171 TILs and counting..._
- [Using vim-surround With A Visual Selection](vim/using-vim-surround-with-a-visual-selection.md)
- [Verbose Commits With Fugitive](vim/verbose-commits-with-fugitive.md)
- [View Commit History of a File](vim/view-commit-history-of-a-file.md)
- [View The Current File In GitHub](vim/view-the-current-file-in-github.md)
- [Viewing Man Pages with man.vim](vim/viewing-man-pages-with-man-vim.md)
- [Vim Without The Extras](vim/vim-without-the-extras.md)
- [What Is On The Runtime Path?](vim/what-is-on-the-runtime-path.md)

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:%
```