Wikia

Vim Tips Wiki

Changes: Reloading a file using a different encoding

Edit

Back to page

(minor cleaning for standard format)
(Comments)
 
Line 32: Line 32:
   
 
==Comments==
 
==Comments==
  +
In order for this tip to work, <tt>'encoding'</tt> 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 <tt>'encoding'</tt> 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]]. — [[User:Tonymec|Tonymec]] ([[User talk:Tonymec|talk]]) 15:29, September 13, 2012 (UTC)

Latest revision as of 15:29, September 13, 2012

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>

ReferencesEdit

CommentsEdit

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