Sep
28th
Mon
28th
[Vim] Trials and errors on EscapeXmlSpecialChars()
- 1. This is not what I want.
-
function EscapeXmlSpecialChars() s/&/\&/eg s/</\</eg s/>/\>/eg s/'/\'/eg s/"/\"/eg endfunction
- 2. This does not work properly.
-
vnoremap <buffer> <LocalLeader>e :call EscapeXmlSpecialChars()<CR> function EscapeXmlSpecialChars() s/\%V&/\&/eg s/\%V</\</eg s/\%V>/\>/eg s/\%V'/\'/eg s/\%V"/\"/eg endfunction
- 3. This looks good :)
-
vnoremap <buffer> <LocalLeader>e "xx:call <SID>EscapeXmlSpecialChars()<CR>"xP function s:EscapeXmlSpecialChars() let @x = substitute(@x, '&', '\&', 'g') let @x = substitute(@x, '<', '\<', 'g') let @x = substitute(@x, '>', '\>', 'g') let @x = substitute(@x, "'", '\'', 'g') let @x = substitute(@x, '"', '\"', 'g') endfunction