Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-gomod

vim-gomod shows which Go module dependencies are out of date, directly in the go.mod buffer, and updates them from there.

It works in both Vim and Neovim. It is written in plain Vim script and has no dependencies beyond the editor itself and the go command. Full documentation is in :help gomod.

Screenshot

Requirements

  • Vim 9.0.0214 or newer, built with +textprop, +job and +popupwin, or Neovim 0.9 or newer
  • The go command in $PATH

Installation

Vim, as a package:

git clone https://github.com/gen2brain/vim-gomod ~/.vim/pack/dist/start/vim-gomod
vim -u NONE -c 'helptags ~/.vim/pack/dist/start/vim-gomod/doc' -c q

Neovim, with the built-in plugin manager:

vim.pack.add({ "https://github.com/gen2brain/vim-gomod" })

Usage

Open a go.mod file. The check runs asynchronously and marks every direct requirement.

Press <CR> on a requirement to open the action menu: update that module, pick several from a list, update everything outdated, re-check, or run go mod tidy. In the picker, <Space> toggles the module under the cursor, a toggles all, u updates the selected ones, U updates all, and q cancels.

Updates run one at a time with go get <module>@<version> in the directory of the go.mod being edited, after which the buffer is reloaded and re-checked. A go.mod with unsaved changes is never reloaded.

Commands

Command Description
:GoModCheck Re-check the current buffer
:GoModToggle Show or hide the annotations
:GoModUpdate Open the multi-select update picker
:GoModUpdate {module} Update one module, with completion on the outdated ones
:GoModUpdateAll Update every outdated module
:GoModTidy Run go mod tidy, then reload and re-check

Configuration

Variable Default Description
g:gomod_auto_check 1 Check when a go.mod buffer is opened
g:gomod_check_interval 60 Minutes after which re-entering a buffer re-checks, 0 to disable
g:gomod_include_indirect 0 Also check requirements marked // indirect
g:gomod_virtual_text 1 Draw the annotations
g:gomod_signs 1 Place signs in the sign column
g:gomod_align 1 Line the annotations up in a column
g:gomod_highlight_version 1 Recolor the version of an outdated requirement
g:gomod_tidy_after_update 0 Run go mod tidy after a successful update
g:gomod_tidy_hint 0 Report in the action menu whether the module is tidy
g:gomod_default_mappings 1 Map <CR> in go.mod buffers
g:gomod_icons → ✓ ⚠ ✗ Markers used in the annotations
g:gomod_sign_icons ● ▲ ✗ Markers used in the sign column

To use a different key instead of <CR>:

let g:gomod_default_mappings = 0
autocmd FileType gomod nmap <buffer> <LocalLeader>u <Plug>(gomod-action)

The other targets are <Plug>(gomod-check), <Plug>(gomod-update) and <Plug>(gomod-toggle).

Highlight groups are GoModMajor, GoModMinor, GoModPatch, GoModCurrent, GoModDeprecated and GoModError. Their defaults are set with highlight default, so linking them to your colorscheme's groups overrides them:

highlight link GoModMajor ErrorMsg
highlight link GoModMinor WarningMsg

How it works

The status of every requirement comes from a single go list -m -u -e call, asking only about the modules written in the buffer. Nothing else in the dependency tree is looked at, so the check stays quick on projects with a lot of transitive dependencies, where go list -m -u all has to resolve the whole graph. The call runs in the background, so Vim stays responsive while it works. It only reads, nothing is written to go.mod or go.sum until you choose an update or a tidy.

Limitations

go list -m -u only reports updates within the same major version, so a module at v1.9.0 whose author has published v2 shows as up to date, because v2 lives at a different module path ending in /v2. Requirements rewritten by a replace directive are reported at their original path and version.

License

MIT, see LICENSE.

About

Check and update Go module dependencies from inside Vim

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Contributors

Languages