How do I set up a debugger with breakpoints in Neovim?
Answer
:lua require'dap'.toggle_breakpoint()
Explanation
The nvim-dap plugin implements the Debug Adapter Protocol in Neovim, providing a full debugging experience with breakpoints, step-through execution, variable inspection, and REPL — all without leaving your editor.
How it works
require'dap'.toggle_breakpoint()— set/remove a breakpoint on the current linerequire'dap'.continue()— start or continue debuggingrequire'dap'.step_over()— step over the current linerequire'dap'.step_into()— step into a function callrequire'dap'.repl.open()— open the debug REPL
Example
" Recommended keybindings
nnoremap <F5> :lua require'dap'.continue()<CR>
nnoremap <F10> :lua require'dap'.step_over()<CR>
nnoremap <F11> :lua require'dap'.step_into()<CR>
nnoremap <leader>b :lua require'dap'.toggle_breakpoint()<CR>
Debugging workflow:
1. Set breakpoint on line 42: <leader>b
2. Start debugging: <F5>
3. Program stops at breakpoint
4. Inspect variables, step through code
5. Continue or step: <F5> or <F10>
Tips
- Install
nvim-dap-uifor a VS Code-like debug panel layout - Use
dap-python,dap-go, etc. for language-specific configurations - Conditional breakpoints:
require'dap'.set_breakpoint(vim.fn.input('Condition: ')) - Log points: breakpoints that print a message without stopping