Last active
March 18, 2025 01:25
-
-
Save palaniraja/96ab171b015676ef331047b571a5ad9a to your computer and use it in GitHub Desktop.
neovim dap custom keybinding to match lldb pref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- dap custom shortcuts | |
-- https://github.com/mfussenegger/dotfiles/blob/e7abb9a13f8fb3075704ed703dd973ecf3502cc3/vim/.config/nvim/lua/me/dap.lua#L64-L75 | |
return { | |
{ | |
"mfussenegger/nvim-dap", | |
config = function() | |
-- working version | |
local dap = require('dap') | |
local kmOpts = { noremap = true, silent = true } | |
dap.listeners.after.event_initialized['me.dap.keys'] = function() | |
vim.api.nvim_set_keymap("n", "n", "<cmd>lua require'dap'.step_over()<CR>", kmOpts) -- next | |
vim.api.nvim_set_keymap("n", "b", "<cmd>lua require'dap'.toggle_breakpoint()<CR>", kmOpts) -- toggle breakpoint | |
vim.api.nvim_set_keymap("n", "f", "<cmd>lua require'dap'.step_out()<CR>", kmOpts) -- finish/return/step-out | |
vim.api.nvim_set_keymap("n", "si", "<cmd>lua require'dap'.step_into()<CR>", kmOpts) -- step into | |
vim.api.nvim_set_keymap("n", "c", "<cmd>lua require'dap'.continue()<CR>", kmOpts) -- run/continue | |
end | |
local reset_keys = function() | |
-- reset to flash default | |
-- vim.api.nvim_set_keymap('n', 'si', "<cmd>lua require'flash'.treesitter()<CR>", kmOpts) | |
-- vim.api.nvim_set_keymap('n', 'f', "<cmd>lua require'flash'.jump({count=1})<CR>", kmOpts) | |
-- reset to vim default? | |
vim.api.nvim_del_keymap('n', 'n') | |
vim.api.nvim_del_keymap('n', 'b') | |
vim.api.nvim_del_keymap('n', 'f') -- couldn't find a way to reset to flash char | |
vim.api.nvim_del_keymap('n', 'si') | |
vim.api.nvim_del_keymap('n', 'c') | |
end | |
dap.listeners.after.event_terminated['me.dap.keys'] = reset_keys | |
dap.listeners.after.disconnected['me.dap.keys'] = reset_keys | |
-- testing | |
-- local dapui = require("dapui") | |
-- dap.listeners.before.attach.dapui_config = function() | |
-- dapui.open() | |
-- end | |
-- dap.listeners.before.launch.dapui_config = function() | |
-- dapui.open() | |
-- end | |
-- dap.listeners.before.event_terminated.dapui_config = function() | |
-- dap.listeners.after.disconnected['me.dap.keys'] = reset_keys | |
-- end | |
-- dap.listeners.before.event_exited.dapui_config = function() | |
-- dap.listeners.after.disconnected['me.dap.keys'] = reset_keys | |
-- end | |
-- CPP / LLDB adapter - https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#ccrust-via-lldb-vscode | |
dap.adapters.lldb = { | |
type = 'executable', | |
command = '/opt/homebrew/opt/llvm/bin/lldb-dap', -- adjust as needed, must be absolute path | |
name = 'lldb' | |
} | |
dap.configurations.cpp = { | |
{ | |
name = 'Launch', | |
type = 'lldb', | |
request = 'launch', | |
program = function() | |
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') | |
end, | |
cwd = '${workspaceFolder}', | |
stopOnEntry = false, | |
args = {}, | |
}, | |
} | |
end | |
}, | |
-- -- dap-ui customization | |
{ | |
"rcarriga/nvim-dap-ui", | |
config = function( ) | |
local dapui = require('dapui') | |
local dap = require("dap") | |
dap.listeners.before.attach.dapui_config = function() | |
dapui.open() | |
end | |
dap.listeners.before.launch.dapui_config = function() | |
dapui.open() | |
end | |
dap.listeners.before.event_terminated.dapui_config = function() | |
dapui.close() | |
end | |
dap.listeners.before.event_exited.dapui_config = function() | |
dapui.close() | |
end | |
dapui.setup({ | |
layouts = { | |
{ | |
elements = { | |
{ id = "scopes", size = 0.35 }, | |
{ id = "watches", size = 0.20 }, | |
{ id = "stacks", size = 0.35 }, | |
{ id = "breakpoints", size = 0.35 }, | |
{ id = "console", size = 0.1}, | |
}, | |
size = 50, -- Width of the layout | |
position = "right", -- Position of the layout | |
wrap = true, | |
}, | |
{ | |
elements = { | |
{ id = "repl"}, | |
}, | |
size = 15, | |
position = "bottom", | |
} | |
}, | |
-- click on stack to jump to | |
element_mappings = { | |
stacks = { | |
open = {"o", "<LeftMouse>"} | |
}, | |
}, | |
}) | |
end | |
}, | |
-- to save breakpoints | |
{ | |
'daic0r/dap-helper.nvim', | |
dependencies = { "rcarriga/nvim-dap-ui", "mfussenegger/nvim-dap" }, | |
config = function() | |
require("dap-helper").setup() | |
end | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/mfussenegger/dotfiles/blob/e7abb9a13f8fb3075704ed703dd973ecf3502cc3/vim/.config/nvim/lua/me/dap.lua#L64-L75