Visual Studio Code - 从代码中删除空行 [英] Visual Studio Code - Remove blank lines from code

查看:72
本文介绍了Visual Studio Code - 从代码中删除空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual Studio Code 作为首选的文本编辑器,但遇到了格式方面的问题.我已经从一个文件中复制了代码并粘贴到另一个文件中,但是当我粘贴代码时,VSC 在每行代码之间放置了一个空行.

这是一个相当大的文件,所以我希望有一种方法可以一次识别所有空行并删除它们?

这就是我希望代码的样子:

<h1></h1><p></p>

然而,在粘贴时它现在看起来像这样:

<h1></h1><p></p>

我在网上看过,但找不到任何直接的答案:(

解决方案

按照步骤操作

  1. Ctrl+H(快速替换).
  2. 点击使用正则表达式".
  3. 在查找中指定^$\n"
  4. 点击全部替换".所有空行都将被删除.

I use Visual Studio Code as my preferred text editor and I have ran into a problem with regards to the formatting. I have copied code from one file and pasted into another, however when I have pasted the code VSC has placed a blank line between every line with code.

It is quite a big file so I am hoping there is a way to identify all the blank lines at once and remove them?

This is how I want the code to look:

<div>
  <h1></h1>
  <p></p>
</div>

however, on paste it now looks like this:

<div>

  <h1></h1>

  <p></p>

</div>

I have looked online but have been unable to find any direct answer to this :(

解决方案

Follow the steps

  1. Press Ctrl+H (quick replace).
  2. Click "Use Regular Expressions".
  3. In Find specify "^$\n"
  4. Click "Replace All". All Blank lines will be deleted.

这篇关于Visual Studio Code - 从代码中删除空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