This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Reformat DocBook paragraphs with Vim


Since monthes (years?) I was compelled tu use the following layout for
my DocBook documents, in order to be able to reformat long paragraphs:

<section>
  <title>Test Section</title>

  <para>This is a very long paragraph. This is a very long paragraph.
  This is a very long paragraph. This is a very long paragraph. This is a
  very long paragraph. This is a very long paragraph. This is a very long
  paragraph. This is a very long paragraph. This is a very long paragraph.
  This is a very long paragraph. This is a very long paragraph.</para>

</section>

Notice the blank lines around the  paragraphs.  With Vim, I used to type
command gqap  to reformat the  paragraphs (ie  wrap long lines  if any).
Today I  wrote a small function  for Vim that detects  the current docbk
syntax and  reformats the paragraphs  correctly even in  situations like
that (without blank lines):

<section>
  <title>Test Section</title>
  <para>This is a very long paragraph. This is a very long paragraph.
  This is a very long paragraph. This is a very long paragraph. This is a
  very long paragraph. This is a very long paragraph. This is a very long
  paragraph. This is a very long paragraph. This is a very long paragraph.
  This is a very long paragraph. This is a very long paragraph.</para>
</section>

Here it is:

imap <C-J> <C-O>:call ReformatParagraph()<cr>
nmap <C-J> :call ReformatParagraph()<cr>
vmap <C-J> gq<cr>

function ReformatParagraph ()
    if &filetype == 'docbk'
        exe "normal! ?<para>^Mv/<\/para>^Mgq"
    else
        normal gqap
    endif
endfunction

Note: ^M must be typed as true return characters using <C-V>

Hope it helps!
-- 
Jean-Baptiste Quenot
http://caraldi.com/jbq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]