Skip to content

[audit] fix LspAttach gd keymap: remove invalid buf key, use buffer for all nvim versions#150

Merged
stanfish06 merged 1 commit into
masterfrom
audit/lspattach-keymap-opts
Jun 5, 2026
Merged

[audit] fix LspAttach gd keymap: remove invalid buf key, use buffer for all nvim versions#150
stanfish06 merged 1 commit into
masterfrom
audit/lspattach-keymap-opts

Conversation

@stanfish06
Copy link
Copy Markdown
Owner

What

lua/config/plugin_config.lua:115 had a version-guarded opts table for the gd buffer-local keymap that contained a bug on two levels:

-- before
local opts = vim.fn.has('nvim-0.12') == 1 and { buf = ev.buf } or { buffer = ev.buf }
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)

Problem 1 — invalid key buf: vim.keymap.set accepts buffer for a buffer-local keymap, not buf. Passing { buf = ev.buf } is silently ignored, so on nvim-0.12+ gd was registered as a global map rather than buffer-local — it would apply in every buffer regardless of which LSP was attached.

Problem 2 — inverted condition: the branch that returned the wrong key (buf) was guarded by has('nvim-0.12') == 1, i.e. the newest code path was also the broken one.

Where

lua/config/plugin_config.lua, lines 115–116 (inside the LspAttach autocmd callback).

Fix

-- after
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = ev.buf })

buffer is the correct, documented key for buffer-local keymaps in vim.keymap.set and has been so since Neovim 0.7. The version check is unnecessary and removed.

Risk

Low — this restores the intended behaviour (buffer-local gd). The only visible change is that gd no longer leaks into buffers that have no LSP attached.


Generated by Claude Code

On nvim-0.12+, the version check used { buf = ev.buf } which is not a
valid key for vim.keymap.set; the recognised option is `buffer`. This
made gd a global map on 0.12+ instead of buffer-local. The condition was
also logically reversed (new version got the wrong key, old got correct).

Simplify to { buffer = ev.buf } which is valid on all supported versions.
@stanfish06 stanfish06 merged commit cb4006c into master Jun 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant