randomfox: (Default)
[personal profile] randomfox
This Vim macro converts <, >, ", and & into &lt;, &gt;, &quot;, and &amp; respectively. You can use this macro in both normal and visual modes. Its main use so far has been to convert scripts and code for posting to this journal.


" ------------------------------------------------------------------
" Convert text to HTML by escaping <, >, ", and &.
function! HtmlizeText()
    let line = getline(".")
    let line = substitute(line, '&', '\&amp;', 'g')
    let line = substitute(line, '<', '\&lt;', 'g')
    let line = substitute(line, '>', '\&gt;', 'g')
    let line = substitute(line, '"', '\&quot;', 'g')
    call setline(".", line)
endfunction

nmap ,h :call HtmlizeText()<cr>
vmap ,h :call HtmlizeText()<cr>

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

randomfox: (Default)
randomfox

November 2012

S M T W T F S
    123
45678910
11121314151617
18192021222324
25262728 2930 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 14th, 2026 01:43 am
Powered by Dreamwidth Studios