Anyone whose done a decent amount of writing in Docbook will realise that
they seem to spend most of their time typing tags. Constructs like:
<structname>foo</structname>.<structfield>bar</structfield>-><structfield>argh</structfield>
won't be unfamiliar to most:) Sicken by this after 300+ pages of docs I
wrote this bit of vim code to ease the pain. The above nightmare can now
be written like this:
<structname>foo</.<structfield>bar</-><structfield>argh</
just ":so" this piece of code(it hammers the E mark and t reg though):
<--cut sgmltag.vim-->
imap / /<ESC>:call SGMLCheckInput()<CR>a
function! SGMLCheckInput()
let curstr = strpart(getline(line(".")), col(".") - 2, 2)
if match(curstr, "<") == 0
if match(curstr, "/") == 1
call SGMLTagSearch()
endif
endif
endfunction
function! SGMLCheckTag(tag)
if match(a:tag, "/") == -1
return -1
else
return 1
endif
endfunction
function! SGMLSearchBack()
let idx = 1
let init = 1
while idx >= 1
if init == 1
let idx = 0
let init = 0
endif
execute "normal ?<.[-a-zA-Z0-9_]*\r\"ty/>\r"
let idx = idx + SGMLCheckTag(@t)
endwhile
return expand("<cword>")
endfunction
function! SGMLTagSearch()
execute "normal mE"
let tag = SGMLSearchBack()
execute "normal `Ea" . tag . ">\e"
endfunction
<--cut sgmltag.vim-->
You can add it to your vimrc with something like:
autocmd BufRead *.sgml so /usr/share/vim/macros/sgmltag.vim
Martin
--
Bother! said Pooh, as the Tribbles rained down on him.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!