A python script to turn tabs into spaces the right way.
detab turns all tabs into spaces, not just leading tabs.
Not all tabs have the same length, detab replaces each one by the right amount of spaces.
The tab size is configurable, but it defaults to 4 if not specified.
Spaces are the way to go for most programming languages according to coding style rules. Tabs do not measure the same across the whole document as their length varies according to the position of the character in the line. Their size also depends on the configuration of the text editor used, which makes them inconsistent. However, the tab key can be configured to insert spaces instead of tabs on some editors to save time and keystrokes, which is an option I would recommend.
There are some solutions out there to replace tabs with spaces, but they often only take into account leading tabs and replace them with a fixed amount of spaces. detab goes one step further, allowing you to easily make the transition from tabs to spaces over long and complex files and replacing all of them accurately to maintain the original look of the document.
The following commands will download the latest version of detab from this repository and install it in your
git clone https://github.com/Julynx/detab cd detab chmod +x detab sudo cp detab /usr/bin/
The program can now be ran from a terminal with the command
The following command will REPLACE all tabs in the specified file with spaces:
<div class="snippet-clipboard-content position-relative overflow-auto" data-snippet-clipboard-copy-content="detab [tabsize] – Defaults to 4″>
detab [tabsize] - Defaults to 4