On 9/04/11 6:51 PM, Andy Wokula wrote:
Am 16.12.2010 17:21, schrieb Tim Chase:
On 12/16/2010 10:05 AM, Anthony Campbell wrote:
That joins ALL the lines. What I need to do is to have each paragraph as
a contimuous line, so that when I import the file into oowriter it will
be easily editable.

I made this little plugin a while ago which you might find helpful
(appended and attached--just save it in ~/.vim/plugin). Use zJ like an
operator to join paragraphs (e.g. ggzJG). It knows about a few different
kinds of things, e.g. list items that begin with - and a space, and
changing indent levels, and avoids joining such things.

Ben.



joinpara.vim:

vnoremap zJ <Esc>:'<,'>call Joinpara()<CR>
nnoremap zJ :set operatorfunc=Joinparaoperator<CR>g@

func! Joinparaoperator(submode)
  '[,']call Joinpara()
endfunc

func! Joinpara() range
  let oldfold=&foldenable
  set nofoldenable
  let lastline=a:lastline
  call cursor(a:firstline,1)
  while getline(".") == "" && line(".") != line("$")
    normal j
  endwhile
  while line(".") <= lastline && line(".") != line("$")
    " execute "normal vip\<Esc>"
    normal V
    while line(".") != 1 &&
        \ getline(line(".")-1) != "" && getline(".") !~ '^\s*- ' &&
        \ (indent(line(".")-1) == indent(".") ||
        \ (getline(line(".")-1) =~ '^\s*- ' &&
        \ indent(line(".")-1) == indent(".")-2))
      normal k
    endwhile
    normal o
    while line(".") != line("$") &&
        \ getline(line(".")+1) != "" && getline(line(".")+1) !~ '^\s*- ' &&
        \ (indent(line(".")+1) == indent(".") ||
        \ (getline(".") =~ '^\s*- ' &&
        \ indent(line(".")+1) == indent(".")+2))
      normal j
    endwhile
    execute "normal \<Esc>"
    if line("'<") != line("'>")
      let lastline -= line("'>") - line("'<")
      '<,'>join
    endif
    normal 0j
    while getline(".") == "" && line(".") != line("$")
      normal j
    endwhile
  endwhile
  let &foldenable=oldfold
endfunc



vnoremap zJ <Esc>:'<,'>call Joinpara()<CR>
nnoremap zJ :set operatorfunc=Joinparaoperator<CR>g@

func! Joinparaoperator(submode)
  '[,']call Joinpara()
endfunc

func! Joinpara() range
  let oldfold=&foldenable
  set nofoldenable
  let lastline=a:lastline
  call cursor(a:firstline,1)
  while getline(".") == "" && line(".") != line("$")
    normal j
  endwhile
  while line(".") <= lastline && line(".") != line("$")
    " execute "normal vip\<Esc>"
    normal V
    while line(".") != 1 &&
        \ getline(line(".")-1) != "" && getline(".") !~ '^\s*- ' &&
        \ (indent(line(".")-1) == indent(".") ||
        \ (getline(line(".")-1) =~ '^\s*- ' &&
        \ indent(line(".")-1) == indent(".")-2))
      normal k
    endwhile
    normal o
    while line(".") != line("$") &&
        \ getline(line(".")+1) != "" && getline(line(".")+1) !~ '^\s*- ' &&
        \ (indent(line(".")+1) == indent(".") ||
        \ (getline(".") =~ '^\s*- ' &&
        \ indent(line(".")+1) == indent(".")+2))
      normal j
    endwhile
    execute "normal \<Esc>"
    if line("'<") != line("'>")
      let lastline -= line("'>") - line("'<")
      '<,'>join
    endif
    normal 0j
    while getline(".") == "" && line(".") != line("$")
      normal j
    endwhile
  endwhile
  let &foldenable=oldfold
endfunc

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to