14

This question is analogous to How to keep Visual Studio autocomplete from overwriting the next word, but targeted at Visual Studio Code instead of Visual Studio.

When a completion suggestion is selected from the list, it is inserted, but all characters from the word after the cursor are deleted. (So, nothing happens if there is a whitespace after the cursor. But if autocompletion is triggered while the cursor is placed at the beginning of a word, said word will be deleted).

Is there a way to disable this deletion behavior and get it to add the selected suggestion without deleting text to the right of the caret?

starball
  • 20,030
  • 7
  • 43
  • 238
Ad N
  • 7,930
  • 6
  • 36
  • 80
  • Loosely related: [Difference between "acceptSelectedSuggestion" and "acceptAlternativeSelectedSuggestion" in VSCode keybinding config](/q/75403131) – starball Mar 02 '23 at 02:44

1 Answers1

10

Check your settings.json files (your user settings.json and your workspace .vscode/settings.json).

You probably have a line that says:

"editor.suggest.insertMode": "replace"

You can either delete it to get the default behaviour, which is "insert" instead of "replace", or just change it to "insert".

The setting's description says:

Controls whether words are overwritten when accepting completions. Note that this depends on extensions opting into this feature.

The "insert" value's description says:

Insert suggestion without overwriting text right of the cursor.

The "replace" value's description says:

Insert suggestion and overwrite text right of the cursor.

For some languages, the default might be changed. You can check all default settings by viewing the defaultSettings.json file using the Preferences: Open Default Settings (JSON) command.

To set settings per-language, enclose them in blocks like this (example for C++):

"[cpp]": {
    "editor.suggest.insertMode": "insert"
}
starball
  • 20,030
  • 7
  • 43
  • 238
  • 2
    Thanks for the info. Mine both user and workspace are on "insert" but it's still acting as "replace". Do you have any idea why? – Reza Taba Jun 14 '23 at 22:17
  • 1
    @RezaTaba what language are you using? I just answered a related question about a C# extension bug: https://stackoverflow.com/a/76477336/11107541 – starball Jun 14 '23 at 22:20
  • 4
    @RezaTaba It's a newly introduced bug https://github.com/dotnet/vscode-csharp/issues/5801 – Steve Lillis Jun 15 '23 at 08:57