nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

<cr> mapping breaks abbreviations

Open joshuarubin opened this issue 4 years ago • 11 comments

I don't think this is necessarily related to cmp, but I wanted to report it on the off chance it is or someone here knows how to fix it.

When I use any mapping for <cr>, my abbreviations stop working when using <cr> as the "non-keyword" character. I get this when using the suggested mapping like:

    ['<CR>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Insert,
      select = true,
    }),

but also in my more complicated mapping here.

An example would be to add this to your config:

iabbrev TODO TODO(jawa)

The expected behavior is in an empty document, in INSERT mode, type TODO then <cr>. This should cause the abbreviation to be expanded to TODO(jawa) with the cursor now on the next line.

This doesn't happen when I have the <cr> mapping specified, I just get TODO followed by the newline.

I tried adding vim.fn.feedkeys(t '<c-]><cr>') in my custom mapping function (instead of fallback()), which worked, but broke other things and wasn't something I could keep in place.

Any ideas would be much appreciated.

joshuarubin avatar Aug 27 '21 15:08 joshuarubin

@joshuarubin You can use the following mapping.

cmp.setup {
  ['<CR>'] = cmp.mapping.confirm({ select = false })
}

hrsh7th avatar Aug 27 '21 16:08 hrsh7th

Thank you. I will try that. My config is a bit more complicated (as linked above) though and the section that is broken (in the <cr> mapping, which is a function) looks like this:

        -- fallback to normal <cr>
        -- TODO(jawa) this breaks abbreviations :-(
        fallback()
        vim.fn.feedkeys(t "<plug>Endwise")

so there is no option for me to modify the select param. do you have a suggestion on how I can modify this to fix the abbreviations? this block is only entered if no popup menu is visible and the text is not an expandable snippet. thanks so much!

joshuarubin avatar Aug 27 '21 16:08 joshuarubin

@joshuarubin I think you don't need to call vim.fn.feedkeys(t "<plug>Endwise"). (it will be invoked by fallback()

hrsh7th avatar Aug 27 '21 16:08 hrsh7th

thanks, but I have vim.g.endwise_no_mappings = 1 so that it doesn't create mappings by default. anyway, I don't think that's what's causing the problem.

joshuarubin avatar Aug 27 '21 16:08 joshuarubin

I've understand. But it is too difficult. Thank you for your report. I will investigate it.

hrsh7th avatar Aug 27 '21 16:08 hrsh7th

I've fixed it maybe. Thank you!

hrsh7th avatar Aug 27 '21 16:08 hrsh7th

The fix you put in place breaks Telescope (which is the issue I had when I tried the same thing)

joshuarubin avatar Aug 27 '21 17:08 joshuarubin

https://github.com/neovim/neovim/issues/16854

hrsh7th avatar Feb 02 '22 07:02 hrsh7th

Hm... it seems stil this problem exists.

hrsh7th avatar Feb 02 '22 07:02 hrsh7th

Have you managed to fix this? I'm facing the same problem on my setup and can't figure it out what's going on.

ruan-molinari avatar Jul 25 '23 06:07 ruan-molinari

Also having the exact same issue. Somehow, fallback fails to expand the abbreviation. When replacing the fallback with a custom feedkey sequence the issue is resolved, however, other plugins start to break (fugitive in my came).

BartSte avatar May 09 '24 06:05 BartSte