https://github.com/almo7aya/openingh.nvim
Open file or project in GitHub for neovim written in lua
https://github.com/almo7aya/openingh.nvim
git lua neovim neovim-plugin nvim
Last synced: 24 days ago
JSON representation
Open file or project in GitHub for neovim written in lua
- Host: GitHub
- URL: https://github.com/almo7aya/openingh.nvim
- Owner: Almo7aya
- License: mit
- Created: 2022-09-25T20:31:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-01T22:39:56.000Z (11 months ago)
- Last Synced: 2025-10-27T22:43:46.873Z (5 months ago)
- Topics: git, lua, neovim, neovim-plugin, nvim
- Language: Lua
- Homepage:
- Size: 3.24 MB
- Stars: 144
- Watchers: 1
- Forks: 28
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openingh.nvim
Opens the current file or project page in GitHub.


[](https://github.com/Almo7aya/openingh.nvim/actions/workflows/lint.yml)

- Features
- Supports macOS, Linux, Windows and WSL
- Works with detached HEAD and supports checked out branches or forks
- Automatically selects the correct line number on the file page
- Supports GitHub, GitHub Enterprise, GitLab, and Bitbucket
- Demo

## Requirements
- Neovim 0.7.2+
## Installation
#### Example with Packer
[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim)
```lua
-- init.lua
require("packer").startup(function()
use "almo7aya/openingh.nvim"
end)
```
## Commands
- `:OpenInGHRepo`
- Opens the project's git repository page in GitHub.
- `:OpenInGHFile`
- Opens the current file page in GitHub. This command supports ranges.
- `:OpenInGHFileLines`
- Opens the current file page in GitHub. This command supports ranges.
## Registers
All of the commands above optionally take a register, e.g. `:OpenInGHFileLines+`.
In this case, the URL will not be opened in the browser, but put into the register given.
This is especially useful if you're running neovim on a remote machine, but want to open the URL locally.
## Priority
At first, this plugin try to identify the page url based on the current branch you are working in,
and if it fails then switches its base to commit.
This behavior can be inverted via bang `!`, e.g. `:OpenInGHFile!`.
Since commit based url tends to have long durablity compared to branch based one, it can be useful in some situation.
It won't be affected by subsequent commits, branch deletion after merge, and so on.
## Usage
You can call the commands directly or define mappings them:
```lua
-- for repository page
vim.api.nvim_set_keymap("n", "gr", ":OpenInGHRepo ", { silent = true, noremap = true })
-- for current file page
vim.api.nvim_set_keymap("n", "gf", ":OpenInGHFile ", { silent = true, noremap = true })
vim.api.nvim_set_keymap("v", "gf", ":OpenInGHFileLines ", { silent = true, noremap = true })
```
In case your remote repository name is different from `origin`, please set a pushDefault so that openingh can get the remote name from it.
```sh
git config remote.pushDefault # e.g. git config remote.pushDefault upstream
```
## TODO
- [x] Support the current file cursor position
- [x] Support visual mode to open a file in range selection
- [x] Support other version control websites
## Contribution
Feel free to open an issue or a pull request if you have any suggestions or improvements
## License
[MIT](./LICENSE)