-
-
Save roman/841327 to your computer and use it in GitHub Desktop.
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> <Bar> <Bar><Esc>:call <SID>align()<CR>a | |
function! s:align() | |
let p = '^\s*|\s.*\s|\s*$' | |
let lineStartsWithPipe = getline('.') =~# '^\s*|' | |
let pipedContentOnPrevLine = getline(line('.')-1) =~# p | |
let pipedContentOnNextLine = getline(line('.')+1) =~# p | |
if exists(':Tabularize') && lineStartsWithPipe && (pipedContentOnPrevLine || pipedContentOnNextLine) | |
" Getting the number of pipes that are on the line | |
" (the column you are standing on) | |
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g')) | |
" Get the length of the lastest word we are standing on | |
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*')) | |
" What is the l1 for? | |
Tabularize/|/l1 | |
" What happens when we don't make this a normal command? | |
normal! 0 | |
" move the cursor to the column and position infered the first time | |
" respecting new whitespaces | |
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment