VIM Tip 1: Align
November 19th, 2006 aizatto Posted in Misc, vim | Hits: 4685 |
I like having my code aligned properly, for example, the following is not cool. The assignment operator is not aligned properly :(.
LIONS = 1
TIGERS = 2
BEARS = 3
This is what I want, it adds a certain zen to the code.
LIONS = 1
TIGERS = 2
BEARS = 3
Yes you can continually hit the spacebar to align it, but imagine if you have alot of values. That is simply going to waste time, an how about if you add a new variable that stretches the alignment? Definetly not cool.
What you want is the Align plugin. This will cover setting up with the Align plugin with VIM v7. So you’ll also need vimball plugin to install it.
Once you’ve downloaded vimball move it to your vim plugin folder (by default on *nix machines: ~/.vim/plugin)
Example:
mv ~/vimballPlugin.vim ~/.vim/plugin
Next open the Align.vba with vim:
vim ~/Align.vba
It will prompt you to enter the following, and just hit enter:
:so %
And there you have it! The Align plugin has been set up.
For basic starters, select a group of text (using Shift V) and enter:
:Align =
VIM will display it as (because its selecting a range):
:'<,'>Align =
Enjoyed that? :3 I did… You can chose to align it with anything, just replace the equality sign with the desired character. For example in Ruby, one might use ‘=>’ for elements in a Hash. Well there you go for starters. The Align plugin has more functionality so do take a peek around.
Live Chat!









Leave a Reply