Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement Super Tab like behavior? #91

Closed
BerkeleyTrue opened this issue Dec 10, 2022 · 3 comments
Closed

How to implement Super Tab like behavior? #91

BerkeleyTrue opened this issue Dec 10, 2022 · 3 comments

Comments

@BerkeleyTrue
Copy link

issue description

If I enable auto_trigger for suggestions, and have my accept keymap set to , when there are no suggestions, tab key does nothing.

expected behavior

I'd expect the tab key to feed tab to the editor when there are no suggestion.

@MunifTanjim
Copy link
Collaborator

For super tab like mapping, disable the built-in mapping:

require("copilot").setup({
  suggestion = {
    accept = false,
  },
})

and define the mapping yourself:

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, {
  silent = true,
})

or if you're using nvim-cmp, you can do something like this:

cmp.setup({
  -- ...
  mapping = {
    -- ...
    ["<Tab>"] = cmp.mapping(function(fallback)
      if require("copilot.suggestion").is_visible() then
        require("copilot.suggestion").accept()
      elseif cmp.visible() then
        cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
      elseif luasnip.expandable() then
        luasnip.expand()
      elseif has_words_before() then
        cmp.complete()
      else
        fallback()
      end
    end, {
      "i",
      "s",
    }),
    -- ...
  },
  -- ...
})

@BerkeleyTrue
Copy link
Author

@MunifTanjim That worked for me.

Should I close this issue?

@MunifTanjim
Copy link
Collaborator

Yep. That is the recommended way of setting up custom keymap behavior.

@MunifTanjim MunifTanjim changed the title Don't swallow accept key when there aren't any suggestions How to implement Super Tab like behavior? Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants