Easily aligning characters after whitespace in vim

Not completely satisfied with Tabular and Align, I've recently built another similar, but simpler plugin called vim-easy-align.

Check out the demo screencast: https://vimeo.com/63506219

For the first case, simply visual-select the lines and enter the command :EasyAlign= to do the trick.

If you have defined a mapping such as,

vnoremap <silent> <Enter> :EasyAlign<cr>

you can do the same with just two keystrokes: Enter and =

The case you mentioned in the comment,

final int foo = 3;
public boolean bar = false;

can be easily aligned using ":EasyAlign*\ " command, or with the aforementioned mapping, Enter, *, and space key, yielding

final  int     foo = 3;
public boolean bar = false;

Without plugins

In this case

foo = 1
fizzbuzz = 2
bar = 3

You can add many spaces with a macro:

0f=10iSPACEESCj

where 10 is an arbitrary number just to add enough space.

Apply the macro M times (for M lines) and get

foo           = 1
fizzbuzz           = 2
bar           = 3

Then remove excessive spaces with a macro that removes all characters till some column N:

0f=d12|j

where 12 is the column number you want to align along and | is a vertical bar (SHIFT + \). Together 12| is a "go to column 12" command.

Repeat for each line and get

foo        = 1
fizzbuzz   = 2
bar        = 3

You can combine the two macros into one:

0f=10iSPACEESCd11|j

Tags:

Vim

Regex

Cursor