-
-
Save MaienM/1258015 to your computer and use it in GitHub Desktop.
Auto-align on equal signs (=) using Tabularize.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inoremap <silent> = =<Esc>:call <SID>ealign()<CR>a | |
function! s:ealign() | |
let p = '^.*=\s.*$' | |
if exists(':Tabularize') && getline('.') =~# '^.*=' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) | |
let column = strlen(substitute(getline('.')[0:col('.')],'[^=]','','g')) | |
let position = strlen(matchstr(getline('.')[0:col('.')],'.*=\s*\zs.*')) | |
Tabularize/=/l1 | |
normal! 0 | |
call search(repeat('[^=]*=',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) | |
endif | |
endfunction | |
Author
MaienM
commented
Feb 29, 2012
via email
I actually did that (or something similar, with the same effect) to my own
version I'm using. I didn't think to update it here though. Thanks for the
update :)
Edit: Updated the gist to reflect the version I have. This will make it work just with = signs, not => or whatever.
Thanks very much for this - one problem I'm finding is that when it carries out the Tabularize the cursor moves to the beginning of the line. Do you know a way around this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment