How to prevent VS Code from deleting the next word characters on IntelliSense auto-completion?
Asked Answered
C

1

20

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?

Clan answered 14/2, 2023 at 13:39 Comment(1)
S
24

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

You may 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"
}

When I look at my defaultSettings.json, for example, CSS, HTML, JSON, C, C++, and related languages have their defaults changed. As for why some extensions set a different default value for that setting, I don't know. You'd need to ask the maintainers of those extensions why they made that choice.

Sartre answered 14/2, 2023 at 16:52 Comment(4)
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?Keble
@RezaTaba what language are you using? I just answered a related question about a C# extension bug: https://mcmap.net/q/663737/-c-suggestions-are-replacing-subsequent-text-in-vs-code-whySartre
@RezaTaba It's a newly introduced bug github.com/dotnet/vscode-csharp/issues/5801Naturalist
Why is "replace" mode preferred by some languages (e.g. C, C++)? I was "forced" to use it for a year and always found it annoying. I wonder, if now I will miss the "replace", after switching to "insert". I don't think so.Cinque

© 2022 - 2024 — McMap. All rights reserved.