I have my source code for copy operators written as follows.
foo = rhs.foo;
foobar = rhs.foobar;
bar = rhs.bar;
toto = rhs.toto;
I\'d like
The other answers here are great, especially @nelstrom's comment for Tabular.vim and his excellent screencast.
But if I were feeling too lazy to install any Vim plugins, yet somehow willing to use Vim macros, I'd use macros.
The algorithm:
For each line,
Add tons of spaces before the symbol =
Go to the column you want to align to
Delete all text up to =, thereby shifting the = into the spot you want.
For your example,
foo = rhs.foo;
foobar = rhs.foobar;
bar = rhs.bar;
toto = rhs.toto;
Position the cursor anywhere on the first line and record the macro for that line by typing, in normal mode:
qa0f=100i 8|dwjq
Which translates to:
qa -- Record a macro in hotkey a0 -- Go to the beginning of the linef= -- Go to the first equals sign100i -- (There's a single space after the i, and the means press escape, don't type "8| -- Go to the 8th column (sorry, you'll have to manually figure out which column to align to)dw -- Delete until the next non-space characterj -- Go to the next lineq -- Stop recording.Then run the macro stored at hotkey a, 3 times (for the 3 remaining lines), by putting the cursor on the second line and pressing:
3@a