VS Code保存后多行内容合并为一行问题求助
Hey there! Let's troubleshoot why your multi-line text is getting squashed into a single line with automatic numbering when you hit Ctrl+S in VS Code. This issue almost always stems from misconfigured auto-formatting settings or an overzealous extension. Here's how to fix it step by step:
1. Disable Suspicious Formatting Extensions
First, let's rule out third-party extensions that might be overriding your formatting:
- Open the Extensions panel with
Ctrl+Shift+X. - Search for extensions related to formatting (like Prettier, ESLint, or any "list formatter" tools).
- Temporarily disable each one, save your file again, and check if the problem goes away.
- If you find the culprit, adjust its settings: either turn off "Format On Save" for that extension, or exclude your file type (e.g., plain text) from its formatting rules.
2. Tweak VS Code's Built-In Formatting Settings
If extensions aren't the issue, check the editor's core settings:
- Open the Settings UI with
Ctrl+,. - Search for Editor: Format On Save and uncheck the box. Save your file to test if the multi-line format stays intact.
- If you still want formatting for other file types but not your current one, create a file-specific rule:
- Open your
settings.jsonfile by pressingCtrl+Shift+Pand selecting "Open Settings (JSON)". - Add this snippet (replace
plaintextwith your file type if needed, likemarkdown):"[plaintext]": { "editor.formatOnSave": false }
- Open your
3. Verify Keyboard Shortcuts
Double-check that Ctrl+S isn't bound to any unexpected commands:
- Open the Keyboard Shortcuts panel with
Ctrl+K Ctrl+S. - Search for "save" and ensure
Ctrl+Sonly maps to thefiles.savecommand. Remove any conflicting bindings if you find them.
4. Check for Auto-List Formatting
Since your saved text is getting numbered (1., 2., 3.), there might be an extension that automatically converts multi-line text into ordered lists. Look for extensions with names like "List Tools" or "Auto List Format" and disable them to test.
Once you've gone through these steps, your multi-line text should stay as-is when you save it in VS Code!
内容的提问来源于stack exchange,提问作者user12456188

