0

Hi I am using AstroNvim.

Copilot help give me the following instruction about desired keybindings:

imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
let g:copilot_no_tab_map = v:true

In AstroNvim I have a file mappings.lua, and inside keybindings, but for copilot keybinding don't work.

return {
  n = {
    ["b"] = { "<Plug>Sneak_S", desc = "Sneak back" },
    ["<M-l>"] = { ":wa<CR>", desc = "close all" },
    ["<leader>;"] = { ":vsplit<CR>", desc = "split" },
    ["<S-l>"] = {
      function() require("astronvim.utils.buffer").nav(vim.v.count > 0 and vim.v.count or 1) end,
      desc = "Next buffer",
    },
    ["<S-h>"] = {
      function() require("astronvim.utils.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1)) end,
      desc = "Previous buffer",
    },
  },
  i = {
    ["<C-t"] = { "<cmd>copilot#Accept('<CR>')", desc = "copilot expand", silent = true },
  },
}


-- imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
-- let g:copilot_no_tab_map = v:true

When I type something in code, I see copilot completions, but Ctrl t don't work. Also :verbose <C-t> don't show anything, I don't have this key bonded.

1 Answer 1

1

It seems to me that you miss:

  • The closing > of <C-t>.
  • The escaped backslash \\
  • The script and expr options needs to be set to match the recommendation

I would do:

return {
  n = {
    ["b"] = { "<Plug>Sneak_S", desc = "Sneak back" },
    ["<M-l>"] = { ":wa<CR>", desc = "close all" },
    ["<leader>;"] = { ":vsplit<CR>", desc = "split" },
    ["<S-l>"] = {
      function() require("astronvim.utils.buffer").nav(vim.v.count > 0 and vim.v.count or 1) end,
      desc = "Next buffer",
    },
    ["<S-h>"] = {
      function() require("astronvim.utils.buffer").nav(-(vim.v.count > 0 and vim.v.count or 1)) end,
      desc = "Previous buffer",
    },
  },
  i = {
    ["<C-t>"] = { "copilot#Accept('\\<CR>')", desc = "copilot expand", silent = true, expr = true, script = true },
  },
}

-- imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
-- let g:copilot_no_tab_map = v:true
2
  • 1
    Thanky a lot, my friend, it's working. I'm so happy)))
    – serii
    Apr 22, 2023 at 10:21
  • Thanks for the feedback :-) You are welcome. Apr 22, 2023 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.