Saghen / blink.cmp

Performant, batteries-included completion plugin for Neovim
MIT License
1.3k stars 74 forks source link

Having trouble setting up enter as accept key #20

Closed giuxtaposition closed 1 month ago

giuxtaposition commented 1 month ago

As per title, I'd like to accept the suggestion after pressing enter, but it's not working. Here's my config:

return {
  "saghen/blink.cmp",
  lazy = false, -- lazy loading handled internally
  dependencies = "rafamadriz/friendly-snippets",
  version = "v0.*",
  opts = {
    keymap = {
      accept = "<CR>",
    },
    highlight = {
      use_nvim_cmp_as_default = true,
    },
    nerd_font_variant = "mono",
    accept = { auto_brackets = { enabled = true } },
    trigger = { signature_help = { enabled = true } },
  },
}

I've also tried <cr> and <Enter> but nothing seems to work

nikbrunner commented 1 month ago

Having the same problem. This is my config:

return {
    "saghen/blink.cmp",
    lazy = false, -- lazy loading handled internally
    dependencies = "rafamadriz/friendly-snippets",
    version = "v0.*",
    opts = {
        keymap = {
            show = "<C-space>",
            hide = "<C-e>",
            accept = "<CR>",
            select_prev = { "<Up>", "<C-j>" },
            select_next = { "<Down>", "<C-k>" },

            show_documentation = {},
            hide_documentation = {},
            scroll_documentation_up = "<C-b>",
            scroll_documentation_down = "<C-f>",

            snippet_forward = "<Tab>",
            snippet_backward = "<S-Tab>",
        },
    },
}
giuxtaposition commented 1 month ago

I found the problem, I have nvim-autopairs that uses enter to register pairs, I guess the two mappings get in conflict. My workaround was to set map_cr = false in nvim-autopairs config:

return {
  "windwp/nvim-autopairs",
  event = "InsertEnter",
  config = true,
  opts = {
    disablee_in_macro = false,
    map_cr = false,
  },
}
dsully commented 1 month ago

The same problem occurs with mini.pairs

formadi commented 1 month ago

I don’t use mini.pairs, and I checked the mappings, but there’s nothing mapped for in insert mode, yet does not function as accept.

julienvincent commented 1 month ago

Same issue.

I'm also using nvim-autopairs and can confirm that setting map_cr = false resolves this but I use the behaviour that map_cr = true enables.

Ideally blink can work alongside this config, perhaps can take a look at what nvim-cmp is doing to work here.

chrisgrieser commented 1 month ago

same thing happening with ultimate-autopair (another auto-pairing plugin), which also maps CR.

gcanat commented 1 month ago

Btw, am I the only one to find weird that <C-j> is bounded to go <Up> in the selection and <C-k> to go <Down> ?? Feels counter intuitive.

Ah nevermind, I just saw there is already https://github.com/Saghen/blink.cmp/pull/23

julienvincent commented 1 month ago

@Saghen The commit ecb3510 breaks normal editing in a buffer:

image

It inserts this when pressing keys in insert mode

Saghen commented 1 month ago

I'm not able to reproduce but does https://github.com/Saghen/blink.cmp/commit/5dd7d667228e3a98d01146db7c4461f42644d0c1 fix the issue for you?

julienvincent commented 1 month ago

Almost. It solved the issue reported above but now when accepting it nukes the first char:

image

Notice the missing bracket.

I typed:

(group-|)
;; Press <Cr>
group-by|)
julienvincent commented 1 month ago

Hmm actually, @Saghen that seems to be a different issue that existing before I just didn't notice.

It works if I do this:

 (group-|)
 ;; <Cr>
 (group-by|)

;; However, without the space it fails
(group-|)
;; <Cr>
group-by|)

I could open a new issue if you like.

Saghen commented 1 month ago

New issue would be great, thanks!

julienvincent commented 1 month ago

But, while https://github.com/Saghen/blink.cmp/issues/20#issuecomment-2400217894 <- this issue is solved - This change did break the map_cr = true behaviour from nvim-autopairs.

So in other words, when I am editing with nvim-autopairs then I expect the following behaviour:

fn main() {|}
// Press <Cr>
fn main() {
  |
}

But now as of 5dd7d667228e3a98d01146db7c4461f42644d0c1 this behaviour is broken. Ideally we can find a way to both allow <Cr> to accept without swallowing existing <Cr> mappings on the buffer.

This behaviour pairing works fine on nvim-cmp so I'm sure it's possible.