If you add this code to your vimrc, you can escape visually-selected HTML by typing \h, and unescape by typing \H (assuming the default backslash leader key).

Automagic escaping

A script is available (unicodeswitch) that automagically converts entities when files are read and written, so you can view the characters, and write the codes, or vice versa. It was originally written for Java unicodes, but there is also a setting for HTML codes.

The script is for &nnn style encoding, not the HTML entities.

Perl HTML::Entities

Note: Vim needs to compiled with the "perl" feature enabled for this to work.

A slightly more complex solution that escapes all characters uses Perl. You need Perl and HTML-Parser.

Language specific HTML-entities

To change, for example, Norwegian special characters, there is no need to select text and not check all the text since it is never part of code-syntax. With the following, typing ,r will check all the text and replace all three Norwegian special characters with entities. This can easily be applied to other languages.