lucideuclid
lucideuclid

Reputation: 9

How to break long statements into multiple lines on VS Code?

I want to be able to break up long lines of code for better readability, but every time I save the file, VS Code reformats it back into a single line. I want to retain auto-formatting of code because it makes indentation easy, but this inability to break it up into multiple lines is really beginning to bother me.

I toggled with wrapAttributes and the html.format.wrapLineLength settings to no avail.

How do I preserve/automatically break-up long lines of code?

PS: I use the Prettier extension, but could not identify any setting there that helped with this either.

Upvotes: 0

Views: 11427

Answers (5)

Hari Om
Hari Om

Reputation: 11

VS Code has an auto-wrapping feature that wraps lines at a certain column width. This is useful when you're working with long lines of code or comments.

Press Alt + Z (Windows/Linux) or Option + Z (macOS) to toggle Word Wrap. This will automatically break long lines to fit within the editor window, making them easier to read without changing the code.

Upvotes: 1

Pooya
Pooya

Reputation: 81

As Wulolo said that is the way, if you want to use the shortcut for toggling wordWrap: Alt + Z.

Preview when its On: toggle word wrap preview

Upvotes: 0

HASSAN METWALLY
HASSAN METWALLY

Reputation: 81

1- Opening the settings.

  • For Windows, press Ctrl+,
  • For Mac, press Command (or Cmd) ⌘+,
  • Or click the gear icon on the bottom-left side

2- Search for "line length".

3- Set it to 2000.

Upvotes: 0

Wulolo
Wulolo

Reputation: 1

there is a similar question: What is the property name to break long lines in VS Code?

  1. Opening the settings.

    • For windows, press Ctrl+,
    • For Mac, press Command (or Cmd) ⌘+,
    • Or click the gear icon on the bottom-left side
  2. Search for "word wrap".

  3. Set Editor: Word Wrap on.

Upvotes: 0

Lucas
Lucas

Reputation: 9

In the vscode settings there is the automatic line break option

Add the following to your settings.json file

"editor.wordWrap": "on",

print

Upvotes: 0

Related Questions