From f532b604eb621d9f697a97820e45f6d6aaa200bf Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 16 Dec 2021 12:28:11 -0600 Subject: [PATCH] Add View The Current File In GitHub as a Vim til --- README.md | 3 ++- vim/view-the-current-file-in-github.md | 30 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 vim/view-the-current-file-in-github.md diff --git a/README.md b/README.md index 0f95ee4..43bb8b7 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/vim/view-the-current-file-in-github.md b/vim/view-the-current-file-in-github.md new file mode 100644 index 0000000..15e329f --- /dev/null +++ b/vim/view-the-current-file-in-github.md @@ -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:% +```