Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change all tabs with whitespaces in IntelliJ for 10K+ classes

How to replace all tab characters in classes by sequences of white-spaces?

Project has 10K+ classes.

Have Community edition IntelliJ, how do I automate this process?

like image 497
Peter Avatar asked Aug 03 '15 14:08

Peter


People also ask

What are smart tabs IntelliJ?

IDEA has a “smart tabs” option that you can turn on: If this check box is selected, IntelliJ IDEA inserts tabs for indentation and reformatting, but fine alignment to a necessary column is done only via spaces. This is done in order to preserve visual representation of the source code, when the Tab Size is changed.

How do I show whitespace in IntelliJ?

To enable this feature in IntelliJ, you must open the Settings dialog ( Ctrl+Alt+S ) and navigate to the Editor | General | Appearance tab. In this tab you need to enable the Show whitespace option. In addition, you can individually enable/disable which whitespaces to show: leading, trailing or inner.


1 Answers

In IntelliJ you can do a find and replace across the entire project by doing ctrl-shift-r, or by going to Edit->Find->Replace In Path, make sure the 'Regular expression' box is ticked, then in the 'Text to find' box enter \\t and the 'replace with' box enter four spaces or whatever you want to replace the tabs with

You could do some magic with find and perl:

find . -name "*.java" -exec perl -i.bak -pe 's/\t/    /g' "{}" \;

This will find all files named something.java within the current directory and its subdirs, then call perl to replace all tabs with four spaces, and create a backup of the file before performing this substitution with the extension.bak

like image 161
beresfordt Avatar answered Sep 18 '22 12:09

beresfordt