In Neovim 0.8, I had the following command mapped

vnoremap <leader>a :lua vim.lsp.buf.range_code_action()<cr>

which in visual mode, gave me options such as Wrap In Try-Catch/Extract Method etc.

Now in 0.9 range_code_action no longer exists and https://neovim.io/doc/user/lsp.html#vim.lsp.buf.code_action() says "range: (table|nil) Range for which code actions should be requested. If in visual mode this defaults to the active selection."

I've tried simply changing the mapping to lua vim.lsp.buf.range_code_action() but I'm just getting the basic code actions, not the various Wrap/Extract method etc.

I'm coding Dart.

Any ideas how I a get my range code actions back?

  • 1
    It's possible that it's not triggering the automatic handling of a range from Visual mode because when you use : you're actually switching to command-line mode. Try using <Cmd> to run the :lua command without switching to command-line mode from your mapping, such as vnoremap <leader>a <Cmd>lua vim.lsp.buf.code_action()<cr>. See :help <Cmd> for more details.
    – filbranden
    Mar 15, 2023 at 14:54
  • @filbranden thnx for the suggestion, but still the same
    – pinoyyid
    Mar 15, 2023 at 20:05
  • 1
    @filbranden on regressing to nvim 0.8 and implementing your suggestion, it worked
    – pinoyyid
    Mar 17, 2023 at 18:16

1 Answer 1


Try this: vnoremap <leader>la :lua vim.lsp.buf.code_action()<CR>

Reference: https://github.com/neovim/neovim/pull/19551

  • You probably meant :xnoremap unless NeoVim removed that
    – D. Ben Knoble
    Apr 28, 2023 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.