Robert Mark Bram wrote:
> fun! EscapeHtmlChars()

Rather than work out what your code is doing, I'll post something I
occasionally use. The following has not had much testing, but seems ok.
It defaults to the current line if nothing is selected, rather than
whole file as you requested (adding '=%' to the -range might fix that).

" Escape/unescape & < > HTML entities in range (default current line).
function! HtmlEntities(line1, line2, action)
  let search = @/
  let range = 'silent ' . a:line1 . ',' . a:line2
  if a:action == 0  " must convert &amp; last
    exe range . 'sno/&lt;/</eg'
    exe range . 'sno/&gt;/>/eg'
    exe range . 'sno/&amp;/&/eg'
  else              " must convert & first
    exe range . 'sno/&/&amp;/eg'
    exe range . 'sno/</&lt;/eg'
    exe range . 'sno/>/&gt;/eg'
  endif
  nohl
  let @/ = search
endfunction
command! -range -nargs=1 Entities call HtmlEntities(<line1>, <line2>,
<args>)
noremap <silent> \h :Entities 0<CR>
noremap <silent> \H :Entities 1<CR>

John


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

Reply via email to