visual-studio-codeintellisense

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


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?


Solution

  • 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.