I tend to align code on equal signs for better readability. From this:
$ = jQuery.sub()
Survey = App.Survey
Sidebar = App.Sidebar
Main = App.Main
I believe this is easily done with the Tabular plugin. Here it is in action.
Select the range in Visual mode (not actually necessary), and do:
:Tabularize /=
The plugin can actually find the correct range on its own often, without needing to select it visually or specify a range to the ex command.
The vim-easy-align plugin does that as well. Here is one of the many examples given:
The best plugin I found so far is Tabular.vim.
Easiest way to install it is by using the Pathogen plugin, and then cloning the Tabular git repository to ~/.vim/bundle/tabular. Full instructions in the Pathogen README.
After it's installed, using it is just a matter of putting your cursor somewhere in the paragraph you want to align and running:
:Tab /=
This isn't the easiest way to do things, but it can be done without any plugins.
V and :s/=/ =/ to insert a bunch of spaces before each equals sign.<< to "unindent" the right hand side of each equation towards the column you selected, then press . repeatedly until the equals signs are lined up in that column.Install tabularize plugin and modify gist by tpope to something like this :
inoremap <silent> : :<Esc>:call <SID>align(':')<CR>a
inoremap <silent> = =<Esc>:call <SID>align('=')<CR>a
function! s:align(aa)
let p = '^.*\s'.a:aa.'\s.*$'
if exists(':Tabularize') && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^'.a:aa.']','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*'.a:aa.':\s*\zs.*'))
exec 'Tabularize/'.a:aa.'/l1'
normal! 0
call search(repeat('[^'.a:aa.']*'.a:aa,column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
For a simple solution that does not involve installing a plugin, just filter through the Unix column command.
Note there are two ways to do this depending on whether your column command supports -o.
GNU column command (Linux etc)
:% ! column -t -s= -o=
That's it.
BSD column command (Mac OS X etc)
Step one, filter through column -t:
:% ! column -t
Step two, remove the padding around the delimiter:
:%s/ = /=/
Initial text is
$ = jQuery.sub()
Survey = App.Survey
Sidebar = App.Sidebar
Main = App.Main
After step one it becomes
$ = jQuery.sub()
Survey = App.Survey
Sidebar = App.Sidebar
Main = App.Main
And after step two
$ = jQuery.sub()
Survey = App.Survey
Sidebar = App.Sidebar
Main = App.Main
Or, if you want to do it in one step:
:% ! column -t | sed 's/ = /=/'
For more info, man column.