Vim Tips Wiki

Reloading a file using a different encoding

1,612pages on
this wiki

Redirected from VimTip690

Tip 690 Printable Monobook Previous Next

created 2004 · complexity basic · author Olivier Mengué · version 6.0

You can reload a file using a different encoding if Vim was not able to detect the correct encoding:

:e ++enc=<encoding>

For example, on Windows in western Europe, the default encoding is latin1. However I often use Vim to edit files that must be encoded using the console codepage which is is usually cp850 or cp437. So I reload the file using this command:

:e ++enc=cp850

If you need to do this often, you can map a key to do it for you:

" Press F12 to switch to UTF-8 encoding
nnoremap <F12> :e ++enc=utf-8<CR>



In order for this tip to work, 'encoding' must be set to some value which allows both charsets to be represented in memory. For instance to UTF-8, which is the default on modern Linux distributions. OTOH, if 'encoding' is set to cp1252, which is the default for Windows in "Western" countries, then however you try you won't be able to see what a file looks like in some incompatible charset like KOI8-R or GB18030. For details, see Working with Unicode. — Tonymec (talk) 15:29, September 13, 2012 (UTC)

Around Wikia's network

Random Wiki