I like to do my editing work in Unicode (say UTF-8) and Vim is quite good at this: setting encoding=utf8 does the job. But there are terminals which do not work natively in UTF-8. A good example is the Linux text console: you may set it to Unicode mode, but with a Spanish keymap you won't be able to enter accented characters without reverting to non-Unicode mode. Another example is Xterm, either old Xterms or ones which are not started in UTF-8 mode. My vimrc contains the following snippet which selects a sane value for termencoding in those terminals:

Doing that you set the terminal encoding to utf-8 as well, because I want Vim to always utf-8 internally. That's why the second line says:

set encoding=utf-8

The problem is that setting the "termencoding" to the same value as "encoding" you make Vim believe that the terminal it's running on supports utf-8, and it will output utf-8 sequences to the terminal. If your terminal does not support utf-8 (i.e: aterm, Linux and OpenBSD virtual terminals, xterm without -u8, and so on) you will see weird characters. So I detect wether Xterm is in unicode mode with "xprop" and set "termencoding" to "latin1" for terminals which do not support unicode. Note that this keeps Vim working internally in utf-8, which is a Good Thing, IMHO.

These are some good heuristics, but I think the better place for them is in your shell startup script (e.g. ~/.bashrc or similar). That way you can guarantee that your $LANG environment variable is correct for all your applications, and then you can rely on it in your vimrc.