Neovim keybinding for LSP "code action" with options

I use neovim and neovim-lsp-config with clangd.

The default keybind for code actions is <space>ca, after pressing which a menu pops up. Usually there is just one option, so having to choose it from the menu feels laborious. Luckily, the documentation states that you can pass a boolean flag apply, so that when there is just one option it is selected automatically.

So I tried to change the keybinding to following:

vim.keymap.set('n', '<space>ca', function()
    vim.lsp.buf.code_action({apply=true}) end, bufopts)

But the behavior does not change - the menu still appears. What am I doing wrong?

Which Neovim version are you using? I’m currently using v0.7.2 and I don’t think my help file has been updated with this commit.

1 Like