neoclide/coc.nvim

[Question] Inability to Close Code Action Window Using Custom Key Mapping in nvim

Closed this issue · 3 comments

Description

I'm encountering an issue with closing the code action window opened via a key binding set for coc.nvim. Specifically, I'm using the following mappings to trigger code actions:

local keyset = vim.keymap.setlocal keyset = vim.keymap.set
local opts = {silent = true, nowait = true}
keyset("x", "<leader>a", "<Plug>(coc-codeaction-cursor)<CR>", opts)
keyset("n", "<leader>a", "<Plug>(coc-codeaction-selected)<CR>", opts)

However, I want to close the code action window with a custom key mapping, defined as follows:

vim.keymap.set({
    'n', 'i', 'v', 'c', 'o', 's', 't', 'x'
}, '<M-;>', '<ESC>', { noremap = true, silent = true })

Despite this, the custom <M-;> mapping does not close the window as expected. It seems that <ESC> called by my keymap is not closing the window only pressing ESC directly closes it.

Expected Behavior

The code action window should close when pressing <M-;> after it opens via the mapped a command.

Actual Behavior

The window remains open, and the custom key mapping does not close it as expected.

Environment

  • Nvim version:
NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info
  • Coc version: latest
  • Operating System: Win-11

Any insights or solutions to adjust this behavior would be appreciated.

Yes, only <esc> and <C-c> are supported. No plan to add custom key mapping for now.

this.addKeys(['<esc>', '<C-c>'], () => {
this._onDidClose.fire(-1)
this.dispose()
})

May i ask why?

  1. <esc> is the mostly used key mapping in vim to do quitting/closing, <C-c> is also mostly used in terminal to stop/cancel actions, I think these two are enough
  2. to support custom key mappings we need to add a configuration to addKeys, it's not a complex code, but with relatively low benefits