On Wed, December 16, 2009 5:20 pm, epanda wrote:
> Try only ./g on the second line of this example :
> DDD_III/CTRL/PT/VERSION;_INSTALL;CSTRING;;;;Commentary
> DDD_AAA/CTRL/PT/VERSION;;;;;;;;;;;;;
> DDD_CCCC/CTRL/PT/VERSION;;;;;;;;;;;;;
> DDD_TTTT/CTRL/PT/VERSION;;;;;;;;;;;;;
>
>
> It complete the second line but should not. Causes first item's of the
> splitted line are not the same.

That contradicts a little bit to your previous use case:

,----
| First case
| ____________
| foo1;foo2;foo3;;;;;
| ;foo2;foo3;;;;;
|
| Has to become
| foo1;foo2;foo3;;;;;
| foo1;foo2;foo3;;;;;
`----

But here we go:

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))
        if empty(tline[i]) && ((tline[0] == prevline[0]) || 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()


regards,
Christian
-- 
:wq

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to