Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmdline fallback for <Esc> sometimes invokes the command #547

Closed
2 tasks done
djdv opened this issue Dec 13, 2024 · 5 comments
Closed
2 tasks done

cmdline fallback for <Esc> sometimes invokes the command #547

djdv opened this issue Dec 13, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@djdv
Copy link

djdv commented Dec 13, 2024

Make sure you have done the following

  • I have updated to the latest version of blink.cmp
  • I have read the README

Bug Description

When I define

keymap = { cmdline = { ['<Esc>'] = { 'cancel', 'fallback' } } }

typing :q followed by <Esc><Esc> will invoke :q for some reason.
When 'fallback' isn't used, this doesn't seem to happen but then you can't exit the command-line with Esc.

More detail: https://youtu.be/DBc5DhH0moA

Relevant configuration

keymap = { cmdline = { ['<Esc>'] = { 'cancel', 'fallback' } } }

neovim version

NVIM v0.11.0-dev-1351+gf9dd682621 Build type: Release LuaJIT 2.1.1732813678

blink.cmp version: branch, tag, or commit

97989c8

@djdv djdv added the bug Something isn't working label Dec 13, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

More context: neovim/neovim#21585

Seems like no one knows why it works this way

@djdv
Copy link
Author

djdv commented Dec 13, 2024

Thanks for the info. That describes exactly what's going on here.

Generally speaking, Neovim behaves as if <Esc> was mapped to <CR>, making it very difficult, if not impossible, to have a useful command mode mapping for the escape key (e.g. a conditional mapping such as: close the completion window if it is visible, otherwise abort the cmdline with <Esc> as if it had never been mapped in the first place).

(The command and/or key combinations I prefer tend to be haunted for one legacy reason or another 😆)

@Saghen
Copy link
Owner

Saghen commented Dec 16, 2024

Closing since it seems like there's nothing to do on our side

@Saghen Saghen closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@ad-on-is
Copy link

ad-on-is commented Dec 23, 2024

With a little bit of help from my friend Claude, I was able to solve that.
Hint: you need to set a preset, or other keys won't work, like moving up and down.

 keymap = {
        preset = "super-tab",
        cmdline = {
          preset = "super-tab",
          ["<esc>"] = {
            "cancel",
            function()
              if vim.fn.getcmdtype() ~= "" then
                vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-c>", true, true, true), "n", true)
                return
              end
            end,
          },
        },
      },


@a-usr
Copy link

a-usr commented Jan 15, 2025

slightly better solution that doesnt require a template:

keymap = {
  cmdline = {
    ["<ESC>"] = {
      function(cmp)
        if cmp.is_visible() then
          cmp.cancel()
        else
          vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-c>", true, true, true), "n", true)
        end
      end,
    },
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants