How to Prevent VS Code from Breaking Up Long HTML Lines into Multiple Lines

How do you stop Prettier in VS code splitting attributes onto multiple lines?

A quick fix is to go to Prettier Extension Settings (ctrl + shift + X) and in Prettier Extension Settings search for "Print Width" set it to 250 or anything that works for you.

1: Go to Extention Settings:

Prettier Extension Settings

2: Change the value of Print Width to your liking.

Changing the value of Print Width

To disable format code on save. Turn off the "Format On Save" and use Alt+Shift+F to format the code when ever you want.

Disable or enable Format On Save

You can visually check the setting here

What is the property name to break long lines in VS Code?

The menu under File > Preferences or press Ctrl+, (on Mac Code > Preferences > Settings or press Command (or Cmd) ⌘+,) provides entries to configure user and workspace settings. You are provided with a list of default Settings.

Set editor.wordWrap: on in your User Settings or Workspace Settings under preference.

Select the below options to change to the desired settings.

  • Off - Lines will never wrap.
  • on - Lines will wrap at the viewport width.
  • wordWrapColumn - Lines will wrap at "Editor: Word Wrap Column".
  • bounded - Lines will wrap at the minimum of viewport and "Editor: Word Wrap Column".

You can toggle word wrap for the VS Code session with Alt+Z (macOS: Option (or Alt) ⌥+Z) or select View > Word Wrap from Menu.

For more about User and Workspace Settings or Key Bindings for Visual Studio Code

How do I prevent Visual Studio Code from breaking long lines when formatting code?

Apparently there's no way of doing this globally. Since I only need this plugin for Javascript, I switched to Beautify altogether and changed the default formatter from Prettier to Beautify with a right click -> "Format Document With" -> "Configure Default Formatter...".

The Beautify plugin seems to keep single line statements as they are.

Q: How to brake one long line of code in VS Code

It's called word wrapping or line breaking.

Select "View > Toggle Word Wrap" from VSCode Menu

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

How to prevent Prettier from breaking test code from 1 line to multiple lines

To prevent Prettier from formatting your code, use this comment before the variable/function/etc.

// prettier-ignore

If you want prettier to ignore multiple lines in Markdown, you can do so as well.

<!-- prettier-ignore-start -->
# Headline

```js
const foo = 'hey';
console.log (foo);
```
<!-- prettier-ignore-end -->

For more information: https://prettier.io/docs/en/ignore.html



Related Topics



Leave a reply



Submit