Yes, in Visual Studio Code (VSCode), you can limit the width of text lines to avoid them extending infinitely and causing horizontal scrolling. This is mainly done by enabling word wrap and optionally setting a maximum wrap column. Here are the key ways to control text width in VSCode:
Enable Word Wrap
- Word wrap makes long lines wrap onto the next line visually, so you don't have to scroll horizontally.
- You can toggle word wrap on/off with the shortcut Alt + Z (Windows/Linux) or Option + Z (Mac).
- Alternatively, go to Settings and search for
Editor: Word Wrap and set it to:
"on" to wrap lines at the viewport width,
"off" to disable wrapping (lines extend infinitely),
"wordWrapColumn" to wrap lines at a specific column number.
Set Word Wrap Column (Limit Line Width)
- To limit the width at which lines wrap, set the
Editor: Word Wrap Column setting.
- For example, setting it to 80 will wrap lines at 80 characters.
- This can be done in your
settings.json file by adding:
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 80
This will wrap lines at 80 characters instead of the viewport width or infinite length[1][3][8].
Visual Rulers for Reference
- You can add vertical rulers as visual guides at specific columns (e.g., 80 or 120) by setting:
"editor.rulers": [80, 120]
This helps you see where the line length limit is visually[3].
Hard Wrapping with Extensions
- VSCode's built-in word wrap is soft wrapping (visual only).
- To hard wrap (insert actual line breaks), you can use extensions like Prettier or Rewrap.
- Prettier can be configured with a
printWidth setting to automatically format lines to a certain length.
- Rewrap allows manual hard wrapping with shortcuts like
Alt + Q[1][8].
Summary Table
| Feature | How to Configure | Effect |
|---|
| Word Wrap | "editor.wordWrap": "on" or toggle Alt+Z | Lines wrap visually to fit window width |
| Word Wrap at Column | "editor.wordWrap": "wordWrapColumn", "editor.wordWrapColumn": 80 | Lines wrap at specified column number |
| Visual Rulers | "editor.rulers": | Shows vertical line as visual guide |
| Hard Wrap (line breaks) | Use Prettier extension with "prettier.printWidth": 80 or Rewrap extension | Inserts actual line breaks at limit |
By enabling word wrap and setting a wrap column, you prevent text from extending infinitely in width and improve readability without horizontal scrolling[1][3][5][6][8].