Easy Github URLs from Vim

URLs are great aren’t they?

You include them in your Slack messages and your co-workers can see exactly what you’re talking about in a single click. I wish people would use them more (and design apps that support them properly).

Anyway, a super-useful Vim mapping I use is:

vnoremap <leader>gb :GBrowse! master:%<cr>

which, after visually selecting a block of code, grabs its Github URL from the HEAD of master and copies it to the clipboard. I use this several times daily.

If you want the URL for the code block from your current branch, use:

:GBrowse!

although you have to have pushed your branch for the URL to resolve.

Various other “fugitive-objects” can be passed to :GBrowse to open or copy URLs for other objects – see the help file for more details.

The :Gbrowse function is provided by the excellent vim-fugitive and requires the vim-rhubarb plugin for Github support.

——————

Something wrong? Suggest an improvement or add a comment (see article history)
Tagged with: github, vim
Filed in: tips

Previous: Software development tips – part 2
Next: Maintainable Terraform CIDR lists

Copyright © 2005-2024 David Winterbottom
Content licensed under CC BY-NC-SA 4.0.