Converting spaces to tabs in multiple files Sublime Text 2

Sodbileg Gansukh picture Sodbileg Gansukh · Dec 19, 2013 · Viewed 11.3k times · Source

Is there any way to convert all spaces to tabs, not file by file?

If I open a file and go through View => Indentation => Convert Indentation to Tabs, it only changes this file. I want to convert indentations to tabs in a whole project.

Answer

megawac picture megawac · Dec 19, 2013

Use search and replace in multiple files to convert n spaces to tabs in select files.

First open find in files panel, cmd + shift + f, by default to find and replace in multiple files. Next define a regular expression to match spaces as tabs eg {4} (make sure you set Regular Expressions in the panel) for 4 spaces and replace with \t in desired files. Change {4} to however many spaces are being used for indentation.

As mentioned in comments to match spaces at the start of a line you can use the regexp ^( {4})+