sglink.nvim

sglink.nvim
Login

sglink.nvim

Copy a Sourcegraph link for the current line or visual selection.

https://<your-sourcegraph>/<host>/<owner>/<repo>/-/blob/<path>?L<start>[-<end>]

The repo name is derived from the buffer's git origin remote (git@github.com:acme/widget.git -> github.com/acme/widget), matching Sourcegraph's default repository naming.

On first use a popup (vim.ui.input) asks for your Sourcegraph base URL (e.g. https://sourcegraph.example.com) and stores it under stdpath("data")/sglink/base_url. Run :SgLink! to change it later.

Install

Clone the fossil repo and add it to your runtimepath, e.g. with lazy.nvim:

fossil clone https://malurs.net/fossil/sglink-nvim ~/src/sglink-nvim.fossil
mkdir ~/src/sglink-nvim && cd ~/src/sglink-nvim && fossil open ~/src/sglink-nvim.fossil
{ dir = vim.fn.expand("~/src/sglink-nvim"), name = "sglink", lazy = false }

Usage

Configuration

Setting Effect
vim.g.sglink_base_url Base URL; set it to skip the popup and the stored file.
vim.g.sglink_default_org Owner inserted for remotes whose path has none (gitolite-style host:repo -> host/<org>/repo).
vim.g.sglink_default_keymaps = false Don't create the <leader>gy mappings.

Requires Neovim >= 0.10 and git.