Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

copilot.vim allows me to use tab for both accepting Copilot suggestions when they're visible, and for increasing the indentation level of the cursor as per normal when Copilot suggestions aren't visible. Is there a way to achieve the same functionality with copilot.lua?

You must be logged in to vote

You can have super-tab like behavior, e.g.: https://github.com/MunifTanjim/dotfiles/blob/6b5199346f7e96065d5e517e61e2d8768e10770d/private_dot_config/nvim/lua/plugins/cmp.lua#L48-L63

For example:

vim.keymap.set('i', '<Tab>', function()
  if require("copilot.suggestion").is_visible() then
    require("copilot.suggestion").accept()
  else
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Tab>", true, false, true), "n", false)
  end
end, { desc = "Super Tab" })

Replies: 4 comments · 6 replies

Comment options

Strangely enough, binding accept to "<C-i>" lets me use tab for both normal indentation and for accepting Copilot suggestions whenever they're visible, but this doesn't seem to work for other keybindings. Is this expected behaviour? Couldn't find anything about this in the help docs.

You must be logged in to vote
0 replies
Comment options

You can have super-tab like behavior, e.g.: https://github.com/MunifTanjim/dotfiles/blob/6b5199346f7e96065d5e517e61e2d8768e10770d/private_dot_config/nvim/lua/plugins/cmp.lua#L48-L63

For example:

vim.keymap.set('i', '<Tab>', function()
  if require("copilot.suggestion").is_visible() then
    require("copilot.suggestion").accept()
  else
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Tab>", true, false, true), "n", false)
  end
end, { desc = "Super Tab" })
You must be logged in to vote
3 replies
@Roundlay
Comment options

Thank you 🙏

@carmilso
Comment options

Hi! Thanks for the suggestion! Where would you write those lines? I'm not sure if they should be inside a mapping overwrite or inside the copilot.lua config

@MunifTanjim
Comment options

Disable the default accept keymap by doing:

require("copilot").setup({
  -- other options
  suggestion = {
    -- other options
    keymap = {
      -- other keymaps
      accept = false
    }
  }
})

Then add your custom accept keymap anywhere in your config. You can add it right below your require("copilot").setup call.

Answer selected by Roundlay
Comment options

Hey @MunifTanjim I did this, but it still doesn't work can you please help

return {
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    event = "InsertEnter",
    config = function()
      require("copilot").setup({ suggestion = { auto_trigger = true, keymap = { accept = false } } })
      vim.keymap.set("i", "<Tab>", function()
        if require("copilot.suggestion").is_visible() then
          require("copilot.suggestion").accept()
        else
          vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Tab>", true, false, true), "n", false)
        end
      end, { desc = "Super Tab" })
    end,
  },
}
You must be logged in to vote
3 replies
@MunifTanjim
Comment options

What's the output for :imap <Tab>?

@mikkybang
Comment options

Here:
i <Tab> * <Lua 529: ~/.local/share/nvim/lazy/LazyVim/lua/lazyvim/plugins/coding.lua:23>

@MunifTanjim
Comment options

https://github.com/LazyVim/LazyVim/blob/879e29504d43e9f178d967ecc34d482f902e5a91/lua/lazyvim/plugins/coding.lua#L21-L27

LazyVim is overriding your keymap.

Comment options

$XDG_CONFIG_HOME/nvim/lua/plugins/copilot.lua:

return {
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    event = "InsertEnter",
    opts = {
      panel = { enabled = false },
      keymap = { accept = false },
      auto_refresh = true,
      filetypes = {
        yaml = true,
        markdown = true,
        suggestion = { auto_trigger = true },
      },
      vim.keymap.set("i", "<Tab>", function()
        if require("copilot.suggestion").is_visible() then
          require("copilot.suggestion").accept()
        else
          vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Tab>", true, false, true), "n", false)
        end
      end, { desc = "Tab for copilot" }),
    },
  },
}

:imap <Tab> shows "Tab for copilot". But still, I cannot accept using Tab. Any ideas?

Your help is much appreciated.

Matthias

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.