Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting spaces to tabs in multiple files Sublime Text 2

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.

like image 475
Sodbileg Gansukh Avatar asked Dec 19 '13 06:12

Sodbileg Gansukh


People also ask

How do you replace tabs with spaces in Sublime Text?

Sublime Text 2 allows you to convert tabs to spaces in existing files manually (View -> Indentation -> Convert indentation to spaces). However, this can be done automatically when saving the file.

What command will easily convert tabs in files to spaces?

The expand command is part of the GNU Core Utilities, which means it is available on just about any Linux system. It's main function is to convert tabs to spaces in a file.

How do I convert all my tabs to spaces?

Instead of changing tabs to spaces one by one, the Word's Find and Replace function is commonly used to convert tabs to spaces. Step 3: Enter a space character (press space button on your keyboard) in the Replace With field; Step 4: Click Replace All.

How do I fix sublime indentations?

by pressing ctrl+f12, it will reindent your file to a tab size of 4. if you want a different tab size, you just change the "value" number.


1 Answers

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})+

like image 179
megawac Avatar answered Nov 13 '22 05:11

megawac