On Wed, December 16, 2009 5:53 pm, epanda wrote:
> It is more complicated, the script should complete empty fields
> between semi colonn only if all previous field of the current line
> are identical to the same position fields of the previous line.
You know, it is kind of hard to help you, if you change your use cases
again and again.
Try this:
,----
| fu! <SID>CSV() range
| if line('$') < 2 | return | endif
| let prevline=split(getline(1), ';', 1)
| let linecount=2
| while linecount <= line ('$')
| let tline=split(getline(linecount), ';', 1)
| let i=0
| let status=0
| while i < (len(tline)<=len(prevline)?len(tline):len(prevline))
| let j=(i==0?0:i-1)
| if empty(tline[i]) && ((tline[0:j] == prevline[0:j]) ||
empty(tline[0]))
| let tline[i]=prevline[i]
| let status=1
| endif
| let i+=1
| endw
| if status
| call setline(linecount, join(tline, ';'))
| endif
|
| let prevline=tline
| let linecount+=1
| endw
| endfu
|
| :com! ReorderCSV :call <SID>CSV()
`----
> DDD_III/CTRL/PT/VERSION;_INSTALL;CSTRING;;;;Commentary
> DDD_AAA/CTRL/PT/VERSION;;;;;;;;;;;;;
> DDD_CCCC/CTRL/PT/VERSION;;;;;;;;;;;;;
> DDD_TTTT/CTRL/PT/VERSION;_INSTALL;CSTRING;;;;;;;;;;;
> DDD_TTTT/CTRL/PT/VERSION;;;ANYTHINGELSE
>
> DDD_III/CTRL/PT/VERSION;_INSTALL;CSTRING;;;;Commentary
> DDD_AAA/CTRL/PT/VERSION;;;;;;;;;;;;;
> DDD_CCCC/CTRL/PT/VERSION;;;;;;;;;;;;;
> DDD_TTTT/CTRL/PT/VERSION;_INSTALL;CSTRING;;;;;;;;;;;
> DDD_TTTT/CTRL/PT/VERSION;_INSTALL;CSTRING;ANYTHINGELSE
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment