Home > OS >  How to remove the empty lines in an html file
How to remove the empty lines in an html file

Time:08-25

In the image below there are empty lines before the head, body and closing /html tags and within the body tag I want to remove. How?

html file with empty lines

CodePudding user response:

  • put cursor at end of line with text
  • press Shift-ArrowRight as many times till cursor at pos 1 selecting all newlines till next text
  • Ctrl Shift L to select all similar parts
  • ArrowRight
  • Backspace as much times as needed
  • Esc to leave multi cursor

CodePudding user response:

According to your screenshot, you can try to reduce the line height to reduce the gaps between two successive lines.

  1. Open Settings
  2. Type Line height in the search bar
  3. Specify your desired line height

And done.

Also you could try reducing your font size which would automatically decrease the line height thus reducing gaps in between successive lines.

Settings section of VS Code editor

CodePudding user response:

Use \n\n* in the Find Widget (Ctrl H) with the regex option (.*) icon enabled, replace with \n. Replace All.

or better change this setting:

// List of tags, comma separated, that should have an extra newline before them. `null` defaults to `"head, body, /html"`.
`HTML > Format: Extra Liners`

In your settings.json:

"html.format.extraLiners": ""  // just leave empty

Now when you format the html file those empty lines above head/body/\html should be removed (select all and Command Palette: Format Selection).

  • Related