golang: debugging application in neovim


The plugin is a capable Vim graphical debugger for multiple languages


DAP (Debug Adapter Protocol)

nvim-dap is a Debug Adapter Protocol client implementation for Neovim (>= 0.5). nvim-dap allows you to:

  • Launch an application to debug
  • Attach to running applications and debug them
  • Set breakpoints and step through code
  • Inspect the state of the application


Delve is a debugger for the Go programming language. The goal of the project is to provide a simple, full featured debugging tool for Go. Delve should be easy to invoke and easy to use. Chances are if you’re using a debugger, things aren’t going your way. With that in mind, Delve should stay out of your way as much as possible.

go install github.com/go-delve/delve/cmd/dlv@latest 

Neovim key mapping

let g:vimspector_enable_mappings = 'HUMAN'nmap <leader>vl :call vimspector#Launch()<CR>
nmap <leader>vr :VimspectorReset<CR>
nmap <leader>ve :VimspectorEval
nmap <leader>vw :VimspectorWatch
nmap <leader>vo :VimspectorShowOutput
nmap <leader>vi <Plug>VimspectorBalloonEval
xmap <leader>vi <Plug>VimspectorBalloonEval

" for normal mode - the word under the cursor
nmap <Leader>di <Plug>VimspectorBalloonEval
" for visual mode, the visually selected text
xmap <Leader>di <Plug>VimspectorBalloonEval

let g:vimspector_install_gadgets = [ 'debugpy', 'vscode-go', 'CodeLLDB', 'vscode-node-debug2' ]

Run :VimspectorInstall and the 4 adapters should be installed.

Golang Debugging

Under the project root folder, create a file called .vimspector.json with the following content. Do change the dlvToolPath path accordingly.

  "configurations": {
    "run": {
      "adapter": "vscode-go",
      "configuration": {
        "request": "launch",
        "program": "${fileDirname}",
        "mode": "debug",
        "dlvToolPath": "$HOME/workspace/development/go-lang/bin/dlv"     }

Human Mode

F5When debugging, continue. Otherwise start debugging.vimspector#Continue()
F3Stop debugging.vimspector#Stop()
F4Restart debugging with the same configuration.vimspector#Restart()
F6Pause debuggee.vimspector#Pause()
F9Toggle line breakpoint on the current line.vimspector#ToggleBreakpoint()
<leader>F9Toggle conditional line breakpoint on the current line.vimspector#ToggleBreakpoint( { trigger expr, hit count expr } )
F8Add a function breakpoint for the expression under cursorvimspector#AddFunctionBreakpoint( '<cexpr>' )
<leader>F8Run to Cursorvimspector#RunToCursor()
F10Step Overvimspector#StepOver()
F11Step Intovimspector#StepInto()
F12Step out of current function scopevimspector#StepOut()