Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save yaSebastian/8fb6d89d65923b3ee47c83d4fa92aad9 to your computer and use it in GitHub Desktop.

Select an option

Save yaSebastian/8fb6d89d65923b3ee47c83d4fa92aad9 to your computer and use it in GitHub Desktop.
Visual Studio Code - Reducing frustrations with Copilot Inline Suggestions

Visual Studio Code - Reducing frustrations with Copilot Inline Suggestions

Note

This document is provided under the CC0 1.0 Universal license (Creative Commons Zero).
This license allows anyone to freely use, modify, and distribute the content without requiring attribution, effectively placing it in the public domain.

It is primarily intended for co-workers, friends, and acquaintances.

Table of Contents

Problem, Context

In Visual Studio Code, the suggestion widget interferes with GitHub Copilot’s inline suggestions, leading users to frequently press Escape to access Copilot’s suggestions or disable the suggestion widget entirely, disrupting their workflow and causing frustration.

This issue occurs because pressing Tab defaults to the suggestion widget, sidelining Copilot's functionality.

Note

Simply removing the Tab shortcut for the suggestion widget causes the editor to insert tab characters instead of accepting inline suggestions, making it an ineffective solution.

Solution

This document addresses this conflict by subtly modifying keybindings to prioritize Copilot’s inline suggestions when both features are visible, without compromising the usability of the suggestion widget.

Key changes:

  • Adding !inlineSuggestionVisible to the acceptSelectedSuggestion command prevents the suggestion widget from overriding Copilot suggestions.
  • Remove !suggestWidgetVisible from the editor.action.inlineSuggest.commit command allows Copilot’s suggestions to be accepted even when the suggestion widget is visible.

These refinements retain default behaviors wherever possible, offering a more seamless integration of Copilot and IntelliSense in VS Code.

Detailed Instructions

Caution

  • Backup your current keybindings before making changes.
  • If you've previously modified your keybindings, adjust the following instructions accordingly.
  • Default keybinding values are provided below for reference.

You can modify your keybindings by following these steps:

  1. Press Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (macOS) to open the command palette.
  2. Start typing Preferences: Open Keyboard Shortcuts (JSON) and select it. This opens the keybindings.json file.
  3. Modify the when clauses of corresponding commands as detailed below.

Note

Alternatively, modify keybindings via the UI by pressing Ctrl + K, then Ctrl + S (Windows/Linux) or Cmd + K, then Cmd + S (macOS) to open the Keyboard Shortcuts interface.

tab:

No changes required.

{
  "key": "tab",
  "command": "tab",
  "when": "editorTextFocus && !editorReadonly && !editorTabMovesFocus"
}

acceptSelectedSuggestion:

Add !inlineSuggestionVisible to the when clause.

{
  "key": "tab",
  "command": "acceptSelectedSuggestion",
  "when": "!inlineSuggestionVisible && suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus"
}

Accept Inline Suggestion (editor.action.inlineSuggest.commit):

Remove !suggestWidgetVisible from the when clause.

{
  "key": "tab",
  "command": "editor.action.inlineSuggest.commit",
  "when": "inlineSuggestionHasIndentationLessThanTabSize && inlineSuggestionVisible && !editorHoverFocused && !editorTabMovesFocus || cursorAtInlineEdit && inlineEditIsVisible && !editor.hasSelection && !editorHoverFocused && !editorTabMovesFocus || inlineEditIsVisible && inlineSuggestionHasIndentationLessThanTabSize && inlineSuggestionVisible && !editorHoverFocused && !editorTabMovesFocus || cursorAtInlineEdit && inlineEditIsVisible && inlineSuggestionVisible && !editor.hasSelection && !editorHoverFocused && !editorTabMovesFocus"
}

Fallback (Default Values)

To revert to default keybindings:

  • Right-click the modified keybinding in the UI and select Reset Keybinding.
  • If a keybinding was deleted, search for the command in the Keyboard Shortcuts UI and reset it from there.

Tip

If a command retains another keybinding, use it to quickly add a new keybinding with the original key, allowing you to reset it to the default.

Alternatively, copy the relevant default keybindings below into your keybindings.json file:

tab:

{
  "key": "tab",
  "command": "tab",
  "when": "editorTextFocus && !editorReadonly && !editorTabMovesFocus"
}

acceptSelectedSuggestion:

{
  "key": "tab",
  "command": "acceptSelectedSuggestion",
  "when": "suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus"
}

Accept Inline Suggestion (editor.action.inlineSuggest.commit):

{
  "key": "tab",
  "command": "editor.action.inlineSuggest.commit",
  "when": "inlineSuggestionHasIndentationLessThanTabSize && inlineSuggestionVisible && !editorHoverFocused && !editorTabMovesFocus && !suggestWidgetVisible || cursorAtInlineEdit && inlineEditIsVisible && !editor.hasSelection && !editorHoverFocused && !editorTabMovesFocus && !suggestWidgetVisible || inlineEditIsVisible && inlineSuggestionHasIndentationLessThanTabSize && inlineSuggestionVisible && !editorHoverFocused && !editorTabMovesFocus && !suggestWidgetVisible || cursorAtInlineEdit && inlineEditIsVisible && inlineSuggestionVisible && !editor.hasSelection && !editorHoverFocused && !editorTabMovesFocus && !suggestWidgetVisible"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment