Sourcegraph for Sublime is in beta mode. Feedback or issue? Please email us at [email protected] or file an issue.
Sourcegraph for Vim allows you to view Go definitions on sourcegraph.com as you code, so you can stay focused on what's important: your code. When your cursor is on a Go symbol and you run :GRAPH (or a remapped hotkey), it should load in a channel in your browser:
To install Sourcegraph for Vim, follow the instructions for your Vim package manager.
git clone https://github.com/sourcegraph/sourcegraph-vim.git ~/.vim/bundle/sourcegraph-vim
echo "Plugin 'sourcegraph/sourcegraph-vim'" >> ~/.vimrc
vim +PluginInstall +qall
echo "NeoBundle 'sourcegraph/sourcegraph-vim'" >> ~/.vimrc
vim +NeoBundleInstall +qall
echo "Plug 'sourcegraph/sourcegraph-vim'" >> ~/.vimrc
vim +PlugInstall
Sourcegraph automatically opens a live channel and shows references for your Go code as you type by default. If you want to disable this feature, set the g:SOURCEGRAPH_AUTO
flag to "false" in your .vimrc file.
let g:SOURCEGRAPH_AUTO = "false"
Sourcegraph for your editor determines the type information for symbols locally on your development machine, using a linter called godefinfo. Check out the communication struct to see what the Sourcegraph editor plugin sends to the Sourcegraph API. If you’d like Sourcegraph for your editor to display usage examples for your private code, create an account and choose to link your private GitHub repositories at Sourcegraph.com.
Sourcegraph for Vim opens a channel in your browser to initialize your Sourcegraph session when in Go files. As you navigate through Go files, enter the Vim command :GRAPH
when your cursor is on a symbol to load its definition and references across thousands of public Go repositories.
To map Sourcegraph for Vim to a hotkey, add a remap command to your ~/.vimrc file. For instance, to map F2 to :GRAPH, add the following to ~/.vimrc.
nnoremap <F2> :GRAPH<CR>
Sourcegraph for Vim has a number of flags to customize your experience. To change your Sourcegraph settings, open add the following settings to your ~/.vimrc file.
To learn more about setting your GOPATH
, please click here.
Sourcegraph for Vim searches your shell to find GOBIN
, the full path of your Go executable. This is typically $GOROOT/bin/go
. Similarly, Sourcegraph loads your /bin/bash
startup scripts to search for the GOPATH
environment variable. If Sourcegraph cannot find your environment variables, or if you would like to use a custom GOPATH
or GOBIN
, add them in the ~/.vimrc file as follows:
g:SOURCEGRAPH_GOPATH = "/path/to/gopath"
g:SOURCEGRAPH_GOBIN = "/path/to/gobin"
This setting gives verbose output from Sourcegraph for Vim to the Vim console, which can be helpful when troubleshooting Sourcegraph for Vim. Different levels of logging are available:
No logging: 0
Only log symbols identified by godefinfo: 1
Log network calls: 2
Log all debugging information: 3
g:SOURCEGRAPH_LOG_LEVEL = 1
Sourcegraph for Vim should automatically install godefinfo
when it loads your settings. If you still receive an error message about godefinfo
installation, you can install it manually by running the following command:
go get -u github.com/sqs/godefinfo
If you want to try Sourcegraph for Vim on a local Sourcegraph server, you can define its base URL in this file using the key SOURCEGRAPH_BASE_URL
in the ~/.vimrc file.
g:SOURCEGRAPH_BASE_URL = "https://sourcegraph.com"
g:SOURCEGRAPH_SEND_URL = "https://grpc.sourcegraph.com"
Sourcegraph for Vim has been tested on Vim 7.3, and requires Python 2.X or Python 3.X to be compiled with your Vim installation. To determine if your Vim is compiled with Python, try running :python import sys; print(sys.version)
from within Vim, and verify that it does not throw an error.