I defined the following function, which works fine when called directly:
function EncloseParagraphs()
execute "normal `>a</p>\<Esc>`<i<p>\<Esc>"
%s/\%V\n\{2,}\%V/<\/p>\r\r<p>/ge
nohl
endfunction
But when I use the following mapping
map <silent> <C-P> :call EncloseParagraphs()<CR>
The results look like this
<p><p><p>This is a paragraph.</p></p></p> <p><p><p>This is a paragraph.</p> </p></p>
In other words, multiple p tags are added when more than one paragraph is selected in visual mode. Why does the function behave differently when called via the mapped shortcut?