Created
January 26, 2010 19:51
-
Star
(137)
You must be signed in to star a gist -
Fork
(24)
You must be signed in to fork a gist
-
-
Save tpope/287147 to your computer and use it in GitHub Desktop.
This file contains hidden or 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*$' | |
| if exists(':Tabularize') && getline('.') =~# '^\s*|' && (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 |
@namjul it works perfectly. Thanks a lot.
In my case it doesn't works perfectly. The alignmet is correct but every pipe add a space at the start of the row.
For example, the first row is:
| pippo | pluto | paperino |
then I start the second row and hapens this:
␣ | pippo | pluto | paperino |
␣ |*
and when I start second column in the second row another space will be added:
␣ ␣ | pippo | pluto | paperino |
␣ ␣ | one |*
(I used " ␣ " to represent a single space and "*" to represent cursor position at the time)
Anyone could figure why?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@namjul hey thank you so much, worked like a charm.