Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I've got multiple cursors along several lines, like this:


How can I automatically push the whitespace at the end of each line out to a flat edge, like this?:

foo    |
barr   |
foobar |
baz    |

(In these examples, | is supposed to be my cursor.)


When you just Tab or Space from the initial arrangement, you get this:

# Useful, but not what I'm looking for
foo    |
barr    |
foobar    |
baz    |

That's useful, but not what I'm looking for. I'm looking for some kind of keyboard shortcut that will let me indent from a ragged multi-cursor insert out to a straight column.

share|improve this question
Does simply inserting a tab or two work? – Darth Android Sep 14 '12 at 19:42
No, but I might be failing to understand. I've edited to clarify my question. – GladstoneKeep Sep 14 '12 at 20:53
Your edit describes what Space does, and to some extent Tab will to if your lines vary by a large amount, but if they're all pretty close then after two tabs your cursors should all be on a tabstop. You might have to do a bit of adjusting to get them all on the same tabstop, but it'll be less than trying to adjust with spaces. – Darth Android Sep 14 '12 at 21:21
It's weird. Pressing Tab at the end of each line indents the ragged multi-cursor insert out to a straight column, but it's not possible to achieve the same effect using regex. I searched for trailing spaces: \s*$ and replaced them with the tab character: \t - but \t does not achieve the same effect as pressing Tab manually. – amiregelz Sep 14 '12 at 22:38
FYI, I posted this as a feature request on Sublime Text 2 request board. – GladstoneKeep Sep 17 '12 at 14:15
up vote 6 down vote accepted

You could use wbond's Sublime Alignment

It may require you to add this to your settings file (Preferences>Package Settings>Alignment>Settings-User:

// The mid-line characters to align in a multi-line selection, changing
// this to an empty array will disable mid-line alignment
"alignment_chars": ["=", "|"],
// If the following character is matched for alignment, insert a space
// before it in the final alignment
"alignment_space_chars": ["=", "|"]

Replace "|" with whatever character you want to align.

Edit: As mtoast has found out, adding "\n" to "alignment_chars" gives the desired effect. Adding the new line character to "alignment_space_chars" is probably not needed and may delete the text. However, with my limited tests I did not see a difference.

Hold control and click at the end of each line. Then press the alignment hotkeys (For linux the default is ctrl + alt + a). You will find that the cursors are lined up with the furthest cursor position.

Edit2: Adding newline to "alignment_space_chars" will delete text if you highlight a block of text and Sublime Alignment can't find something else to align on the line (like a equal sign).

Also, if Sublime Alignment can't find something else to align, adding newline to "alignment_chars" will pad the end of lines with spaces (or tabs depending on your settings) to match longest line highlighted.

share|improve this answer
Wow, great! I installed the Sublime Alignment package, added "\n" (newline) to my "alignment_chars", and got the desired result. (Note: I didn't add it to "alignment_space_chars", which caused the lines to be deleted.) If you'll add that specific suggestion ("n") to your answer, I'll accept. – GladstoneKeep Oct 2 '12 at 17:23
Nice! Very useful package for perfectionists like me :) – amiregelz Oct 4 '12 at 20:52
There's also a similar package: Align Tabular, which is a little more flexible (you're able to align on multiple characters). – d_rail Sep 24 '13 at 21:13
With AlignTab mentioned above by d_rail, remember to escape | by a single `\` – Error Oct 12 '13 at 6:57

You can also do it without an external package, with only slightly more effort.

Add additional spaces after every word, until any cursor is at least past the longest word

foo     |
barr     |
foobar     |
baz     |

Type any character, lets say c

foo     c|
barr     c|
foobar     c|
baz     c|

Press Home, to make the cursors go the beginning of the lines

|foo     c
|barr     c
|foobar     c
|baz     c

Press right arrow, until any cursor is past the longest word

foo    | c
barr   |  c
foobar |    c
baz    | c

Press ctrl+shift+right to select all following whitespace and c, then press delete

foo    |
barr   |
foobar |
baz    |

Note: The c character is there in case you have extra content on the lines. Without it, the ctrl+shift+right would delete the first word of your existing content.

share|improve this answer
This looks twisted at first but it's a neat hack. Good for pasting columns with proper alignment. Next column can be pasted using text pastry plug-in. – Error Feb 26 '14 at 18:05
I've been using this technique for a while but be careful, ctrl+shift+right doesn't treat all characters consistently so it may end up selecting more than just white space. – SpareBytes Jun 12 '15 at 16:37
A really neat trick, I agree. But I just tried it without a character at the end, and used Shift-End Delete and it just worked. Does it work in some cases but not others? – Septagram Sep 1 '15 at 12:54
This is what I always do :) – Jacque Goupil Apr 9 at 21:23
This doesn't work if the c on one line is before the end of the word on another. Which is the problem I'm having right now. Certain lines don't contain enough character to scroll to the right, so when you do it wraps to the next line, leaving this hack as just that. This is a hack, not a useful catch-all replacement. – leetNightshade 22 hours ago

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.