How to remove trailing whitespace of all files recursively?

前端 未结 15 1950
难免孤独
难免孤独 2020-12-07 06:58

How can you remove all of the trailing whitespace of an entire project? Starting at a root directory, and removing the trailing whitespace from all files in all folders.

15条回答
  •  既然无缘
    2020-12-07 07:54

    I use regular expressions. 4 steps:

    1. Open the root folder in your editor (I use Visual Studio Code).
    2. Tap the Search icon on the left, and enable the regular expression mode.
    3. Enter " +\n" in the Search bar and "\n" in the Replace bar.
    4. Click "Replace All".

    This removes all trailing spaces at the end of each line in all files. And you can exclude some files that don't fit with this need.

提交回复
热议问题