Streamlining execution flow during an active debugging session requires fast,
intuitive keyboard shortcuts. In
commit ca95bed6 to my nvim-config repository, I added four
custom keybindings to make evaluating expressions, managing conditional
breakpoints, and terminating debug sessions much cleaner.
Here is a breakdown of the new additions to lua/plugins/dap.lua.
1. Floating Expression Evaluation (<Leader>de)
Inspecting variables on the fly without switching focus into the DAP UI panels keeps your focus on the code structure:
-- Evaluate the word under the cursor (or selected text in Visual mode) in a float
vim.keymap.set({ "n", "v" }, "<Leader>de", function()
dapui.eval()
end, { desc = "Debug: Evaluate in Float" })
Works seamlessly in both Normal mode (evaluating the word directly under the cursor) and Visual mode (evaluating complex highlighted expressions).
2. Evaluate & Focus Floating Window (<Leader>dE)
Sometimes a simple preview float isn’t enough—you might need to scroll through a large data structure or inspect nested attributes inside the floating window.
-- Double-tap/Focus float: Open and jump cursor straight into the floating window
vim.keymap.set("n", "<Leader>dE", function()
dapui.eval(nil, { enter = true })
end, { desc = "Debug: Evaluate and Focus Float" })
By passing { enter = true } to dapui.eval(), NeoVim immediately shifts
cursor focus into the pop-up float, allowing you to scroll, copy text, or close
it with standard window navigation.
3. Quick Session Termination (<Leader>dq)
To quickly tear down an active debugging session and reset your environment:
-- Terminate the current debugging session
vim.keymap.set("n", "<Leader>dq", function()
dap.terminate()
end, { desc = "Debug: Stop/Terminate Session" })
Mapping dap.terminate() to <Leader>dq (“Debug Quit”) provides an
easy-to-remember exit shortcut once your session finishes.
4. Conditional Breakpoints (<Leader>dB)
Stopping execution inside large loops or recursive algorithms requires conditional breakpoints:
-- Prompt for a condition string and set a conditional breakpoint on the current line
vim.keymap.set("n", "<Leader>dB", function()
dap.set_breakpoint(vim.fn.input("Breakpoint condition: "))
end, { desc = "Debug: Set Conditional Breakpoint" })
Using <Leader>dB prompts directly for a condition string (e.g., i == 42 or
ptr == NULL) and sets a conditional breakpoint without requiring manual GDB
console setup.
Shortcut Summary
| Keymap | Mode | Action | Description |
|---|---|---|---|
<Leader>de |
Normal / Visual | dapui.eval() |
Evaluate word/selection in a floating window |
<Leader>dE |
Normal | dapui.eval(nil, { enter = true }) |
Evaluate expression and jump cursor into float |
<Leader>dq |
Normal | dap.terminate() |
Terminate active debug session |
<Leader>dB |
Normal | dap.set_breakpoint(...) |
Prompt for condition string and set breakpoint |