Skip to content

Plugin seems to hijack <cr> after recent changes #581

@bcyran

Description

@bcyran

Hi,
after recent changes I'm experiencing an issue with <cr> in insert mode. It seems to be mapped to accept a copilot suggestion. If there is no suggestion displayed it just doesn't to anything, i.e. it doesn't go to the next line. If suggestion is displayed, it accepts the suggestion.

I'm using LazyVim and a bunch of plugins so I assume this behavior is a result of some weird interaction between them. Still, I'm using exactly the same combo of plugins for months, if not years, at this point and this issue has appeared only recently. Even if copilot.lua is not at fault, I would appreciate some tips how to fix this.

I bisected recent commits and was able to pin down the commit which introduced the issue: 3ea8f8c.

Here's my plugin config:

Click to expand
  {
    "zbirenbaum/copilot.lua",
    -- FIXME: The next commit breaks <CR>. Unpin when fixed on master.
    commit = "8b9af0c3777f81e9f45059ff41fd1f93f492d9a7",
    enabled = settings.copilot_enabled and not settings.copilot_official,
    cmd = "Copilot",
    event = "InsertEnter",
    keys = {
      {
        "<leader>at",
        function()
          require("copilot.suggestion").toggle_auto_trigger()
        end,
        desc = "Toggle Copilot auto trigger",
      },
    },
    opts = {
      panel = {
        enabled = false,
      },
      suggestion = {
        enabled = true,
        auto_trigger = true,
        keymap = {
          accept = false,
          accept_word = false,
          accept_line = "<C-m>",
          prev = "<C-p>",
          next = "<C-n>",
          dismiss = "<C-e>",
        },
      },
      filetypes = {
        rust = true,
        python = true,
        bash = true,
        lua = true,
        nix = true,
        ["*"] = false,
      },
    },
    init = function()
      -- Define suggestion accept function
      LazyVim.cmp.actions.ai_accept = function()
        if require("copilot.suggestion").is_visible() then
          LazyVim.create_undo()
          require("copilot.suggestion").accept()
          return true
        end
      end

      -- Dismiss copilot suggestion when cmp menu is opened
      local cmp = require("blink.cmp.completion.list")
      cmp.show_emitter:on(function()
        require("copilot.suggestion").dismiss()
        vim.api.nvim_buf_set_var(0, "copilot_suggestion_hidden", true)
      end)
      cmp.hide_emitter:on(function()
        vim.api.nvim_buf_set_var(0, "copilot_suggestion_hidden", false)
      end)
    end,
  },

My full nvim config can be found here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions