zbirenbaum / copilot.lua

Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
MIT License
2.64k stars 75 forks source link

How to do the very basics. #98

Closed Aur0nd closed 1 year ago

Aur0nd commented 1 year ago

Hi there,

I've been trying to figure out the very basics for hours and I've got a point where I'm not sure if I'm missing something or if there's a misconfig with my lunarvim setup.

I'm sure this is going to help a lot of newbies like myself looking for answers.

Q.1: How do you accept the suggestions? I see that in your default settings you're suggesting CR, which I think it's enter? - which doesn't do anything other than newline. Screenshot_20221222_152719

Q.2: :help copilot and a few other options are not working, is this intentional - is there a problem with my packages?

MunifTanjim commented 1 year ago

Q.1: How do you accept the suggestions? I see that in your default settings you're suggesting CR, which I think it's enter? - which doesn't do anything other than newline. Screenshot_20221222_152719

That's for Copilot Panel. Panel is opened by pressing <M-CR> (i.e. Alt+Enter or Option+Enter).

For suggestion keymaps, check suggestion.keymap config (it's commented out in your screenshot).

Q.2: :help copilot and a few other options are not working, is this intentional - is there a problem with my packages?

This plugin doesn't have any helpfile. Check the README.md file on this repo for all the info: https://github.com/zbirenbaum/copilot.lua/blob/master/README.md

Aur0nd commented 1 year ago

Thank you @MunifTanjim ! What I cannot figure out is how the autocompletion works, if I type the resource halfway I can do tab and it will autocomplete (I think that's because of lsp) - I've seen youtube videos pulling this trick but no luck for me ^^

https://youtu.be/FL70Locz6oY?t=259

MunifTanjim commented 1 year ago

Okay, so here's a more complete guide:

  1. Install zbirenbaum/copilot.lua with your plugin manager of choice (vim-plug or packer.nvim or lazy.nvim or something else).

  2. Setup copilot.lua.

require("copilot").setup({
  panel = {
    auto_refresh = false,
    keymap = {
      accept = "<CR>",
      jump_prev = "[[",
      jump_next = "]]",
      refresh = "gr",
      open = "<M-CR>",
    },
  },
  suggestion = {
    auto_trigger = true,
    keymap = {
      accept = "<M-l>",
      prev = "<M-[>",
      next = "<M-]>",
      dismiss = "<C-]>",
    },
  },
})
  1. Restart Neovim.

  2. Run :Copilot auth and complete the authentication process (if it's not done already).

  3. Run :Copilot status to make sure copilot is running and enabled.

  4. Now open a file and start writing codes/comments. Copilot will autmatically show suggestions.

You can accept the suggestion by pressing the suggestion.keymap.accept key (as set in Step 2). Or request the prev/next suggestion by pressing suggestion.keymap.prev/suggestion.keymap.next key (as set in Step 2).

Note: <M-l> means Alt+l (or Option+l for Mac). If for some reason Alt+l does not work on the terminal you're using, try using different keymap in Step 2.


If you want to use <Tab> for accepting suggestion, check the code snippets in this comment: https://github.com/zbirenbaum/copilot.lua/issues/91#issuecomment-1345190310

Aur0nd commented 1 year ago

Bless you @MunifTanjim that actually did the trick man. - Thank you so much!!!! Adding the keymap / Alt+ l works like a charm now.