Skip to content

Commit 0c5aaeb

Browse files
refactor: move diff keymaps to LazyVim spec configuration
- Remove hardcoded keymaps from diff.lua - Add diff keymaps to LazyVim specs in README.md and dev-config.lua - Update documentation to reflect LazyVim spec configuration approach - Provide clear examples for customizing diff keymaps - Maintain backward compatibility with default <leader>da and <leader>dq This allows users to easily customize or disable diff keymaps by modifying their LazyVim plugin configuration instead of needing to override hardcoded keymaps. Co-authored-by: ThomasK33 <[email protected]> Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent d52cd61 commit 0c5aaeb

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim):
6161
desc = "Add file",
6262
ft = { "NvimTree", "neo-tree", "oil" },
6363
},
64+
-- Diff management
65+
{ "<leader>da", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
66+
{ "<leader>dq", "<cmd>ClaudeCodeDiffDeny<cr>", desc = "Deny diff" },
6467
},
6568
}
6669
```
@@ -139,7 +142,7 @@ When Claude proposes changes to your files, the plugin opens a native Neovim dif
139142
### Accepting Changes
140143

141144
- **`:w` (save)** - Accept the changes and apply them to your file
142-
- **`<leader>da`** - Accept the changes using the dedicated keymap
145+
- **`<leader>da`** - Accept the changes using the dedicated keymap (configured in LazyVim spec)
143146

144147
You can edit the proposed changes in the right-hand diff buffer before accepting them. This allows you to modify Claude's suggestions or make additional tweaks before applying the final version to your file.
145148

@@ -148,7 +151,7 @@ Both methods signal Claude Code to apply the changes to your file, after which t
148151
### Rejecting Changes
149152

150153
- **`:q` or `:close`** - Close the diff view to reject the changes
151-
- **`<leader>dq`** - Reject changes using the dedicated keymap
154+
- **`<leader>dq`** - Reject changes using the dedicated keymap (configured in LazyVim spec)
152155
- **`:bdelete` or `:bwipeout`** - Delete the diff buffer to reject changes
153156

154157
When you reject changes, the diff view closes and the original file remains unchanged.
@@ -159,12 +162,22 @@ You can also navigate to the Claude Code terminal window and accept or reject di
159162

160163
### Customizing Diff Keymaps
161164

162-
The default keymaps (`<leader>da` and `<leader>dq`) can be customized by remapping them to the underlying commands:
165+
The diff keymaps are configured in the LazyVim spec and can be customized by modifying the `keys` table:
163166

164167
```lua
165-
-- Example: Use different keymaps for diff handling
166-
vim.keymap.set('n', '<leader>ya', '<cmd>ClaudeCodeDiffAccept<cr>', { desc = 'Accept diff' })
167-
vim.keymap.set('n', '<leader>yn', '<cmd>ClaudeCodeDiffDeny<cr>', { desc = 'Deny diff' })
168+
{
169+
"coder/claudecode.nvim",
170+
config = true,
171+
keys = {
172+
-- ... other keymaps ...
173+
174+
-- Customize diff keymaps to avoid conflicts (e.g., with debugger)
175+
{ "<leader>ya", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
176+
{ "<leader>yn", "<cmd>ClaudeCodeDiffDeny<cr>", desc = "Deny diff" },
177+
178+
-- Or disable them entirely by omitting them from the keys table
179+
},
180+
}
168181
```
169182

170183
The commands `ClaudeCodeDiffAccept` and `ClaudeCodeDiffDeny` work only in diff buffers created by the plugin and will show a warning if used elsewhere.

dev-config.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ return {
3131
{ "<leader>ai", "<cmd>ClaudeCodeStatus<cr>", desc = "Claude Status" },
3232
{ "<leader>aS", "<cmd>ClaudeCodeStart<cr>", desc = "Start Claude Server" },
3333
{ "<leader>aQ", "<cmd>ClaudeCodeStop<cr>", desc = "Stop Claude Server" },
34+
35+
-- Diff management (buffer-local, only active in diff buffers)
36+
{ "<leader>da", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
37+
{ "<leader>dq", "<cmd>ClaudeCodeDiffDeny<cr>", desc = "Deny diff" },
3438
},
3539

3640
-- Development configuration - all options shown with defaults commented out

lua/claudecode/diff.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,10 @@ function M._create_diff_view_from_window(target_window, old_file_path, new_buffe
583583
vim.b[new_buffer].claudecode_diff_new_win = new_win
584584
vim.b[new_buffer].claudecode_diff_target_win = target_window
585585

586-
local keymap_opts = { buffer = new_buffer, silent = true }
587-
588-
-- Use the new user commands instead of inline functions
589-
vim.keymap.set("n", "<leader>da", "<cmd>ClaudeCodeDiffAccept<cr>", keymap_opts)
590-
vim.keymap.set("n", "<leader>dq", "<cmd>ClaudeCodeDiffDeny<cr>", keymap_opts)
586+
-- Note: Keymaps for diff accept/deny are now configured in the LazyVim spec
587+
-- Users can customize them by adding to their plugin configuration:
588+
-- { "<leader>da", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff", buffer = true }
589+
-- { "<leader>dq", "<cmd>ClaudeCodeDiffDeny<cr>", desc = "Deny diff", buffer = true }
591590

592591
-- Return window information for later storage
593592
return {

0 commit comments

Comments
 (0)