*mbyte.txt* For Vim version 7.1. Last change: 2006 Aug 11 VIM REFERENCE MANUAL by Bram Moolenaar et al. Multi-byte support *multibyte* *multi-byte* *Chinese* *Japanese* *Korean*This is about editing text in languages which have many characters that cannot be represented using one byte (one octet). Examples are Chinese, Japaneseand Korean. Unicode is also covered here. For an introduction to the most common features, see |usr_45.txt| in the usermanual.For changing the language of messages and menus see |mlang.txt|. {not available when compiled without the +multi_byte feature} 1. Getting started |mbyte-first|2. Locale |mbyte-locale|3. Encoding |mbyte-encoding|4. Using a terminal |mbyte-terminal|5. Fonts on X11 |mbyte-fonts-X11|6. Fonts on MS-Windows |mbyte-fonts-MSwin|7. Input on X11 |mbyte-XIM|8. Input on MS-Windows |mbyte-IME|9. Input with a keymap |mbyte-keymap|10. Using UTF-8 |mbyte-utf8|11. Overview of options |mbyte-options| NOTE: This file contains UTF-8 characters. These may show up as strangecharacters or boxes when using another encoding. ==============================================================================1. Getting started *mbyte-first* This is a summary of the multibyte features in Vim. If you are lucky it worksas described and you can start using Vim without much trouble. If somethingdoesn't work you will have to read the rest. Don't be surprised if it takesquite a bit of work and experimenting to make Vim use all the multi-bytefeatures. Unfortunately, every system has its own way to deal with multibytelanguages and it is quite complicated. COMPILING If you already have a compiled Vim program, check if the |+multi_byte| featureis included. The |:version| command can be used for this. If +multi_byte is not included, you should compile Vim with "big" features.You can further tune what features are included. See the INSTALL files in thesource directory. LOCALE First of all, you must make sure your current locale is set correctly. Ifyour system has been installed to use the language, it probably works rightaway. If not, you can often make it work by setting the $LANG environmentvariable in your shell: > setenv LANG ja_JP.EUC Unfortunately, the name of the locale depends on your system. Japanese mightalso be called "ja_JP.EUCjp" or just "ja". To see what is currently used: > :language To change the locale inside Vim use: > :language ja_JP.EUC Vim will give an error message if this doesn't work. This is a good way toexperiment and find the locale name you want to use. But it's always betterto set the locale in the shell, so that it is used right from the start. See |mbyte-locale| for details. ENCODING If your locale works properly, Vim will try to set the 'encoding' optionaccordingly. If this doesn't work you can overrule its value: > :set encoding=utf-8 See |encoding-values| for a list of acceptable values. The result is that all the text that is used inside Vim will be in thisencoding. Not only the text in the buffers, but also in registers, variables,etc. This also means that changing the value of 'encoding' makes the existingtext invalid! The text doesn't change, but it will be displayed wrong. You can edit files in another encoding than what 'encoding' is set to. Vimwill convert the file when you read it and convert it back when you write it.See 'fileencoding', 'fileencodings' and |++enc|. DISPLAY AND FONTS If you are working in a terminal (emulator) you must make sure it accepts thesame encoding as which Vim is working with. If this is not the case, you canuse the 'termencoding' option to make Vim convert text automatically. For the GUI you must select fonts that work with the current 'encoding'. Thisis the difficult part. It depends on the system you are using, the locale anda few other things. See the chapters on fonts: |mbyte-fonts-X11| forX-Windows and |mbyte-fonts-MSwin| for MS-Windows. For GTK+ 2, you can skip most of this section. The option 'guifontset' doesno longer exist. You only need to set 'guifont' and everything should "justwork". If your system comes with Xft2 and fontconfig and the current fontdoes not contain a certain glyph, a different font will be used automaticallyif available. The 'guifontwide' option is still supported but usually you donot need to set it. It is only necessary if the automatic font selection doesnot suit your needs. For X11 you can set the 'guifontset' option to a list of fonts that togethercover the characters that are used. Example for Korean: > :set guifontset=k12,r12 Alternatively, you can set 'guifont' and 'guifontwide'. 'guifont' is used forthe single-width characters, 'guifontwide' for the double-width characters.Thus the 'guifontwide' font must be exactly twice as wide as 'guifont'.Example for UTF-8: > :set guifont=-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1 :set guifontwide=-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1 You can also set 'guifont' alone, Vim will try to find a matching'guifontwide' for you. INPUT There are several ways to enter multi-byte characters:- For X11 XIM can be used. See |XIM|.- For MS-Windows IME can be used. See |IME|.- For all systems keymaps can be used. See |mbyte-keymap|. The options 'iminsert', 'imsearch' and 'imcmdline' can be used to chosethe different input methods or disable them temporarily. ==============================================================================2. Locale *mbyte-locale* The easiest setup is when your whole system uses the locale you want to workin. But it's also possible to set the locale for one shell you are workingin, or just use a certain locale inside Vim. WHAT IS A LOCALE? *locale* There are many of languages in the world. And there are different culturesand environments at least as much as the number of languages. A linguisticenvironment corresponding to an area is called "locale". This includesinformation about the used language, the charset, collating order for sorting,date format, currency format and so on. For Vim only the language and charsetreally matter. You can only use a locale if your system has support for it. Some systemshave only a few locales, especially in the USA. The language which you wantto use may not be on your system. In that case you might be able to installit as an extra package. Check your system documentation for how to do that. The location in which the locales are installed varies from system to system.For example, "/usr/share/locale" or "/usr/lib/locale". See your system'ssetlocale() man page. Looking in these directories will show you the exact name of each locale.Mostly upper/lowercase matters, thus "ja_JP.EUC" and "ja_jp.euc" aredifferent. Some systems have a locale.alias file, which allows translationfrom a short name like "nl" to the full name "nl_NL.ISO_8859-1". Note that X-windows has its own locale stuff. And unfortunately uses localenames different from what is used elsewhere. This is confusing! For Vim itmatters what the setlocale() function uses, which is generally NOT theX-windows stuff. You might have to do some experiments to find out whatreally works. *locale-name*The (simplified) format of |locale| name is: languageor language_territoryor language_territory.codeset Territory means the country (or part of it), codeset means the |charset|. Forexample, the locale name "ja_JP.eucJP" means: ja the language is Japanese JP the country is Japan eucJP the codeset is EUC-JPBut it also could be "ja", "ja_JP.EUC", "ja_JP.ujis", etc. And unfortunately,the locale name for a specific language, territory and codeset is not unifiedand depends on your system. Examples of locale name: charset language locale name ~ GB2312 Chinese (simplified) zh_CN.EUC, zh_CN.GB2312 Big5 Chinese (traditional) zh_TW.BIG5, zh_TW.Big5 CNS-11643 Chinese (traditional) zh_TW EUC-JP Japanese ja, ja_JP.EUC, ja_JP.ujis, ja_JP.eucJP Shift_JIS Japanese ja_JP.SJIS, ja_JP.Shift_JIS EUC-KR Korean ko, ko_KR.EUC USING A LOCALE To start using a locale for the whole system, see the documentation of yoursystem. Mostly you need to set it in a configuration file in "/etc". To use a locale in a shell, set the $LANG environment value. When you want touse Korean and the |locale| name is "ko", do this: sh: export LANG=ko csh: setenv LANG ko You can put this in your ~/.profile or ~/.cshrc file to always use it. To use a locale in Vim only, use the |:language| command: > :language ko Put this in your ~/.vimrc file to use it always. Or specify $LANG when starting Vim: sh: LANG=ko vim {vim-arguments} csh: env LANG=ko vim {vim-arguments} You could make a small shell script for this. ==============================================================================3. Encoding *mbyte-encoding* Vim uses the 'encoding' option to specify how characters identified andencoded when they are used inside Vim. This applies to all the places wheretext is used, including buffers (files loaded into memory), registers andvariables. *charset* *codeset*Charset is another name for encoding. There are subtle differences, but thesedon't matter when using Vim. "codeset" is another similar name. Each character is encoded as one or more bytes. When all characters areencoded with one byte, we call this a single-byte encoding. The most oftenused one is called "latin1". This limits the number of characters to 256.Some of these are control characters, thus even fewer can be used for text. When some characters use two or more bytes, we call this a multi-byteencoding. This allows using much more than 256 characters, which is requiredfor most East Asian languages. Most multi-byte encodings use one byte for the first 127 characters. Theseare equal to ASCII, which makes it easy to exchange plain-ASCII text, nomatter what language is used. Thus you might see the right text even when theencoding was set wrong. *encoding-names*Vim can use many different character encodings. There are three major groups: 1 8bit Single-byte encodings, 256 different characters. Mostly used in USA and Europe. Example: ISO-8859-1 (Latin1). All characters occupy one screen cell only. 2 2byte Double-byte encodings, over 10000 different characters. Mostly used in Asian countries. Example: euc-kr (Korean) The number of screen cells is equal to the number of bytes (except for euc-jp when the first byte is 0x8e). u Unicode Universal encoding, can replace all others. ISO 10646. Millions of different characters. Example: UTF-8. The relation between bytes and screen cells is complex. Other encodings cannot be used by Vim internally. But files in otherencodings can be edited by using conversion, see 'fileencoding'.Note that all encodings must use ASCII for the characters up to 128 (exceptwhen compiled for EBCDIC). Supported 'encoding' values are: *encoding-values*1 latin1 8-bit characters (ISO 8859-1)1 iso-8859-n ISO_8859 variant (n = 2 to 15)1 koi8-r Russian1 koi8-u Ukrainian1 macroman MacRoman (Macintosh encoding)1 8bit-{name} any 8-bit encoding (Vim specific name)1 cp437 similar to iso-8859-11 cp737 similar to iso-8859-71 cp775 Baltic1 cp850 similar to iso-8859-41 cp852 similar to iso-8859-11 cp855 similar to iso-8859-21 cp857 similar to iso-8859-51 cp860 similar to iso-8859-91 cp861 similar to iso-8859-11 cp862 similar to iso-8859-11 cp863 similar to iso-8859-81 cp865 similar to iso-8859-11 cp866 similar to iso-8859-51 cp869 similar to iso-8859-71 cp874 Thai1 cp1250 Czech, Polish, etc.1 cp1251 Cyrillic1 cp1253 Greek1 cp1254 Turkish1 cp1255 Hebrew1 cp1256 Arabic1 cp1257 Baltic1 cp1258 Vietnamese1 cp{number} MS-Windows: any installed single-byte codepage2 cp932 Japanese (Windows only)2 euc-jp Japanese (Unix only)2 sjis Japanese (Unix only)2 cp949 Korean (Unix and Windows)2 euc-kr Korean (Unix only)2 cp936 simplified Chinese (Windows only)2 euc-cn simplified Chinese (Unix only)2 cp950 traditional Chinese (on Unix alias for big5)2 big5 traditional Chinese (on Windows alias for cp950)2 euc-tw traditional Chinese (Unix only)2 2byte-{name} Unix: any double-byte encoding (Vim specific name)2 cp{number} MS-Windows: any installed double-byte codepageu utf-8 32 bit UTF-8 encoded Unicode (ISO/IEC 10646-1)u ucs-2 16 bit UCS-2 encoded Unicode (ISO/IEC 10646-1)u ucs-2le like ucs-2, little endianu utf-16 ucs-2 extended with double-words for more charactersu utf-16le like utf-16, little endianu ucs-4 32 bit UCS-4 encoded Unicode (ISO/IEC 10646-1)u ucs-4le like ucs-4, little endian The {name} can be any encoding name that your system supports. It is passedto iconv() to convert between the encoding of the file and the current locale.For MS-Windows "cp{number}" means using codepage {number}.Examples: > :set encoding=8bit-cp1252 :set encoding=2byte-cp932<Several aliases can be used, they are translated to one of the names above.An incomplete list: 1 ansi same as latin1 (obsolete, for backward compatibility)2 japan Japanese: on Unix "euc-jp", on MS-Windows cp9322 korea Korean: on Unix "euc-kr", on MS-Windows cp9492 prc simplified Chinese: on Unix "euc-cn", on MS-Windows cp9362 chinese same as "prc"2 taiwan traditional Chinese: on Unix "euc-tw", on MS-Windows cp950u utf8 same as utf-8u unicode same as ucs-2u ucs2be same as ucs-2 (big endian)u ucs-2be same as ucs-2 (big endian)u ucs-4be same as ucs-4 (big endian) default stands for the default value of 'encoding', depends on the environment For the UCS codes the byte order matters. This is tricky, use UTF-8 wheneveryou can. The default is to use big-endian (most significant byte comesfirst): name bytes char ~ ucs-2 11 22 1122 ucs-2le 22 11 1122 ucs-4 11 22 33 44 11223344 ucs-4le 44 33 22 11 11223344 On MS-Windows systems you often want to use "ucs-2le", because it uses littleendian UCS-2. There are a few encodings which are similar, but not exactly the same. Vimtreats them as if they were different encodings, so that conversion will bedone when needed. You might want to use the similar name to avoid conversionor when conversion is not possible: cp932, shift-jis, sjis cp936, euc-cn *encoding-table*Normally 'encoding' is equal to your current locale and 'termencoding' isempty. This means that your keyboard and display work with characters encodedin your current locale, and Vim uses the same characters internally. You can make Vim use characters in a different encoding by setting the'encoding' option to a different value. Since the keyboard and display stilluse the current locale, conversion needs to be done. The 'termencoding' thentakes over the value of the current locale, so Vim converts between 'encoding'and 'termencoding'. Example: > :let &termencoding = &encoding :set encoding=utf-8 However, not all combinations of values are possible. The table below tellsyou how each of the nine combinations works. This is further restricted bynot all conversions being possible, iconv() being present, etc. Since thisdepends on the system used, no detailed list can be given. ('tenc' is the short name for 'termencoding' and 'enc' short for 'encoding') 'tenc' 'enc' remark ~ 8bit 8bit Works. When 'termencoding' is different from 'encoding' typing and displaying may be wrong for some characters, Vim does NOT perform conversion (set 'encoding' to "utf-8" to get this). 8bit 2byte MS-Windows: works for all codepages installed on your system; you can only type 8bit characters; Other systems: does NOT work. 8bit Unicode Works, but only 8bit characters can be typed directly (others through digraphs, keymaps, etc.); in a terminal you can only see 8bit characters; the GUI can show all characters that the 'guifont' supports. 2byte 8bit Works, but typing non-ASCII characters might be a problem. 2byte 2byte MS-Windows: works for all codepages installed on your system; typing characters might be a problem when locale is different from 'encoding'. Other systems: Only works when 'termencoding' is equal to 'encoding', you might as well leave it empty. 2byte Unicode works, Vim will translate typed characters. Unicode 8bit works (unusual) Unicode 2byte does NOT work Unicode Unicode works very well (leaving 'termencoding' empty works the same way, because all Unicode is handled internally as UTF-8) CONVERSION *charset-conversion* Vim will automatically convert from one to another encoding in several places:- When reading a file and 'fileencoding' is different from 'encoding'- When writing a file and 'fileencoding' is different from 'encoding'- When displaying characters and 'termencoding' is different from 'encoding'- When reading input and 'termencoding' is different from 'encoding'- When displaying messages and the encoding used for LC_MESSAGES differs from 'encoding' (requires a gettext version that supports this).- When reading a Vim script where |:scriptencoding| is different from 'encoding'.- When reading or writing a |viminfo| file.Most of these require the |+iconv| feature. Conversion for reading andwriting files may also be specified with the 'charconvert' option. Useful utilities for converting the charset: All: iconv GNU iconv can convert most encodings. Unicode is used as the intermediate encoding, which allows conversion from and to all other encodings. See http://www.gnu.org/directory/libiconv.html. Japanese: nkf Nkf is "Network Kanji code conversion Filter". One of the most unique facility of nkf is the guess of the input Kanji code. So, you don't need to know what the inputting file's |charset| is. When convert to EUC-JP from ISO-2022-JP or Shift_JIS, simply do the following command in Vim: :%!nkf -e Nkf can be found at: http://www.sfc.wide.ad.jp/~max/FreeBSD/ports/distfiles/nkf-1.62.tar.gz Chinese: hc Hc is "Hanzi Converter". Hc convert a GB file to a Big5 file, or Big5 file to GB file. Hc can be found at: ftp://ftp.cuhk.hk/pub/chinese/ifcss/software/unix/convert/hc-30.tar.gz Korean: hmconv Hmconv is Korean code conversion utility especially for E-mail. It can convert between EUC-KR and ISO-2022-KR. Hmconv can be found at: ftp://ftp.kaist.ac.kr/pub/hangul/code/hmconv/ Multilingual: lv Lv is a Powerful Multilingual File Viewer. And it can be worked as |charset| converter. Supported |charset|: ISO-2022-CN, ISO-2022-JP, ISO-2022-KR, EUC-CN, EUC-JP, EUC-KR, EUC-TW, UTF-7, UTF-8, ISO-8859 series, Shift_JIS, Big5 and HZ. Lv can be found at: http://www.ff.iij4u.or.jp/~nrt/freeware/lv4495.tar.gz *mbyte-conversion*When reading and writing files in an encoding different from 'encoding',conversion needs to be done. These conversions are supported:- All conversions between Latin-1 (ISO-8859-1), UTF-8, UCS-2 and UCS-4 are handled internally.- For MS-Windows, when 'encoding' is a Unicode encoding, conversion from and to any codepage should work.- Conversion specified with 'charconvert'- Conversion with the iconv library, if it is available. Old versions of GNU iconv() may cause the conversion to fail (they request a very large buffer, more than Vim is willing to provide). Try getting another iconv() implementation. *iconv-dynamic*On MS-Windows Vim can be compiled with the |+iconv/dyn| feature. This meansVim will search for the "iconv.dll" and "libiconv.dll" libraries. Whenneither of them can be found Vim will still work but some conversions won't bepossible. ==============================================================================4. Using a terminal *mbyte-terminal* The GUI fully supports multi-byte characters. It is also possible in aterminal, if the terminal supports the same encoding that Vim uses. Thus thisis less flexible. Lines 1–500 of 1408. Load more
*mbyte.txt* For Vim version 7.1. Last change: 2006 Aug 11 VIM REFERENCE MANUAL by Bram Moolenaar et al. Multi-byte support *multibyte* *multi-byte* *Chinese* *Japanese* *Korean* This is about editing text in languages which have many characters that can not be represented using one byte (one octet). Examples are Chinese, Japanese and Korean. Unicode is also covered here. For an introduction to the most common features, see |usr_45.txt| in the user manual. For changing the language of messages and menus see |mlang.txt|. {not available when compiled without the +multi_byte feature} 1. Getting started |mbyte-first| 2. Locale |mbyte-locale| 3. Encoding |mbyte-encoding| 4. Using a terminal |mbyte-terminal| 5. Fonts on X11 |mbyte-fonts-X11| 6. Fonts on MS-Windows |mbyte-fonts-MSwin| 7. Input on X11 |mbyte-XIM| 8. Input on MS-Windows |mbyte-IME| 9. Input with a keymap |mbyte-keymap| 10. Using UTF-8 |mbyte-utf8| 11. Overview of options |mbyte-options| NOTE: This file contains UTF-8 characters. These may show up as strange characters or boxes when using another encoding. ============================================================================== 1. Getting started *mbyte-first* This is a summary of the multibyte features in Vim. If you are lucky it works as described and you can start using Vim without much trouble. If something doesn't work you will have to read the rest. Don't be surprised if it takes quite a bit of work and experimenting to make Vim use all the multi-byte features. Unfortunately, every system has its own way to deal with multibyte languages and it is quite complicated. COMPILING If you already have a compiled Vim program, check if the |+multi_byte| feature is included. The |:version| command can be used for this. If +multi_byte is not included, you should compile Vim with "big" features. You can further tune what features are included. See the INSTALL files in the source directory. LOCALE First of all, you must make sure your current locale is set correctly. If your system has been installed to use the language, it probably works right away. If not, you can often make it work by setting the $LANG environment variable in your shell: > setenv LANG ja_JP.EUC Unfortunately, the name of the locale depends on your system. Japanese might also be called "ja_JP.EUCjp" or just "ja". To see what is currently used: > :language To change the locale inside Vim use: > :language ja_JP.EUC Vim will give an error message if this doesn't work. This is a good way to experiment and find the locale name you want to use. But it's always better to set the locale in the shell, so that it is used right from the start. See |mbyte-locale| for details. ENCODING If your locale works properly, Vim will try to set the 'encoding' option accordingly. If this doesn't work you can overrule its value: > :set encoding=utf-8 See |encoding-values| for a list of acceptable values. The result is that all the text that is used inside Vim will be in this encoding. Not only the text in the buffers, but also in registers, variables, etc. This also means that changing the value of 'encoding' makes the existing text invalid! The text doesn't change, but it will be displayed wrong. You can edit files in another encoding than what 'encoding' is set to. Vim will convert the file when you read it and convert it back when you write it. See 'fileencoding', 'fileencodings' and |++enc|. DISPLAY AND FONTS If you are working in a terminal (emulator) you must make sure it accepts the same encoding as which Vim is working with. If this is not the case, you can use the 'termencoding' option to make Vim convert text automatically. For the GUI you must select fonts that work with the current 'encoding'. This is the difficult part. It depends on the system you are using, the locale and a few other things. See the chapters on fonts: |mbyte-fonts-X11| for X-Windows and |mbyte-fonts-MSwin| for MS-Windows. For GTK+ 2, you can skip most of this section. The option 'guifontset' does no longer exist. You only need to set 'guifont' and everything should "just work". If your system comes with Xft2 and fontconfig and the current font does not contain a certain glyph, a different font will be used automatically if available. The 'guifontwide' option is still supported but usually you do not need to set it. It is only necessary if the automatic font selection does not suit your needs. For X11 you can set the 'guifontset' option to a list of fonts that together cover the characters that are used. Example for Korean: > :set guifontset=k12,r12 Alternatively, you can set 'guifont' and 'guifontwide'. 'guifont' is used for the single-width characters, 'guifontwide' for the double-width characters. Thus the 'guifontwide' font must be exactly twice as wide as 'guifont'. Example for UTF-8: > :set guifont=-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1 :set guifontwide=-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1 You can also set 'guifont' alone, Vim will try to find a matching 'guifontwide' for you. INPUT There are several ways to enter multi-byte characters: - For X11 XIM can be used. See |XIM|. - For MS-Windows IME can be used. See |IME|. - For all systems keymaps can be used. See |mbyte-keymap|. The options 'iminsert', 'imsearch' and 'imcmdline' can be used to chose the different input methods or disable them temporarily. ============================================================================== 2. Locale *mbyte-locale* The easiest setup is when your whole system uses the locale you want to work in. But it's also possible to set the locale for one shell you are working in, or just use a certain locale inside Vim. WHAT IS A LOCALE? *locale* There are many of languages in the world. And there are different cultures and environments at least as much as the number of languages. A linguistic environment corresponding to an area is called "locale". This includes information about the used language, the charset, collating order for sorting, date format, currency format and so on. For Vim only the language and charset really matter. You can only use a locale if your system has support for it. Some systems have only a few locales, especially in the USA. The language which you want to use may not be on your system. In that case you might be able to install it as an extra package. Check your system documentation for how to do that. The location in which the locales are installed varies from system to system. For example, "/usr/share/locale" or "/usr/lib/locale". See your system's setlocale() man page. Looking in these directories will show you the exact name of each locale. Mostly upper/lowercase matters, thus "ja_JP.EUC" and "ja_jp.euc" are different. Some systems have a locale.alias file, which allows translation from a short name like "nl" to the full name "nl_NL.ISO_8859-1". Note that X-windows has its own locale stuff. And unfortunately uses locale names different from what is used elsewhere. This is confusing! For Vim it matters what the setlocale() function uses, which is generally NOT the X-windows stuff. You might have to do some experiments to find out what really works. *locale-name* The (simplified) format of |locale| name is: language or language_territory or language_territory.codeset Territory means the country (or part of it), codeset means the |charset|. For example, the locale name "ja_JP.eucJP" means: ja the language is Japanese JP the country is Japan eucJP the codeset is EUC-JP But it also could be "ja", "ja_JP.EUC", "ja_JP.ujis", etc. And unfortunately, the locale name for a specific language, territory and codeset is not unified and depends on your system. Examples of locale name: charset language locale name ~ GB2312 Chinese (simplified) zh_CN.EUC, zh_CN.GB2312 Big5 Chinese (traditional) zh_TW.BIG5, zh_TW.Big5 CNS-11643 Chinese (traditional) zh_TW EUC-JP Japanese ja, ja_JP.EUC, ja_JP.ujis, ja_JP.eucJP Shift_JIS Japanese ja_JP.SJIS, ja_JP.Shift_JIS EUC-KR Korean ko, ko_KR.EUC USING A LOCALE To start using a locale for the whole system, see the documentation of your system. Mostly you need to set it in a configuration file in "/etc". To use a locale in a shell, set the $LANG environment value. When you want to use Korean and the |locale| name is "ko", do this: sh: export LANG=ko csh: setenv LANG ko You can put this in your ~/.profile or ~/.cshrc file to always use it. To use a locale in Vim only, use the |:language| command: > :language ko Put this in your ~/.vimrc file to use it always. Or specify $LANG when starting Vim: sh: LANG=ko vim {vim-arguments} csh: env LANG=ko vim {vim-arguments} You could make a small shell script for this. ============================================================================== 3. Encoding *mbyte-encoding* Vim uses the 'encoding' option to specify how characters identified and encoded when they are used inside Vim. This applies to all the places where text is used, including buffers (files loaded into memory), registers and variables. *charset* *codeset* Charset is another name for encoding. There are subtle differences, but these don't matter when using Vim. "codeset" is another similar name. Each character is encoded as one or more bytes. When all characters are encoded with one byte, we call this a single-byte encoding. The most often used one is called "latin1". This limits the number of characters to 256. Some of these are control characters, thus even fewer can be used for text. When some characters use two or more bytes, we call this a multi-byte encoding. This allows using much more than 256 characters, which is required for most East Asian languages. Most multi-byte encodings use one byte for the first 127 characters. These are equal to ASCII, which makes it easy to exchange plain-ASCII text, no matter what language is used. Thus you might see the right text even when the encoding was set wrong. *encoding-names* Vim can use many different character encodings. There are three major groups: 1 8bit Single-byte encodings, 256 different characters. Mostly used in USA and Europe. Example: ISO-8859-1 (Latin1). All characters occupy one screen cell only. 2 2byte Double-byte encodings, over 10000 different characters. Mostly used in Asian countries. Example: euc-kr (Korean) The number of screen cells is equal to the number of bytes (except for euc-jp when the first byte is 0x8e). u Unicode Universal encoding, can replace all others. ISO 10646. Millions of different characters. Example: UTF-8. The relation between bytes and screen cells is complex. Other encodings cannot be used by Vim internally. But files in other encodings can be edited by using conversion, see 'fileencoding'. Note that all encodings must use ASCII for the characters up to 128 (except when compiled for EBCDIC). Supported 'encoding' values are: *encoding-values* 1 latin1 8-bit characters (ISO 8859-1) 1 iso-8859-n ISO_8859 variant (n = 2 to 15) 1 koi8-r Russian 1 koi8-u Ukrainian 1 macroman MacRoman (Macintosh encoding) 1 8bit-{name} any 8-bit encoding (Vim specific name) 1 cp437 similar to iso-8859-1 1 cp737 similar to iso-8859-7 1 cp775 Baltic 1 cp850 similar to iso-8859-4 1 cp852 similar to iso-8859-1 1 cp855 similar to iso-8859-2 1 cp857 similar to iso-8859-5 1 cp860 similar to iso-8859-9 1 cp861 similar to iso-8859-1 1 cp862 similar to iso-8859-1 1 cp863 similar to iso-8859-8 1 cp865 similar to iso-8859-1 1 cp866 similar to iso-8859-5 1 cp869 similar to iso-8859-7 1 cp874 Thai 1 cp1250 Czech, Polish, etc. 1 cp1251 Cyrillic 1 cp1253 Greek 1 cp1254 Turkish 1 cp1255 Hebrew 1 cp1256 Arabic 1 cp1257 Baltic 1 cp1258 Vietnamese 1 cp{number} MS-Windows: any installed single-byte codepage 2 cp932 Japanese (Windows only) 2 euc-jp Japanese (Unix only) 2 sjis Japanese (Unix only) 2 cp949 Korean (Unix and Windows) 2 euc-kr Korean (Unix only) 2 cp936 simplified Chinese (Windows only) 2 euc-cn simplified Chinese (Unix only) 2 cp950 traditional Chinese (on Unix alias for big5) 2 big5 traditional Chinese (on Windows alias for cp950) 2 euc-tw traditional Chinese (Unix only) 2 2byte-{name} Unix: any double-byte encoding (Vim specific name) 2 cp{number} MS-Windows: any installed double-byte codepage u utf-8 32 bit UTF-8 encoded Unicode (ISO/IEC 10646-1) u ucs-2 16 bit UCS-2 encoded Unicode (ISO/IEC 10646-1) u ucs-2le like ucs-2, little endian u utf-16 ucs-2 extended with double-words for more characters u utf-16le like utf-16, little endian u ucs-4 32 bit UCS-4 encoded Unicode (ISO/IEC 10646-1) u ucs-4le like ucs-4, little endian The {name} can be any encoding name that your system supports. It is passed to iconv() to convert between the encoding of the file and the current locale. For MS-Windows "cp{number}" means using codepage {number}. Examples: > :set encoding=8bit-cp1252 :set encoding=2byte-cp932 < Several aliases can be used, they are translated to one of the names above. An incomplete list: 1 ansi same as latin1 (obsolete, for backward compatibility) 2 japan Japanese: on Unix "euc-jp", on MS-Windows cp932 2 korea Korean: on Unix "euc-kr", on MS-Windows cp949 2 prc simplified Chinese: on Unix "euc-cn", on MS-Windows cp936 2 chinese same as "prc" 2 taiwan traditional Chinese: on Unix "euc-tw", on MS-Windows cp950 u utf8 same as utf-8 u unicode same as ucs-2 u ucs2be same as ucs-2 (big endian) u ucs-2be same as ucs-2 (big endian) u ucs-4be same as ucs-4 (big endian) default stands for the default value of 'encoding', depends on the environment For the UCS codes the byte order matters. This is tricky, use UTF-8 whenever you can. The default is to use big-endian (most significant byte comes first): name bytes char ~ ucs-2 11 22 1122 ucs-2le 22 11 1122 ucs-4 11 22 33 44 11223344 ucs-4le 44 33 22 11 11223344 On MS-Windows systems you often want to use "ucs-2le", because it uses little endian UCS-2. There are a few encodings which are similar, but not exactly the same. Vim treats them as if they were different encodings, so that conversion will be done when needed. You might want to use the similar name to avoid conversion or when conversion is not possible: cp932, shift-jis, sjis cp936, euc-cn *encoding-table* Normally 'encoding' is equal to your current locale and 'termencoding' is empty. This means that your keyboard and display work with characters encoded in your current locale, and Vim uses the same characters internally. You can make Vim use characters in a different encoding by setting the 'encoding' option to a different value. Since the keyboard and display still use the current locale, conversion needs to be done. The 'termencoding' then takes over the value of the current locale, so Vim converts between 'encoding' and 'termencoding'. Example: > :let &termencoding = &encoding :set encoding=utf-8 However, not all combinations of values are possible. The table below tells you how each of the nine combinations works. This is further restricted by not all conversions being possible, iconv() being present, etc. Since this depends on the system used, no detailed list can be given. ('tenc' is the short name for 'termencoding' and 'enc' short for 'encoding') 'tenc' 'enc' remark ~ 8bit 8bit Works. When 'termencoding' is different from 'encoding' typing and displaying may be wrong for some characters, Vim does NOT perform conversion (set 'encoding' to "utf-8" to get this). 8bit 2byte MS-Windows: works for all codepages installed on your system; you can only type 8bit characters; Other systems: does NOT work. 8bit Unicode Works, but only 8bit characters can be typed directly (others through digraphs, keymaps, etc.); in a terminal you can only see 8bit characters; the GUI can show all characters that the 'guifont' supports. 2byte 8bit Works, but typing non-ASCII characters might be a problem. 2byte 2byte MS-Windows: works for all codepages installed on your system; typing characters might be a problem when locale is different from 'encoding'. Other systems: Only works when 'termencoding' is equal to 'encoding', you might as well leave it empty. 2byte Unicode works, Vim will translate typed characters. Unicode 8bit works (unusual) Unicode 2byte does NOT work Unicode Unicode works very well (leaving 'termencoding' empty works the same way, because all Unicode is handled internally as UTF-8) CONVERSION *charset-conversion* Vim will automatically convert from one to another encoding in several places: - When reading a file and 'fileencoding' is different from 'encoding' - When writing a file and 'fileencoding' is different from 'encoding' - When displaying characters and 'termencoding' is different from 'encoding' - When reading input and 'termencoding' is different from 'encoding' - When displaying messages and the encoding used for LC_MESSAGES differs from 'encoding' (requires a gettext version that supports this). - When reading a Vim script where |:scriptencoding| is different from 'encoding'. - When reading or writing a |viminfo| file. Most of these require the |+iconv| feature. Conversion for reading and writing files may also be specified with the 'charconvert' option. Useful utilities for converting the charset: All: iconv GNU iconv can convert most encodings. Unicode is used as the intermediate encoding, which allows conversion from and to all other encodings. See http://www.gnu.org/directory/libiconv.html. Japanese: nkf Nkf is "Network Kanji code conversion Filter". One of the most unique facility of nkf is the guess of the input Kanji code. So, you don't need to know what the inputting file's |charset| is. When convert to EUC-JP from ISO-2022-JP or Shift_JIS, simply do the following command in Vim: :%!nkf -e Nkf can be found at: http://www.sfc.wide.ad.jp/~max/FreeBSD/ports/distfiles/nkf-1.62.tar.gz Chinese: hc Hc is "Hanzi Converter". Hc convert a GB file to a Big5 file, or Big5 file to GB file. Hc can be found at: ftp://ftp.cuhk.hk/pub/chinese/ifcss/software/unix/convert/hc-30.tar.gz Korean: hmconv Hmconv is Korean code conversion utility especially for E-mail. It can convert between EUC-KR and ISO-2022-KR. Hmconv can be found at: ftp://ftp.kaist.ac.kr/pub/hangul/code/hmconv/ Multilingual: lv Lv is a Powerful Multilingual File Viewer. And it can be worked as |charset| converter. Supported |charset|: ISO-2022-CN, ISO-2022-JP, ISO-2022-KR, EUC-CN, EUC-JP, EUC-KR, EUC-TW, UTF-7, UTF-8, ISO-8859 series, Shift_JIS, Big5 and HZ. Lv can be found at: http://www.ff.iij4u.or.jp/~nrt/freeware/lv4495.tar.gz *mbyte-conversion* When reading and writing files in an encoding different from 'encoding', conversion needs to be done. These conversions are supported: - All conversions between Latin-1 (ISO-8859-1), UTF-8, UCS-2 and UCS-4 are handled internally. - For MS-Windows, when 'encoding' is a Unicode encoding, conversion from and to any codepage should work. - Conversion specified with 'charconvert' - Conversion with the iconv library, if it is available. Old versions of GNU iconv() may cause the conversion to fail (they request a very large buffer, more than Vim is willing to provide). Try getting another iconv() implementation. *iconv-dynamic* On MS-Windows Vim can be compiled with the |+iconv/dyn| feature. This means Vim will search for the "iconv.dll" and "libiconv.dll" libraries. When neither of them can be found Vim will still work but some conversions won't be possible. ============================================================================== 4. Using a terminal *mbyte-terminal* The GUI fully supports multi-byte characters. It is also possible in a terminal, if the terminal supports the same encoding that Vim uses. Thus this is less flexible.