Accept line by line from autocompletion

4.5k Views Asked by At

I'm using GitHub—Copilot in a VS-Code environment. Given the autocompletion feature, I want to have the possibility to only accept line by line.

For example: The autocomplete shows five lines on TAB, but I just need the first two of them.

Is there a config file or any other possibility to achieve this?

4

There are 4 best solutions below

0
On

The CoPilot extension makes a request to the OpenAI completion API. (see docs for reference: https://api.openai.com/v1/completions )

These settings can be affected by tuning the github.copilot.advanced settings of Copilot.

You could try to increase the limits that are responsible for

github.copilot.advanced": {
    "inlineSuggestCount": 5,
    "length": 700,
    "listCount": 15,
    "stops": {
    }
}

These are the undocumented settings in GitHub Copilot v1.70.8099:

""github.copilot.advanced": {
    "debug.filterLogCategories":[],
    "debug.overrideEngine": "",
    "debug.overrideProxyUrl": "",
    "debug.showScores": false,
    "debug.testOverrideProxyUrl": "",
    "indentationMode": {
        "python": false,
        "javascript": false,
        "javascriptreact": false,
        "jsx": false,
        "typescript": false,
        "typescriptreact": false,
        "go": false,
        "ruby": false,
        "*": true
    },
    "inlineSuggestCount": 3,
    "length": 500,
    "listCount": 10,
    "secret_key": "",
    "stops": {
        "*": [
            "\n\n\n"
        ],
        "python": [
            "\ndef ",
            "\nclass ",
            "\nif ",
            "\n\n#"
        ]
    },
    "temperature":"",
    "top_p": 1
}

Source: Settings in GitHub Copilot v1.70.8099

0
On

Method 1 (Config):

  1. Go to Co-pilot extension settings.

  2. Edit advanced settings

  3. paste this in the settings.json file

  4. You must adjust based on the number of tokens. Try it out a few times to see what works best for you

    "github.copilot.advanced": {
    "length": 500
    }

Method 2 (With Intuition):

This is something I found annoying at times. Upon using it for months, I found that if you want only a line but it is showing you 5-6 lines of autocomplete, you just type something in the current line and it should only autosuggest the line you are on.

for eg, let's say you are trying to make a function that counts prime numbers. Let us say you write a comment and expect it to finish the function. Usually, when you comment, it should show you the whole function at once when you name your function or sometimes even hit enter right after the comment.

But instead, you simply name a variable called prim and it should autocomplete the rest based on its approach. It could be primes = 0 and keep on hitting enter, you should see line-by-line.

TLDR;; If you want it to complete, just "restrict" its predictions by telling it how you want it to look by just trying about your business!

Edit:

As Randolph said in the comments, now you have a setting to do this

0
On

There is "Accept next word" action. Default keybinding: ⌘→

1
On

Yes, this is now possible but not yet enabled by default (at least in January 2024).

To enable line-by-line acceptance of suggestions, you need to create a custom keybinding, e.g. ctrl+shift+right_arrow, and map it to the editor.action.inlineSuggest.acceptNextLine command.

Paste this into the keybindings.json file (which you can find through the omnibox):

{
  "key": "shift+ctrl+right"    
  "command": "editor.action.inlineSuggest.acceptNextLine",
  "when": "inlineSuggestionVisible && !editorReadonly"
}

In this demo I use different keybindings shift+cmd+l for the same action:

enter image description here