Sample Header Ad - 728x90

Script for formatting code into columns

0 votes
3 answers
586 views
Often I have code that I want to align based on similar structure of lines, not just the left-side auto indent. Is there a script out there that can do something like this? Here is an example of what I want to do. Given:
self.colorOfBackground =? colorOfBackground
            self.colorOfLineForTime =? colorOfLineForTime
            self.marginOnBottom =? marginOnBottom
            self.marginOnTop =? marginOnTop
            ...
I want to run a script and align each "column" on a tab so that they are aligned and easier to visually parse:
self.colorOfBackground     =?    colorOfBackground
            self.colorOfLineForTime    =?    colorOfLineForTime
            self.marginOnBottom        =?    marginOnBottom
            self.marginOnTop           =?    marginOnTop
            ...
I am thinking that a Perl or Python or AWK or some other scripting language could do this, but alas I know none of these. Till now I have been using Vim and its regex based substitution capabilities but I still spend most of the time manually spacing out the columns.
Asked by andrewz (153 rep)
Nov 28, 2020, 04:19 AM
Last activity: Nov 28, 2020, 05:26 PM