This is the mail archive of the
docbook-apps@lists.oasis-open.org
mailing list .
Reformat DocBook paragraphs with Vim
- From: Jean-Baptiste Quenot <jb dot quenot at caraldi dot com>
- To: docbook-apps <docbook-apps at lists dot oasis-open dot org>
- Date: Fri, 28 Jun 2002 13:11:11 +0200
- Subject: DOCBOOK-APPS: 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/