Why Typing Deletes the Next Letter in VS Code: Overwrite Mode Explained
Press the Insert key to toggle out of Overwrite mode, which replaces the character at the cursor instead of inserting before it.
The "typing deletes next letter" behavior in VS Code is not caused by the TypeScript compiler or language service. This effect occurs when the editor enters Overwrite (or Overtype) mode, a feature controlled entirely by the editor's settings rather than the microsoft/TypeScript repository logic.
Understanding the "Typing Deletes Next Character" Issue
When your editor behaves as if typing deletes the next character, you are experiencing Overwrite mode. In this state, every keystroke replaces the character immediately following the cursor rather than pushing it forward.
This differs from the default Insert mode, where new characters shift existing text to the right. The confusion often arises because users accidentally trigger this toggle, leading them to suspect a bug in the language service or compiler.
Common Triggers for Overwrite Mode
Three primary factors activate this behavior:
- The Insert Key: Pressing the Insert key (or ⇧ Insert on some keyboards) toggles between Insert and Overwrite modes instantly.
- VS Code Settings: The
editor.overwriteModesetting defaults tofalse, but if enabled, the editor starts in Overwrite mode for every session. - Extensions and Keybindings: Vim extensions or custom keybindings bound to
toggleOverwritecan switch modes automatically when opening files or during specific commands.
How TypeScript Models Text Replacement Operations
While the TypeScript language service never forces an editor into Overwrite mode, the microsoft/TypeScript codebase implements the underlying text replacement logic that editors emulate. The core utility resides in src/services/textChanges.ts, specifically within the replaceRange method at line 565.
This function generates a text change object that deletes a specific range and inserts new content—mathematically identical to an overwrite operation in the editor.
// src/services/textChanges.ts – replace a range with a new node
public replaceRange(
sourceFile: SourceFile,
range: TextRange,
newNode: Node,
options: InsertNodeOptions = {}
): void {
// The underlying edit will delete the characters in `range`
// and then insert the text for `newNode`.
this.replaceRange(sourceFile, getAdjustedRange(sourceFile, oldNode, oldNode, options), newNode, options);
}
When VS Code operates in Overwrite mode, it internally executes a similar operation for each keystroke: deleting the character at the cursor position (range = { pos: cursor, end: cursor + 1 }) and inserting the typed character in its place.
Practical refactors like inline variable demonstrate this mechanism:
// src/services/refactors/inlineVariable.ts
tracker.replaceRangeWithText(
sourceFile,
createRange(startPos, endPos),
newText,
{ prefix: this.newLineCharacter }
);
How to Fix "Typing Deletes Next Letter" in VS Code
Resolve this behavior by returning the editor to Insert mode through the following steps:
-
Press the Insert Key: Tap the Insert key once to toggle back to Insert mode. Observe the status bar at the bottom of VS Code, which displays "INS" when in Insert mode and "OVR" when in Overwrite mode.
-
Check Your Settings: Open Settings (
Ctrl+,), search foreditor.overwriteMode, and ensure the checkbox is unchecked (defaultfalse). This prevents the editor from defaulting to Overwrite mode on startup. -
Review Keybindings: Navigate to Keyboard Shortcuts (
Ctrl+K Ctrl+S) and search fortoggleOverwrite. Remove or reconfigure any custom bindings that might trigger this mode accidentally. -
Audit Extensions: Disable or reconfigure extensions—particularly Vim emulators—that might automatically toggle overwrite mode when opening specific file types. Access this via the Extensions view (
Ctrl+Shift+X).
Key Source Files in the TypeScript Repository
These files from the microsoft/TypeScript repository define the text manipulation logic that parallels editor overwrite operations:
src/services/textChanges.ts: Contains thereplaceRangefunction (line 565) and other utilities that generate replace and insert text edits used by the language service.src/compiler/program.ts: Handles file overwrite checks during compilation, preventing emitted files from clobbering source files (around line 4400).src/services/types.ts: Defines theTextChangeinterface (line 941) that describes single edit operations including insertions, deletions, and replacements.src/server/project.ts: Contains the onTypingInstallerWatchInvoke callback (line 1526), demonstrating where typing-related hooks exist in the TypeScript server, though unrelated to editor overwrite mode.
Summary
- Overwrite mode causes typing to replace the next character rather than insert before it, appearing as if letters are being deleted.
- This is a VS Code editor setting, not a bug in the TypeScript language service or compiler.
- Toggle between modes using the Insert key or configure the
editor.overwriteModesetting tofalse. - The TypeScript codebase implements similar text replacement logic in
src/services/textChanges.tsvia thereplaceRangefunction, which editors mirror during overwrite operations.
Frequently Asked Questions
Why does VS Code delete letters when I type?
VS Code has entered Overwrite mode (also called Overtype mode). In this state, each character you type replaces the character immediately to the right of the cursor. Press the Insert key to toggle back to Insert mode, where typing pushes existing text forward instead of replacing it.
Is "typing deletes next character" a TypeScript bug?
No. This behavior is controlled entirely by the editor, not the TypeScript language service. According to the microsoft/TypeScript source code, the language service only provides text change objects; it never dictates whether the editor operates in Insert or Overwrite mode.
How do I permanently disable Overwrite mode in VS Code?
Open Settings (Ctrl+,), search for editor.overwriteMode, and ensure the value is set to false (unchecked). This prevents VS Code from defaulting to Overwrite mode when opening new files or windows.
Can extensions cause the typing overwrite behavior?
Yes. Vim extensions and other editor enhancements can programmatically toggle overwrite mode. Check your Keyboard Shortcuts for bindings to toggleOverwrite and review your installed extensions—particularly those emulating modal editors—to ensure they are not automatically enabling Overwrite mode on file open.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →