File Type Tabbing

On the Tabbing page in the file type configuration you can specify tab stops and indentation sizes for files of the selected file type.

Tab Characters

Normally, pressing the Tab key on the keyboard inserts a special tab character that has a variable width depending on the column where you insert it. The tab’s width can change if its column changes when you edit the line. Its width can also be different when others view your file with different tab stops.

If you turn on “pressing Tab inserts spaces instead of tab characters” then EditPad Pro inserts the number of spaces until the next tab stop when you press the Tab key.

“Tab size in spaces” is the maximum width of a tab character expressed in an equivalent number of spaces. A typical value is 8 spaces. This puts a tab stop at every 8th column. A tab is then between 1 and 7 spaces wide so that the character after the tab is at the next tab stop. This option also determines the number of spaces that is inserted if you turn on “pressing Tab inserts spaces”.

When you open a file EditPad looks for the first match of the “regular expression to detect tab size” in the first 4 KB of the file. If your files contain some kind of comment to indicate the tab size then you can provide a regex to match this comment and automatically adjust the tab size to that comment. The regex should have a capturing group named “tab”. If this group matches a number between 2 and 32 then that is used as the tab size in spaces. If the group does not match a number but it matches between 2 and 8 characters then the number of characters matched by the group is used as the tab size in spaces. It doesn’t matter what those characters are as long as the group didn’t match an integer number. If the regex also contains a group named “tabspaces” and that group matched some text, then that text overrides the option to make the Tab key insert spaces. If the group “tabspaces” matched “0”, “false”, “tab”, or “no” then the option is turned off. Otherwise it is turned on.

You can also place tab stops at specific columns by entering a comma-delimited list of column numbers. Pressing Tab then makes the cursor jump to the next tab stop column, by inserting either a single tab character or the number of spaces needed to reach the next tab stop (depending on the “pressing Tab inserts spaces” option). After the last specific column tab stops are spaced according to the “tab size in spaces” setting. You can put a + before a number to make that tab stop relative to the previous tab stop. E.g.: 10,+5,+5,37,+7,+12 would be equivalent to 10,15,20,37,44,56.

Elastic Tab Stops

Traditional fixed tab stops, like you can set in EditPad with the above options, make each tab a certain number of spaces wide. This works well when using tabs for indentation. It even works well if others view your file with a different tab size if your file only uses tabs for indentation.

But if you want to use tabs to line up columns, then your columns aren't likely to still line up nicely when somebody else views your file with a different tab size. You could work around this by using spaces. But then you’ll have to use a monospaced font to make sure your spaces and your characters line up correctly.

Elastic tab stops are the solution to neatly lining up columns irrespective of tab size and font spacing. The screen shot shows a source code file using a proportionally spaced font. The file uses tabs for indentation, to line up function parameters (int start and int length) and to line up the /* and */ that delimit comments. Spaces and tabs are visualized. You can clearly see that all the columns are lined up with only a single tab.

The way this works is that when adjacent lines use the same tab stop, that tab stop is moved to the same position on all those lines. That position is the furthest position to the right that is needed to give each tab that uses that tab stop its minimum width on all lines in that block of adjacent lines. For tabs used for indentation, the minimum width is determined by the “tab size in spaces” and the “tab stops at specific columns” settings above. For tabs used in the middle of a line, the minimum width is the “smallest gap between text, in spaces” that you specify.

You can see this in the screen shot. The tabs on lines 1 and 18 use the “smallest gap” size because they are rightmost tabs on lines 1–2 and 18–19. Though the tabs on lines 2 and 19 are indentation tabs, they still use the elastic tab stop that was pushed out further to the right by lines 1 and 18. You can also see that the tab stops on lines 1–2 and on lines 18–19 are not at the same position as the tab stops on any other lines. Because line 3 has no tab stops, the tab stop on lines 1–2 is independent of any other tab stops. The tab stop on lines 18–19 is also independent because lines 17 and 20 have no tabs.

The first tab stop on lines 4 to 14 uses the “tab size in spaces” because that tab stop is only used for indentation on those lines. The second tab stop on lines 4 to 7 is determined by the tab on line 7 as it is the furthest to the right. The second tab stop on lines 10 to 13 is independent of the second tab stop on lines 4 to 7 because lines 8 and 9 have only one tab.

Elastic tab stops are moved immediately as you edit your file. Making some edits is the best way to get the hang of how elastic tab stops work. If you change "someDemoCode" into "editedDemoCode" then you shift the tab on line 1 to the right. This shifts the tab stop to the right. The spacing of the tab on line 2 automatically and immediately adjusts to the new position of the tab stop. If you shorten “doSomethingComplicated” into “doSomethingSimple” then the comments on lines 4 to 7 immediately shift to the left. If you insert “little” into “a bit longer” then you end up shifting the tab on line 7 beyond the tab on line 5. This immediately moves the 3rd tab stop on lines 4 to 6 to line up with the new 3rd tab stop position on line 7. Throughout the edit the 3 */ delimiters continue to be neatly lined up by their tabs.

