On Wed, July 1, 2009 5:11 am, [email protected] wrote:
> Charlie Kester <[email protected]> [09-07-01 04:50]:
>> On Tue 30 Jun 2009 at 19:31:41 PDT [email protected] wrote:
>> >I want to make from this input (example):
>> >
>> >a d f g h
>> >b c d e f
>> >g h i
>> >a i
>> >b f g j
>> >
>> >this output
>> >
>> >
>> >a d f g h
>> > b c d e f
>> > g h i
>> >a i
>> > b f g j
>> >
>> >
>> >is there any vim script, which does this for me?
>> >I am working under Linux and vim (console).
Interesting problem. Here is my proposal:
,----
| fu! Position(char)
| " lowercase letters
| if ((char2nr(a:char) >= 97) && (char2nr(a:char) <= 122))
| return (char2nr(a:char)-97)*2
| " uppercase letters
| elseif ((char2nr(a:char) >= 65) && (char2nr(a:char) <= 90))
| return (char2nr(a:char)-65)*2
| endif
| return -1
| endfu
|
| fu! Tab()
| let i=repeat(' ', 51)
| let mylist=split(i,'\zs')
| let j=split(getline('.'), '\s')
| for char in j
| let pos=Position(char)
| if pos<0
| call add(mylist, char)
| else
| let mylist[pos]=char
| endif
| endfor
| let i=join(mylist, '')
| let i=substitute(i,'\s\+$','','')
| call setline('.', i)
| endfunction
| com! -range Tabularize :<line1>,<line2>call Tab()
`----
This seems to work with lowercase and uppercase letters in the range of
[a-z] without umlauts or special chars. To make it work, all chars need
to be separated by whitespace as your example shows, if not the line is
ignored. Special chars like digits or umlauts will be silently appended
at the end.
>> What are the constraints?
>>
>> Will the input lines always be pre-sorted, as in your example? I.e.,
>> will you ever have a row like "b d a f"? If so, should the
>> "tabulerization" sort it?
For my proposal, the letters do not need to be presorted. The function
will take care of it.
regards,
Christian
--
:wq!
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---