Skip to content

Instantly share code, notes, and snippets.

@Soft
Created May 24, 2014 16:28
Show Gist options
  • Save Soft/741b7b6c32ceebb4bcb5 to your computer and use it in GitHub Desktop.
Save Soft/741b7b6c32ceebb4bcb5 to your computer and use it in GitHub Desktop.
function! AlignAssignments() range
let l:max = -1
for n in range(a:firstline, a:lastline)
let l:line = getline(n)
let l:pos = match(line, "=")
if pos > max
let l:max = pos
endif
endfor
for n in range(a:firstline, a:lastline)
let l:line = getline(n)
let l:pos = match(line, "=")
if pos > -1
let l:diff = l:max - l:pos
execute "normal! " . n . "gg0" . pos . "li" . repeat(" ", l:diff) . "\<esc>"
endif
endfor
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment