Accept GitHub Copilot suggestions line by line
Asked Answered
R

7

31

Is there a shortcut key to complete the first line only?

enter image description here

Here I wanted to autocomplete only the line line-height: 1.2;, but if I press the tab it will insert the whole suggested code including a new class below.

Since this happens a lot, is there a way only to complete the first line/ line by line?

Revolting answered 20/12, 2021 at 21:24 Comment(7)
github.com/github/feedback/discussions/7331Mycorrhiza
You can press ctrl + enter, copilot usually suggest upto 10 solutions at a go, once you click that, you can accept anyone that fit your intent.Brickyard
Switch to IntelliJ, then you can use github.com/cmp-nct/Stewardess CTRL+ALT+D pressed two times and you'll have the first line completed without the garbage below.Rawlins
We have forgotten one very small detail sir. I would understand your request if this was code but this is css so "how is the copilot supposed to read your mind and set the style properties you like, just based on the class name?". It can merely reproduce what it finds on other examples it has been trained on...Instance
android-studio___for mac___ type : add variable___ // val foo : Any? = null___ press tabDelinquent
Tracked here: github.com/orgs/community/discussions/6744Atalee
Similar question: #72228674Atalee
S
9

Since at least January 2024, there is a solution, the editor command "command": "editor.action.inlineSuggest.acceptNextLine",

That is annoying, but the answer to your question seems to be no for the time being. Keep in mind that there are updates to the plugin very frequently, so there's still hope:)

Sobersided answered 28/4, 2022 at 13:48 Comment(0)
W
8

In Visual Studio Code (VSCode), there is a helpful feature that allows you to accept code suggestions word by word not line by line.

For Windows users, you can achieve this by using Ctrl + Right Arrow to accept the next word from the suggestions.

Similarly, for Mac users, the equivalent command would be Cmd + Right Arrow. Please note that I don't personally use a Mac, so it's advisable to verify this shortcut on a Mac system. This method can be particularly useful for enhancing the efficiency of our coding workflow.

Weapon answered 9/1, 2024 at 2:21 Comment(2)
If you might have changed keybindings, you can find out what the right combination is by triggering the "inlineSuggestion panel", by hovering the mouse over the suggestion. This will then show what keys to press to accept the next word.Atalee
For Mac this is the correct instruction.Johst
C
4

Here you can add in your "keybindings.json"

ctrl+shift+p then navigate to keybindings.json file

If want to accept only 1 word

{
    "key": "tab",
    "command": "editor.action.inlineSuggest.acceptNextWord",
    "when": "inlineSuggestionVisible && !editorReadonly"
  },

if wants to accept only one line (first one)

{
    "key": "tab",
    "command": "editor.action.inlineSuggest.acceptNextLine",
    "when": "inlineSuggestionVisible && !editorReadonly"
  },

for whole code accept use

{
    "key": "tab",
    "command": "editor.action.inlineSuggest.commit",
    "when": "textInputFocus && inlineSuggestionVisible && !editorTabMovesFocus"
  },

mostly i assigned like

tab --> will accept one line
ctrl+tab -> accept whole code 
Corfu answered 9/2, 2024 at 11:3 Comment(2)
I confirm this works! Should be the accepted answer.Atalee
In my humble opinion, this is the most intuitive method.Fullgrown
P
1

In case someone uses a JetBrains IDEA: The feature was added in version 1.4.1.3828:

What's new:

  • Support for partial acceptance in the editor
    • You can either accept the first word of a suggestion using Commmand+→ (or Ctrl+→)
    • Or you can accept the first line of a multi-line suggestion using Command+Control+→ (or Ctrl+Alt+→).

But in my case, the shortcuts conflict with my current IntelliJ shortcuts. In this case it seems to give other shortcuts (just go to settings->keymap and search for Copilot: Apply Next Line of Completion to Editor)

Pompei answered 22/11, 2023 at 16:25 Comment(1)
The question is about vscode specificallyAtalee
S
1

There is such a command Accept Next Line Of Inline Suggestion, however it does not seem to be assigned a keyboard shortcut by default.

There is also a Accept Next Word Of Inline Suggestion, for me that was defaulted to Ctrl+RightArrow.

Search for all Inline Suggestion in the Keyboard Shortcuts to see all possibilities.

Soracco answered 7/1, 2024 at 11:41 Comment(0)
R
0

I'm on Jetbrains but same thing, it is extremely frustrating that there is no control over the completions. Right now it's not possible, you need to either take it all or write it yourself as before.

The reason for Github/Microsoft doing that with CoPilot is quite simple: Their #1 marketing strategy is how much more "efficient" their users are. They say 60% of the code is written by CoPilot.

What they do not say or track is that of those 60% users likely delete 95% afterward. In reality accepting a solution only means that you need a fraction of it, often it's wrong redundant and a multiple of what you want. But that would destroy their metrics.

I'd recommend making a bug report to the plugin developer and hope that enough people do it until it's fixed.

The other option is to hack the plugin itself, I looked into that and it can be done. Though I'm not too fond of that approach.

Rawlins answered 17/10, 2022 at 0:22 Comment(1)
It was such a problem, I took 2 days to learn Kotlin, plugin development and wrote Stewardess: github.com/cmp-nct/Stewardess Stewardess completes copilot suggestions word-by-wordRawlins
H
-1

If you're using VSCode, I think it's Alt + \ to toggle inline suggestions, or at least that's what the docs say.Docs

Hellenic answered 28/4, 2022 at 4:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.