Status: Beta
sg.nvim is a plugin focused on bringing many of the features of sourcegraph.com into Neovim.
To configure logging in:
- Log in on your Sourcegraph instance.
- Click your user menu in the top right, then select Settings > Access tokens.
- Create your access token, and then run
:SourcegraphLoginin your neovim editor after installation. - Type in the link to your Sourcegraph instance (for example:
https://sourcegraph.com) - And then paste in your access token.
An alternative to this is to use the environment variables specified for src-cli.
You can check that you're logged in by then running :checkhealth sg
Requires:
- nvim 0.9 or nvim nightly
- Node.js >= 18.17.0 (LTS) at runtime for
cody-agent.js
(By default, sg.nvim downloads released binaries from Github. If you prefer to build the plugin yourself, you'll need cargo to build)
lazy.nvim
-- Use your favorite package manager to install, for example in lazy.nvim
return {
{
"sourcegraph/sg.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
-- If you have a recent version of lazy.nvim, you don't need to add this!
build = "nvim -l build/init.lua",
},
}packer.nvim
-- Packer.nvim, also make sure to install nvim-lua/plenary.nvim
use { 'sourcegraph/sg.nvim', run = 'nvim -l build/init.lua' }vim-plug
" Using vim-plug
Plug 'sourcegraph/sg.nvim', { 'do': 'nvim -l build/init.lua' }After installation, run :checkhealth sg.
(Nix instructions at the end of the readme)
-- Sourcegraph configuration. All keys are optional
require("sg").setup {
-- Pass your own custom attach function
-- If you do not pass your own attach function, then the following maps are provide:
-- - gd -> goto definition
-- - gr -> goto references
on_attach = your_custom_lsp_attach_function
}" Example mapping for doing searches from within neovim (may change) using telescope.
" (requires telescope.nvim to be installed)
nnoremap <space>ss <cmd>lua require('sg.extensions.telescope').fuzzy_search_results()<CR>- Latest Demo: Alpha Release
- Short clip of cross repository jump to definition: Clip
- Demo v2: YouTube
- Demo v1: YouTube
Cody:
- Chat interface and associated commands
- Autocompletions, prompted
- Autocompletions, suggested
Sourcegraph Browsing:
- Read files:
- Directly from sourcegraph links:
:edit <sourcegraph url>sg.nvimwill automatically add protocols for handlinghttps://sourcegraph.com/*links.
- Directly from buffer names:
:edit sg://github.com/tjdevries/sam.py/-/src/sam.py - Use
:SourcegraphLinkto get a link for the location under your cursor
- Directly from sourcegraph links:
- Reading non-files:
- Repository roots
- Folders
- Expand Folders
- Unexpand Folders
- Open file from folder
- Use builtin LSP client to connect to SG
- Goto Definition
- Goto References
- <20 references
- kind of broken right now for lots of references
- Basic Search
- literal, regexp and structural search support
-
type:symbolsupport - repo support
- Advanced Search Features
- Autocompletion
- Memory of last searches
- More? Make an issue with something you're missing :)
The project is packaged as a Nix Flake. Consume it as you normally would. In your Nix configuration,
make sure that sg-nvim is included both as a Neovim plugin and as an environment/user package
(because sg-lsp needs to be on your PATH).
See Neovim guide on NixOS wiki for more details on configuration See gh:willruggiano/neovim.drv for a practical configuration.
For Nix contributors and maintainers:
- Feel free to
nix flake updateevery once in a while to make sureflake.lockis up-to-date - Minimal
sg.nvim-integrated neovim package for testing and example - Integrate
sg.nvim+ Cody onto nixpkgs:vimPlugins
You will also need to add the built .cdylib onto package.cpath. Here is one example
using gh:willruggiano/neovim.nix:
sg = let
system = "x86_64-linux";
package = inputs.sg-nvim.packages.${system}.default;
in {
inherit package;
init = pkgs.writeTextFile {
name = "sg.lua";
text = ''
return function()
package.cpath = package.cpath .. ";" .. "${package}/lib/?.so;${package}/lib/?.dylib"
end
'';
};
};