While elastic tab stops are very flexible, they do have a few limitations. You only get elastic tab stops if you actually use tabs. To be able to line up “int length” with “int start” we need to have a tab before “int start”. If you remove the tabs on lines 1 and 18, then the tabs on lines 2 and 19 no longer have tab stops on adjacent lines. They will revert to the indentation tab size.

Blank lines form a barrier between blocks of lines that use the same number of tab stops. If you need a blank line between two lines of which you want the tab stops to line up then you need to put the same number of tabs on that blank line. The tabs on lines 6 and 23 in the screen shot ensure that the comments on the preceding and following line are aligned. To preserve tabs on otherwise blank lines, you need to turn off the two automatic whitespace trimming options on the Editor page.

You need to use exactly one tab to line up each column. Without elastic tab stops, you would need multiple tabs after “x()” to line up its comment with the comments on the next few lines, as “x()” is several tab widths shorter than “doSomethingComplicated()”. If you enable elastic tab stops when those multiple tabs are present, the comments won’t line up as they won’t use the same tab stops on adjacent lines. If you want to switch from fixed to elastic tab stops and your file may be using tabs in the middle of lines then it’s probably best to use Convert|Tabs|Tabs -> Spaces first to fix the existing layout of the file. As you edit the file you can then use tabs in the middle of lines to line up columns.

Tab-Separated Values

The tab-separated values option also makes tab stops elastic. The key difference is that it lines up all the tab stops on all the lines throughout the file. Blank lines or lines with fewer tabs do not break the alignment. The result is that EditPad lines up your tab-separated values in perfectly aligned columns, no matter how large the file is.

You can make this option line up columns using a different delimiter too. Set “value separator” to the character that should be spaced as if it were a tab. Only a single character can be used. The Comma-Separated.csv file in the screen shot uses a comma as the value separator. The value separator is shown with the same color as visualized tabs and spaces. It is always visible, regardless of whether tabs and spaces are visualized.

If you need to be able to use the value separator within values too, you can specify a quote character and an escape character. For CSV files the quote is usually a straight double quote. The escape is usually a backslash. In the screen shot, the quote is a straight double quote. No escape character is used. As you can see, commas between double quotes are spaced as normal commas. This is how Microsoft Excel saves CSV files.

If you specify a comment character then EditPad ignores the value separator character on lines that have the comment character as their very first character. If such a line doesn’t have any tabs then the length of that line does not affect the width of any of the columns.

Tabs are always spaced as tabs even if you set “value separator” to something else. Tabs cannot be quoted, escaped, or commented out.

Indentation

When you turn on “keep the same level of indentation when pressing Enter”, EditPad automatically puts the same number of spaces and/or tabs at the start of the new line as the previous line starts with. This option can be toggled for individual files with Options|Keep Indent.

The option “automatically indent or outdent new lines based on the syntax coloring scheme” is only enabled if you turn on the preceding option and if the syntax coloring scheme that you select on the Colors & Syntax page provides automatic indention rules. Check it to use those automatic indentation rules. This option can be toggled for individual files with Options|Auto Indent. The help topic for Options|Auto Indent explains how automatic indentation works in detail.

“Indentation size in spaces” is the number of spaces that Block|Indent and Block|Outdent use to indent or outdent the current selection. If the indentation size is the same as the tab size or a multiple of the tab size, and the option to make Tab insert spaces is off, the Indent and Outdent functions use tab characters. The indentation size is also used when automatic indentation needs to increase or decrease the indentation of the new line by one level.

If you edit files from different sources that use different indentation sizes, turn on “detect indentation size of the text surrounding the block to be indented”. If you do so then EditPad counts the amount of indentation of the lines above and below the selection each time you use Block|Indent or Block|Outdent. This also happens when automatic indentation needs to increase or decrease the indentation of the new line by one level.

To detect the indentation size, EditPad counts how many lines are indented by tabs and how many lines are indented by 2 to 8 spaces or a multiple thereof. If more lines are indented by tabs than by any of the multiples of 2 to 8 spaces then the indentation size is a single tab character. Otherwise the indentation size is the most common multiple of spaces that lines are indented with. If your file is consistently uses a tab or between 2 to 8 spaces as the indentation level then EditPad detects this perfectly. If your file uses inconsistent indentation then it uses the most common indentation size. If no lines are indented yet then EditPad uses the indentation size you specified above.