vim-go Deployment and Usage Guide
Prerequisites
- Vim 8.2.5072 or later, or Neovim 0.4.0 or later
- Go (latest stable version recommended)
- Git for cloning the repository
- curl or wget (usually pre-installed) for downloading binaries
Installation
Step 1: Install the Plugin
Choose one of the following methods based on your package manager:
vim-plug (Recommended):
Add to your .vimrc or init.vim:
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Then run :PlugInstall
Vim 8 Native Packages:
git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go
Neovim Native Packages:
git clone https://github.com/fatih/vim-go.git ~/.local/share/nvim/site/pack/plugins/start/vim-go
Pathogen:
git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
Vundle:
Add to your .vimrc:
Plugin 'fatih/vim-go'
Then run :PluginInstall
Step 2: Install Required Binaries
After installing the plugin, open Vim/Neovim and run:
:GoInstallBinaries
This command installs all required tools including gopls, dlv (delve), golint, goimports, and others via go install.
Note: If you update the plugin later, run :GoUpdateBinaries to ensure all tools are current.
Step 3: Generate Help Tags
Depending on your installation method, you may need to generate help tags manually:
:helptags ALL
Configuration
Essential Settings
Add to your .vimrc or init.vim:
" Enable formatting on save (keeps cursor position and undo history)
let g:go_fmt_autosave = 1
" Use gopls for completion and analysis (enabled by default)
" To disable gopls and use alternative tools:
" let g:go_gopls_enabled = 0
" Share gopls instance with other plugins (e.g., coc.nvim, ale)
let g:go_gopls_options = ['-remote=auto']
" Enable syntax highlighting
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
Integration Configuration
Tagbar Integration (requires gotags):
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : ['p:package', 'i:imports:1', 'c:constants', 'v:variables', 't:types', 'n:interfaces', 'w:fields', 'e:embedded', 'm:methods', 'r:constructor', 'f:functions'],
\ 'sro' : '.',
\ 'kind2scope' : { 't' : 'ctype', 'n' : 'ntype' },
\ 'scope2kind' : { 'ctype' : 't', 'ntype' : 'n' },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
UltiSnips Integration: vim-go works automatically with UltiSnips if installed. No additional configuration required.
Build & Run
Development Workflow Commands
Open any .go file to activate vim-go. Use these commands within Vim:
Building and Testing:
:GoBuild " Compile the current package
:GoInstall " Install the current package
:GoTest " Run all tests in the current package
:GoTestFunc " Run the test under the cursor
:GoCoverage " Show test coverage in the editor
Running Code:
:GoRun " Execute the current file
Code Analysis:
:GoDef " Jump to symbol definition
:GoDoc " Show documentation for symbol under cursor
:GoDocBrowser " Open documentation in browser
:GoRename " Rename identifier under cursor
:GoLint " Run golint
:GoVet " Run go vet
:GoErrCheck " Check for unchecked errors
:GoMetaLinter " Run multiple linters
Debugging:
:GoDebugStart " Start debugging with delve
:GoDebugStop " Stop debugging session
Import Management:
:GoImport <path> " Add import
:GoDrop <path> " Remove import
:GoAddTags " Add struct tags (json/xml/etc.)
:GoRemoveTags " Remove struct tags
Testing the Plugin (Contributors)
If modifying vim-go itself, run the test suite:
make
This lints the VimL, validates documentation, and runs tests against multiple Vim/Neovim versions.
Deployment
Team/Enterprise Deployment
Automated Installation Script:
Create install-vim-go.sh for team onboarding:
#!/bin/bash
# Install vim-go for team members
VIM_GO_DIR="$HOME/.vim/pack/plugins/start/vim-go"
# Clone stable release
git clone --depth 1 --branch $(curl -s https://api.github.com/repos/fatih/vim-go/releases/latest | grep tag_name | cut -d '"' -f 4) \
https://github.com/fatih/vim-go.git "$VIM_GO_DIR"
# Install binaries
vim -c 'GoInstallBinaries' -c 'qall'
Docker Development Environment:
Create a Dockerfile for consistent CI/CD environments:
FROM golang:latest
RUN apt-get update && apt-get install -y vim-nox
# Install vim-go
RUN mkdir -p ~/.vim/pack/plugins/start && \
git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go
# Install binaries
RUN vim -T dumb -c 'GoInstallBinaries' -c 'qall' 2>/dev/null
WORKDIR /app
CI/CD Integration
Use vim-go in headless mode for linting in pipelines:
vim -T dumb -c 'GoLint' -c 'qall' ./... 2>/dev/null
Troubleshooting
Common Issues
Binaries Not Found:
If commands like :GoBuild fail with "command not found":
- Ensure
$GOPATH/binor$GOBINis in your system$PATH - Run
:GoInstallBinariesto reinstall tools - Check binary location:
:GoPath
gopls Connection Issues:
- Restart gopls:
:GoLspRestart - Check gopls status:
:GoLspStatus - View gopls log:
:GoLspDebug
Help Documentation Not Loading:
:helptags ~/.vim/pack/plugins/start/vim-go/doc
Or for vim-plug users:
:helptags ~/.vim/plugged/vim-go/doc
Vim Version Errors: vim-go requires Vim 8.2.5072+ or Neovim 0.4.0+. Check your version:
vim --version
nvim --version
Getting Help
- Built-in Documentation:
:help vim-goor:help go-troubleshooting - Pre-populate Bug Report:
:GoReportGitHubIssue(auto-fills environment details) - Check Existing Issues: https://github.com/fatih/vim-go/issues
- Tutorial: https://github.com/fatih/vim-go/wiki/Tutorial
Debug Information
When reporting issues, include output from:
:GoReportGitHubIssue
This automatically collects your Vim version, Go version, and vim-go configuration.