blob: f02092b81063ca8ce5abe11456497f5b89af1c46 [file] [log] [blame]
Christian Brabandtd24aaa92024-07-17 08:25:45 +02001*mbyte.txt* For Vim version 9.1. Last change: 2024 Jul 17
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar et al.
5
6
7Multi-byte support *multibyte* *multi-byte*
8 *Chinese* *Japanese* *Korean*
9This is about editing text in languages which have many characters that can
10not be represented using one byte (one octet). Examples are Chinese, Japanese
11and Korean. Unicode is also covered here.
12
13For an introduction to the most common features, see |usr_45.txt| in the user
14manual.
15For changing the language of messages and menus see |mlang.txt|.
16
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171. Getting started |mbyte-first|
182. Locale |mbyte-locale|
193. Encoding |mbyte-encoding|
204. Using a terminal |mbyte-terminal|
215. Fonts on X11 |mbyte-fonts-X11|
226. Fonts on MS-Windows |mbyte-fonts-MSwin|
237. Input on X11 |mbyte-XIM|
248. Input on MS-Windows |mbyte-IME|
259. Input with a keymap |mbyte-keymap|
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01002610. Input with imactivatefunc() |mbyte-func|
2711. Using UTF-8 |mbyte-utf8|
2812. Overview of options |mbyte-options|
Bram Moolenaar071d4272004-06-13 20:20:40 +000029
30NOTE: This file contains UTF-8 characters. These may show up as strange
31characters or boxes when using another encoding.
32
33==============================================================================
341. Getting started *mbyte-first*
35
36This is a summary of the multibyte features in Vim. If you are lucky it works
37as described and you can start using Vim without much trouble. If something
38doesn't work you will have to read the rest. Don't be surprised if it takes
Bram Moolenaar207f0092020-08-30 17:20:20 +020039quite a bit of work and experimenting to make Vim use all the multibyte
Bram Moolenaar071d4272004-06-13 20:20:40 +000040features. Unfortunately, every system has its own way to deal with multibyte
41languages and it is quite complicated.
42
43
Bram Moolenaar071d4272004-06-13 20:20:40 +000044LOCALE
45
46First of all, you must make sure your current locale is set correctly. If
47your system has been installed to use the language, it probably works right
48away. If not, you can often make it work by setting the $LANG environment
49variable in your shell: >
50
51 setenv LANG ja_JP.EUC
52
53Unfortunately, the name of the locale depends on your system. Japanese might
54also be called "ja_JP.EUCjp" or just "ja". To see what is currently used: >
55
56 :language
57
58To change the locale inside Vim use: >
59
60 :language ja_JP.EUC
61
62Vim will give an error message if this doesn't work. This is a good way to
63experiment and find the locale name you want to use. But it's always better
64to set the locale in the shell, so that it is used right from the start.
65
66See |mbyte-locale| for details.
67
68
69ENCODING
70
71If your locale works properly, Vim will try to set the 'encoding' option
72accordingly. If this doesn't work you can overrule its value: >
73
74 :set encoding=utf-8
75
76See |encoding-values| for a list of acceptable values.
77
78The result is that all the text that is used inside Vim will be in this
79encoding. Not only the text in the buffers, but also in registers, variables,
80etc. This also means that changing the value of 'encoding' makes the existing
81text invalid! The text doesn't change, but it will be displayed wrong.
82
83You can edit files in another encoding than what 'encoding' is set to. Vim
84will convert the file when you read it and convert it back when you write it.
85See 'fileencoding', 'fileencodings' and |++enc|.
86
87
88DISPLAY AND FONTS
89
90If you are working in a terminal (emulator) you must make sure it accepts the
91same encoding as which Vim is working with. If this is not the case, you can
92use the 'termencoding' option to make Vim convert text automatically.
93
94For the GUI you must select fonts that work with the current 'encoding'. This
95is the difficult part. It depends on the system you are using, the locale and
96a few other things. See the chapters on fonts: |mbyte-fonts-X11| for
97X-Windows and |mbyte-fonts-MSwin| for MS-Windows.
98
99For GTK+ 2, you can skip most of this section. The option 'guifontset' does
100no longer exist. You only need to set 'guifont' and everything should "just
101work". If your system comes with Xft2 and fontconfig and the current font
102does not contain a certain glyph, a different font will be used automatically
103if available. The 'guifontwide' option is still supported but usually you do
104not need to set it. It is only necessary if the automatic font selection does
105not suit your needs.
106
107For X11 you can set the 'guifontset' option to a list of fonts that together
108cover the characters that are used. Example for Korean: >
109
110 :set guifontset=k12,r12
111
112Alternatively, you can set 'guifont' and 'guifontwide'. 'guifont' is used for
113the single-width characters, 'guifontwide' for the double-width characters.
114Thus the 'guifontwide' font must be exactly twice as wide as 'guifont'.
115Example for UTF-8: >
116
117 :set guifont=-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1
118 :set guifontwide=-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1
119
120You can also set 'guifont' alone, Vim will try to find a matching
121'guifontwide' for you.
122
123
124INPUT
125
Bram Moolenaar207f0092020-08-30 17:20:20 +0200126There are several ways to enter multibyte characters:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127- For X11 XIM can be used. See |XIM|.
128- For MS-Windows IME can be used. See |IME|.
129- For all systems keymaps can be used. See |mbyte-keymap|.
130
Bram Moolenaar2547aa92020-07-26 17:00:44 +0200131The options 'iminsert', 'imsearch' and 'imcmdline' can be used to choose
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000132the different input methods or disable them temporarily.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133
134==============================================================================
1352. Locale *mbyte-locale*
136
137The easiest setup is when your whole system uses the locale you want to work
138in. But it's also possible to set the locale for one shell you are working
139in, or just use a certain locale inside Vim.
140
141
142WHAT IS A LOCALE? *locale*
143
Bram Moolenaar2547aa92020-07-26 17:00:44 +0200144There are many languages in the world. And there are different cultures and
145environments at least as many as the number of languages. A linguistic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146environment corresponding to an area is called "locale". This includes
147information about the used language, the charset, collating order for sorting,
148date format, currency format and so on. For Vim only the language and charset
149really matter.
150
151You can only use a locale if your system has support for it. Some systems
152have only a few locales, especially in the USA. The language which you want
153to use may not be on your system. In that case you might be able to install
154it as an extra package. Check your system documentation for how to do that.
155
156The location in which the locales are installed varies from system to system.
157For example, "/usr/share/locale" or "/usr/lib/locale". See your system's
158setlocale() man page.
159
160Looking in these directories will show you the exact name of each locale.
161Mostly upper/lowercase matters, thus "ja_JP.EUC" and "ja_jp.euc" are
162different. Some systems have a locale.alias file, which allows translation
163from a short name like "nl" to the full name "nl_NL.ISO_8859-1".
164
165Note that X-windows has its own locale stuff. And unfortunately uses locale
166names different from what is used elsewhere. This is confusing! For Vim it
167matters what the setlocale() function uses, which is generally NOT the
168X-windows stuff. You might have to do some experiments to find out what
169really works.
170
171 *locale-name*
172The (simplified) format of |locale| name is:
173
174 language
175or language_territory
176or language_territory.codeset
177
178Territory means the country (or part of it), codeset means the |charset|. For
179example, the locale name "ja_JP.eucJP" means:
180 ja the language is Japanese
181 JP the country is Japan
182 eucJP the codeset is EUC-JP
183But it also could be "ja", "ja_JP.EUC", "ja_JP.ujis", etc. And unfortunately,
184the locale name for a specific language, territory and codeset is not unified
185and depends on your system.
186
187Examples of locale name:
188 charset language locale name ~
189 GB2312 Chinese (simplified) zh_CN.EUC, zh_CN.GB2312
190 Big5 Chinese (traditional) zh_TW.BIG5, zh_TW.Big5
191 CNS-11643 Chinese (traditional) zh_TW
192 EUC-JP Japanese ja, ja_JP.EUC, ja_JP.ujis, ja_JP.eucJP
193 Shift_JIS Japanese ja_JP.SJIS, ja_JP.Shift_JIS
194 EUC-KR Korean ko, ko_KR.EUC
195
196
197USING A LOCALE
198
199To start using a locale for the whole system, see the documentation of your
200system. Mostly you need to set it in a configuration file in "/etc".
201
202To use a locale in a shell, set the $LANG environment value. When you want to
203use Korean and the |locale| name is "ko", do this:
204
205 sh: export LANG=ko
206 csh: setenv LANG ko
207
208You can put this in your ~/.profile or ~/.cshrc file to always use it.
209
210To use a locale in Vim only, use the |:language| command: >
211
212 :language ko
213
214Put this in your ~/.vimrc file to use it always.
215
216Or specify $LANG when starting Vim:
217
218 sh: LANG=ko vim {vim-arguments}
219 csh: env LANG=ko vim {vim-arguments}
220
221You could make a small shell script for this.
222
223==============================================================================
2243. Encoding *mbyte-encoding*
225
Bram Moolenaar446cb832008-06-24 21:56:24 +0000226Vim uses the 'encoding' option to specify how characters are identified and
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227encoded when they are used inside Vim. This applies to all the places where
228text is used, including buffers (files loaded into memory), registers and
229variables.
230
231 *charset* *codeset*
232Charset is another name for encoding. There are subtle differences, but these
233don't matter when using Vim. "codeset" is another similar name.
234
235Each character is encoded as one or more bytes. When all characters are
236encoded with one byte, we call this a single-byte encoding. The most often
237used one is called "latin1". This limits the number of characters to 256.
238Some of these are control characters, thus even fewer can be used for text.
239
Bram Moolenaar207f0092020-08-30 17:20:20 +0200240When some characters use two or more bytes, we call this a multibyte
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241encoding. This allows using much more than 256 characters, which is required
242for most East Asian languages.
243
Bram Moolenaar207f0092020-08-30 17:20:20 +0200244Most multibyte encodings use one byte for the first 127 characters. These
Bram Moolenaar071d4272004-06-13 20:20:40 +0000245are equal to ASCII, which makes it easy to exchange plain-ASCII text, no
246matter what language is used. Thus you might see the right text even when the
247encoding was set wrong.
248
249 *encoding-names*
250Vim can use many different character encodings. There are three major groups:
251
2521 8bit Single-byte encodings, 256 different characters. Mostly used
253 in USA and Europe. Example: ISO-8859-1 (Latin1). All
254 characters occupy one screen cell only.
255
2562 2byte Double-byte encodings, over 10000 different characters.
257 Mostly used in Asian countries. Example: euc-kr (Korean)
258 The number of screen cells is equal to the number of bytes
259 (except for euc-jp when the first byte is 0x8e).
260
261u Unicode Universal encoding, can replace all others. ISO 10646.
262 Millions of different characters. Example: UTF-8. The
263 relation between bytes and screen cells is complex.
264
265Other encodings cannot be used by Vim internally. But files in other
266encodings can be edited by using conversion, see 'fileencoding'.
267Note that all encodings must use ASCII for the characters up to 128 (except
268when compiled for EBCDIC).
269
270Supported 'encoding' values are: *encoding-values*
Bram Moolenaard58e9292011-02-09 17:07:58 +01002711 latin1 8-bit characters (ISO 8859-1, also used for cp1252)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 iso-8859-n ISO_8859 variant (n = 2 to 15)
2731 koi8-r Russian
2741 koi8-u Ukrainian
2751 macroman MacRoman (Macintosh encoding)
2761 8bit-{name} any 8-bit encoding (Vim specific name)
Bram Moolenaar35fdbb52005-07-09 21:08:57 +00002771 cp437 similar to iso-8859-1
2781 cp737 similar to iso-8859-7
2791 cp775 Baltic
2801 cp850 similar to iso-8859-4
2811 cp852 similar to iso-8859-1
2821 cp855 similar to iso-8859-2
2831 cp857 similar to iso-8859-5
2841 cp860 similar to iso-8859-9
2851 cp861 similar to iso-8859-1
2861 cp862 similar to iso-8859-1
2871 cp863 similar to iso-8859-8
2881 cp865 similar to iso-8859-1
2891 cp866 similar to iso-8859-5
2901 cp869 similar to iso-8859-7
2911 cp874 Thai
2921 cp1250 Czech, Polish, etc.
2931 cp1251 Cyrillic
2941 cp1253 Greek
2951 cp1254 Turkish
2961 cp1255 Hebrew
2971 cp1256 Arabic
2981 cp1257 Baltic
2991 cp1258 Vietnamese
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 cp{number} MS-Windows: any installed single-byte codepage
3012 cp932 Japanese (Windows only)
3022 euc-jp Japanese (Unix only)
3032 sjis Japanese (Unix only)
3042 cp949 Korean (Unix and Windows)
3052 euc-kr Korean (Unix only)
3062 cp936 simplified Chinese (Windows only)
3072 euc-cn simplified Chinese (Unix only)
3082 cp950 traditional Chinese (on Unix alias for big5)
3092 big5 traditional Chinese (on Windows alias for cp950)
3102 euc-tw traditional Chinese (Unix only)
3112 2byte-{name} Unix: any double-byte encoding (Vim specific name)
3122 cp{number} MS-Windows: any installed double-byte codepage
313u utf-8 32 bit UTF-8 encoded Unicode (ISO/IEC 10646-1)
314u ucs-2 16 bit UCS-2 encoded Unicode (ISO/IEC 10646-1)
315u ucs-2le like ucs-2, little endian
316u utf-16 ucs-2 extended with double-words for more characters
317u utf-16le like utf-16, little endian
318u ucs-4 32 bit UCS-4 encoded Unicode (ISO/IEC 10646-1)
319u ucs-4le like ucs-4, little endian
320
321The {name} can be any encoding name that your system supports. It is passed
322to iconv() to convert between the encoding of the file and the current locale.
323For MS-Windows "cp{number}" means using codepage {number}.
324Examples: >
325 :set encoding=8bit-cp1252
326 :set encoding=2byte-cp932
Bram Moolenaard58e9292011-02-09 17:07:58 +0100327
328The MS-Windows codepage 1252 is very similar to latin1. For practical reasons
329the same encoding is used and it's called latin1. 'isprint' can be used to
330display the characters 0x80 - 0xA0 or not.
331
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332Several aliases can be used, they are translated to one of the names above.
333An incomplete list:
334
3351 ansi same as latin1 (obsolete, for backward compatibility)
3362 japan Japanese: on Unix "euc-jp", on MS-Windows cp932
3372 korea Korean: on Unix "euc-kr", on MS-Windows cp949
3382 prc simplified Chinese: on Unix "euc-cn", on MS-Windows cp936
3392 chinese same as "prc"
3402 taiwan traditional Chinese: on Unix "euc-tw", on MS-Windows cp950
341u utf8 same as utf-8
342u unicode same as ucs-2
343u ucs2be same as ucs-2 (big endian)
344u ucs-2be same as ucs-2 (big endian)
345u ucs-4be same as ucs-4 (big endian)
Bram Moolenaar446cb832008-06-24 21:56:24 +0000346u utf-32 same as ucs-4
347u utf-32le same as ucs-4le
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000348 default stands for the default value of 'encoding', depends on the
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000349 environment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350
351For the UCS codes the byte order matters. This is tricky, use UTF-8 whenever
352you can. The default is to use big-endian (most significant byte comes
353first):
354 name bytes char ~
355 ucs-2 11 22 1122
356 ucs-2le 22 11 1122
357 ucs-4 11 22 33 44 11223344
358 ucs-4le 44 33 22 11 11223344
359
360On MS-Windows systems you often want to use "ucs-2le", because it uses little
361endian UCS-2.
362
363There are a few encodings which are similar, but not exactly the same. Vim
364treats them as if they were different encodings, so that conversion will be
365done when needed. You might want to use the similar name to avoid conversion
366or when conversion is not possible:
367
368 cp932, shift-jis, sjis
369 cp936, euc-cn
370
371 *encoding-table*
372Normally 'encoding' is equal to your current locale and 'termencoding' is
373empty. This means that your keyboard and display work with characters encoded
374in your current locale, and Vim uses the same characters internally.
375
376You can make Vim use characters in a different encoding by setting the
377'encoding' option to a different value. Since the keyboard and display still
378use the current locale, conversion needs to be done. The 'termencoding' then
379takes over the value of the current locale, so Vim converts between 'encoding'
380and 'termencoding'. Example: >
381 :let &termencoding = &encoding
382 :set encoding=utf-8
383
384However, not all combinations of values are possible. The table below tells
385you how each of the nine combinations works. This is further restricted by
386not all conversions being possible, iconv() being present, etc. Since this
387depends on the system used, no detailed list can be given.
388
389('tenc' is the short name for 'termencoding' and 'enc' short for 'encoding')
390
391'tenc' 'enc' remark ~
392
393 8bit 8bit Works. When 'termencoding' is different from
394 'encoding' typing and displaying may be wrong for some
395 characters, Vim does NOT perform conversion (set
396 'encoding' to "utf-8" to get this).
397 8bit 2byte MS-Windows: works for all codepages installed on your
398 system; you can only type 8bit characters;
399 Other systems: does NOT work.
Bram Moolenaar9964e462007-05-05 17:54:07 +0000400 8bit Unicode Works, but only 8bit characters can be typed directly
401 (others through digraphs, keymaps, etc.); in a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402 terminal you can only see 8bit characters; the GUI can
403 show all characters that the 'guifont' supports.
404
405 2byte 8bit Works, but typing non-ASCII characters might
406 be a problem.
407 2byte 2byte MS-Windows: works for all codepages installed on your
408 system; typing characters might be a problem when
409 locale is different from 'encoding'.
410 Other systems: Only works when 'termencoding' is equal
411 to 'encoding', you might as well leave it empty.
412 2byte Unicode works, Vim will translate typed characters.
413
414 Unicode 8bit works (unusual)
415 Unicode 2byte does NOT work
416 Unicode Unicode works very well (leaving 'termencoding' empty works
417 the same way, because all Unicode is handled
418 internally as UTF-8)
419
420CONVERSION *charset-conversion*
421
422Vim will automatically convert from one to another encoding in several places:
423- When reading a file and 'fileencoding' is different from 'encoding'
424- When writing a file and 'fileencoding' is different from 'encoding'
425- When displaying characters and 'termencoding' is different from 'encoding'
426- When reading input and 'termencoding' is different from 'encoding'
427- When displaying messages and the encoding used for LC_MESSAGES differs from
428 'encoding' (requires a gettext version that supports this).
429- When reading a Vim script where |:scriptencoding| is different from
430 'encoding'.
431- When reading or writing a |viminfo| file.
432Most of these require the |+iconv| feature. Conversion for reading and
433writing files may also be specified with the 'charconvert' option.
434
435Useful utilities for converting the charset:
436 All: iconv
437 GNU iconv can convert most encodings. Unicode is used as the
438 intermediate encoding, which allows conversion from and to all other
439 encodings. See http://www.gnu.org/directory/libiconv.html.
440
441 Japanese: nkf
442 Nkf is "Network Kanji code conversion Filter". One of the most unique
443 facility of nkf is the guess of the input Kanji code. So, you don't
444 need to know what the inputting file's |charset| is. When convert to
445 EUC-JP from ISO-2022-JP or Shift_JIS, simply do the following command
446 in Vim:
447 :%!nkf -e
448 Nkf can be found at:
449 http://www.sfc.wide.ad.jp/~max/FreeBSD/ports/distfiles/nkf-1.62.tar.gz
450
451 Chinese: hc
452 Hc is "Hanzi Converter". Hc convert a GB file to a Big5 file, or Big5
453 file to GB file. Hc can be found at:
Christian Brabandt1c5728e2024-05-11 11:12:40 +0200454 https://www.freshports.org/chinese/hc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455 ftp://ftp.cuhk.hk/pub/chinese/ifcss/software/unix/convert/hc-30.tar.gz
456
457 Korean: hmconv
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000458 Hmconv is Korean code conversion utility especially for E-mail. It can
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459 convert between EUC-KR and ISO-2022-KR. Hmconv can be found at:
Christian Brabandt1c5728e2024-05-11 11:12:40 +0200460 https://www.freshports.org/korean/hmconv/
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461
462 Multilingual: lv
463 Lv is a Powerful Multilingual File Viewer. And it can be worked as
464 |charset| converter. Supported |charset|: ISO-2022-CN, ISO-2022-JP,
465 ISO-2022-KR, EUC-CN, EUC-JP, EUC-KR, EUC-TW, UTF-7, UTF-8, ISO-8859
Christian Brabandt1c5728e2024-05-11 11:12:40 +0200466 series, Shift_JIS, Big5 and HZ. Lv can be found at (link seems dead):
Bram Moolenaar30b65812012-07-12 22:01:11 +0200467 http://www.ff.iij4u.or.jp/~nrt/lv/index.html
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468
469
470 *mbyte-conversion*
471When reading and writing files in an encoding different from 'encoding',
472conversion needs to be done. These conversions are supported:
473- All conversions between Latin-1 (ISO-8859-1), UTF-8, UCS-2 and UCS-4 are
474 handled internally.
475- For MS-Windows, when 'encoding' is a Unicode encoding, conversion from and
476 to any codepage should work.
477- Conversion specified with 'charconvert'
478- Conversion with the iconv library, if it is available.
479 Old versions of GNU iconv() may cause the conversion to fail (they
480 request a very large buffer, more than Vim is willing to provide).
481 Try getting another iconv() implementation.
482
Bram Moolenaara5792f52005-11-23 21:25:05 +0000483 *iconv-dynamic*
484On MS-Windows Vim can be compiled with the |+iconv/dyn| feature. This means
485Vim will search for the "iconv.dll" and "libiconv.dll" libraries. When
486neither of them can be found Vim will still work but some conversions won't be
487possible.
488
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489==============================================================================
4904. Using a terminal *mbyte-terminal*
491
Bram Moolenaar207f0092020-08-30 17:20:20 +0200492The GUI fully supports multibyte characters. It is also possible in a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493terminal, if the terminal supports the same encoding that Vim uses. Thus this
494is less flexible.
495
Christian Brabandte7a45232024-07-17 20:41:48 +0200496For example, you can run Vim in an xterm with added multibyte support and/or
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497|XIM|. Examples are kterm (Kanji term) and hanterm (for Korean), Eterm
498(Enlightened terminal) and rxvt.
499
500If your terminal does not support the right encoding, you can set the
501'termencoding' option. Vim will then convert the typed characters from
502'termencoding' to 'encoding'. And displayed text will be converted from
503'encoding' to 'termencoding'. If the encoding supported by the terminal
504doesn't include all the characters that Vim uses, this leads to lost
505characters. This may mess up the display. If you use a terminal that
506supports Unicode, such as the xterm mentioned below, it should work just fine,
507since nearly every character set can be converted to Unicode without loss of
508information.
509
510
511UTF-8 IN XFREE86 XTERM *UTF8-xterm*
512
513This is a short explanation of how to use UTF-8 character encoding in the
514xterm that comes with XFree86 by Thomas Dickey (text by Markus Kuhn).
515
516Get the latest xterm version which has now UTF-8 support:
517
518 http://invisible-island.net/xterm/xterm.html
519
520Compile it with "./configure --enable-wide-chars ; make"
521
522Also get the ISO 10646-1 version of various fonts, which is available on
523
524 http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz
525
526and install the font as described in the README file.
527
528Now start xterm with >
529
530 xterm -u8 -fn -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1
531or, for bigger character: >
532 xterm -u8 -fn -misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1
533
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000534and you will have a working UTF-8 terminal emulator. Try both >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535
536 cat utf-8-demo.txt
537 vim utf-8-demo.txt
538
539with the demo text that comes with ucs-fonts.tar.gz in order to see
540whether there are any problems with UTF-8 in your xterm.
541
542For Vim you may need to set 'encoding' to "utf-8".
543
544==============================================================================
5455. Fonts on X11 *mbyte-fonts-X11*
546
547Unfortunately, using fonts in X11 is complicated. The name of a single-byte
Bram Moolenaar207f0092020-08-30 17:20:20 +0200548font is a long string. For multibyte fonts we need several of these...
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549
550Note: Most of this is no longer relevant for GTK+ 2. Selecting a font via
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100551its XLFD is not supported; see 'guifont' for an example of how to
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552set the font. Do yourself a favor and ignore the |XLFD| and |xfontset|
553sections below.
554
555First of all, Vim only accepts fixed-width fonts for displaying text. You
556cannot use proportionally spaced fonts. This excludes many of the available
557(and nicer looking) fonts. However, for menus and tooltips any font can be
558used.
559
560Note that Display and Input are independent. It is possible to see your
561language even though you have no input method for it.
562
563You should get a default font for menus and tooltips that works, but it might
564be ugly. Read the following to find out how to select a better font.
565
566
567X LOGICAL FONT DESCRIPTION (XLFD)
568 *XLFD*
569XLFD is the X font name and contains the information about the font size,
570charset, etc. The name is in this format:
571
572FOUNDRY-FAMILY-WEIGHT-SLANT-WIDTH-STYLE-PIXEL-POINT-X-Y-SPACE-AVE-CR-CE
573
574Each field means:
575
576- FOUNDRY: FOUNDRY field. The company that created the font.
577- FAMILY: FAMILY_NAME field. Basic font family name. (helvetica, gothic,
578 times, etc)
579- WEIGHT: WEIGHT_NAME field. How thick the letters are. (light, medium,
580 bold, etc)
581- SLANT: SLANT field.
582 r: Roman (no slant)
583 i: Italic
584 o: Oblique
585 ri: Reverse Italic
586 ro: Reverse Oblique
587 ot: Other
588 number: Scaled font
589- WIDTH: SETWIDTH_NAME field. Width of characters. (normal, condensed,
590 narrow, double wide)
591- STYLE: ADD_STYLE_NAME field. Extra info to describe font. (Serif, Sans
592 Serif, Informal, Decorated, etc)
593- PIXEL: PIXEL_SIZE field. Height, in pixels, of characters.
594- POINT: POINT_SIZE field. Ten times height of characters in points.
595- X: RESOLUTION_X field. X resolution (dots per inch).
596- Y: RESOLUTION_Y field. Y resolution (dots per inch).
597- SPACE: SPACING field.
598 p: Proportional
599 m: Monospaced
600 c: CharCell
601- AVE: AVERAGE_WIDTH field. Ten times average width in pixels.
602- CR: CHARSET_REGISTRY field. The name of the charset group.
603- CE: CHARSET_ENCODING field. The rest of the charset name. For some
604 charsets, such as JIS X 0208, if this field is 0, code points has
605 the same value as GL, and GR if 1.
606
Bram Moolenaar30b65812012-07-12 22:01:11 +0200607For example, in case of a 16 dots font corresponding to JIS X 0208, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608written like:
609 -misc-fixed-medium-r-normal--16-110-100-100-c-160-jisx0208.1990-0
610
611
612X FONTSET
613 *fontset* *xfontset*
Bram Moolenaar207f0092020-08-30 17:20:20 +0200614A single-byte charset is typically associated with one font. For multibyte
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615charsets a combination of fonts is often used. This means that one group of
616characters are used from one font and another group from another font (which
617might be double wide). This collection of fonts is called a fontset.
618
619Which fonts are required in a fontset depends on the current locale. X
620windows maintains a table of which groups of characters are required for a
621locale. You have to specify all the fonts that a locale requires in the
622'guifontset' option.
623
Bram Moolenaarf720d0a2019-04-28 14:02:47 +0200624Setting the 'guifontset' option also means that all font names will be handled
625as a fontset name. Also the ones used for the "font" argument of the
626|:highlight| command.
627
628Note the difference between 'guifont' and 'guifontset': In 'guifont'
629the comma-separated names are alternative names, one of which will be
630used. In 'guifontset' the whole string is one fontset name,
631including the commas. It is not possible to specify alternative
632fontset names.
633This example works on many X11 systems: >
634 :set guifontset=-*-*-medium-r-normal--16-*-*-*-c-*-*-*
635<
636The fonts must match with the current locale. If fonts for the character sets
637that the current locale uses are not included, setting 'guifontset' will fail.
638
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639NOTE: The fontset always uses the current locale, even though 'encoding' may
640be set to use a different charset. In that situation you might want to use
641'guifont' and 'guifontwide' instead of 'guifontset'.
642
643Example:
644 |charset| language "groups of characters" ~
645 GB2312 Chinese (simplified) ISO-8859-1 and GB 2312
646 Big5 Chinese (traditional) ISO-8859-1 and Big5
647 CNS-11643 Chinese (traditional) ISO-8859-1, CNS 11643-1 and CNS 11643-2
648 EUC-JP Japanese JIS X 0201 and JIS X 0208
649 EUC-KR Korean ISO-8859-1 and KS C 5601 (KS X 1001)
650
651You can search for fonts using the xlsfonts command. For example, when you're
652searching for a font for KS C 5601: >
653 xlsfonts | grep ksc5601
654
655This is complicated and confusing. You might want to consult the X-Windows
656documentation if there is something you don't understand.
657
658 *base_font_name_list*
659When you have found the names of the fonts you want to use, you need to set
660the 'guifontset' option. You specify the list by concatenating the font names
661and putting a comma in between them.
662
663For example, when you use the ja_JP.eucJP locale, this requires JIS X 0201
664and JIS X 0208. You could supply a list of fonts that explicitly specifies
665the charsets, like: >
666
667 :set guifontset=-misc-fixed-medium-r-normal--14-130-75-75-c-140-jisx0208.1983-0,
668 \-misc-fixed-medium-r-normal--14-130-75-75-c-70-jisx0201.1976-0
669
670Alternatively, you can supply a base font name list that omits the charset
671name, letting X-Windows select font characters required for the locale. For
672example: >
673
674 :set guifontset=-misc-fixed-medium-r-normal--14-130-75-75-c-140,
675 \-misc-fixed-medium-r-normal--14-130-75-75-c-70
676
677Alternatively, you can supply a single base font name that allows X-Windows to
678select from all available fonts. For example: >
679
680 :set guifontset=-misc-fixed-medium-r-normal--14-*
681
682Alternatively, you can specify alias names. See the fonts.alias file in the
683fonts directory (e.g., /usr/X11R6/lib/X11/fonts/). For example: >
684
685 :set guifontset=k14,r14
686<
687 *E253*
688Note that in East Asian fonts, the standard character cell is square. When
689mixing a Latin font and an East Asian font, the East Asian font width should
690be twice the Latin font width.
691
692If 'guifontset' is not empty, the "font" argument of the |:highlight| command
693is also interpreted as a fontset. For example, you should use for
694highlighting: >
695 :hi Comment font=english_font,your_font
696If you use a wrong "font" argument you will get an error message.
697Also make sure that you set 'guifontset' before setting fonts for highlight
698groups.
699
700
701USING RESOURCE FILES
702
703Instead of specifying 'guifontset', you can set X11 resources and Vim will
704pick them up. This is only for people who know how X resource files work.
705
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +0100706For Motif insert these three lines in your $HOME/.Xdefaults file:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707
708 Vim.font: |base_font_name_list|
709 Vim*fontSet: |base_font_name_list|
710 Vim*fontList: your_language_font
711
712Note: Vim.font is for text area.
713 Vim*fontSet is for menu.
714 Vim*fontList is for menu (for Motif GUI)
715
716For example, when you are using Japanese and a 14 dots font, >
717
718 Vim.font: -misc-fixed-medium-r-normal--14-*
719 Vim*fontSet: -misc-fixed-medium-r-normal--14-*
720 Vim*fontList: -misc-fixed-medium-r-normal--14-*
721<
722or: >
723
724 Vim*font: k14,r14
725 Vim*fontSet: k14,r14
726 Vim*fontList: k14,r14
727<
728To have them take effect immediately you will have to do >
729
730 xrdb -merge ~/.Xdefaults
731
732Otherwise you will have to stop and restart the X server before the changes
733take effect.
734
735
736The GTK+ version of GUI Vim does not use .Xdefaults, use ~/.gtkrc instead.
737The default mostly works OK. But for the menus you might have to change
738it. Example: >
739
740 style "default"
741 {
742 fontset="-*-*-medium-r-normal--14-*-*-*-c-*-*-*"
743 }
744 widget_class "*" style "default"
745
746==============================================================================
7476. Fonts on MS-Windows *mbyte-fonts-MSwin*
748
749The simplest is to use the font dialog to select fonts and try them out. You
750can find this at the "Edit/Select Font..." menu. Once you find a font name
751that works well you can use this command to see its name: >
752
753 :set guifont
754
755Then add a command to your |gvimrc| file to set 'guifont': >
756
757 :set guifont=courier_new:h12
758
759==============================================================================
7607. Input on X11 *mbyte-XIM*
761
762X INPUT METHOD (XIM) BACKGROUND *XIM* *xim* *x-input-method*
763
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200764XIM is an international input module for X. There are two kinds of structures,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765Xlib unit type and |IM-server| (Input-Method server) type. |IM-server| type
766is suitable for complex input, such as CJK.
767
768- IM-server
769 *IM-server*
770 In |IM-server| type input structures, the input event is handled by either
771 of the two ways: FrontEnd system and BackEnd system. In the FrontEnd
772 system, input events are snatched by the |IM-server| first, then |IM-server|
773 give the application the result of input. On the other hand, the BackEnd
Bram Moolenaar130cbfc2021-04-07 21:07:20 +0200774 system works reverse order. MS-Windows adopt BackEnd system. In X, most of
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775 |IM-server|s adopt FrontEnd system. The demerit of BackEnd system is the
776 large overhead in communication, but it provides safe synchronization with
777 no restrictions on applications.
778
779 For example, there are xwnmo and kinput2 Japanese |IM-server|, both are
780 FrontEnd system. Xwnmo is distributed with Wnn (see below), kinput2 can be
Christian Brabandt1c5728e2024-05-11 11:12:40 +0200781 found at (link seems dead): ftp://ftp.sra.co.jp/pub/x11/kinput2/
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782
783 For Chinese, there's a great XIM server named "xcin", you can input both
784 Traditional and Simplified Chinese characters. And it can accept other
Christian Brabandt1c5728e2024-05-11 11:12:40 +0200785 locale if you make a correct input table. Xcin can be found at (link seems
786 dead): http://cle.linux.org.tw/xcin/
787 Others are scim: https://www.freedesktop.org/wiki/Software/scim/ and fcitx:
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000788 http://www.fcitx.org/
Bram Moolenaar071d4272004-06-13 20:20:40 +0000789
790- Conversion Server
791 *conversion-server*
792 Some system needs additional server: conversion server. Most of Japanese
793 |IM-server|s need it, Kana-Kanji conversion server. For Chinese inputting,
794 it depends on the method of inputting, in some methods, PinYin or ZhuYin to
795 HanZi conversion server is needed. For Korean inputting, if you want to
796 input Hanja, Hangul-Hanja conversion server is needed.
797
798 For example, the Japanese inputting process is divided into 2 steps. First
799 we pre-input Hira-gana, second Kana-Kanji conversion. There are so many
800 Kanji characters (6349 Kanji characters are defined in JIS X 0208) and the
801 number of Hira-gana characters are 76. So, first, we pre-input text as
802 pronounced in Hira-gana, second, we convert Hira-gana to Kanji or Kata-Kana,
803 if needed. There are some Kana-Kanji conversion server: jserver
h-east9c4389a2024-06-09 16:32:19 +0200804 (distributed with Wnn, see below) and canna. Canna can be found at:
Christian Brabandt1c5728e2024-05-11 11:12:40 +0200805 https://osdn.net/projects/canna/
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806
807There is a good input system: Wnn4.2. Wnn 4.2 contains,
808 xwnmo (|IM-server|)
809 jserver (Japanese Kana-Kanji conversion server)
810 cserver (Chinese PinYin or ZhuYin to simplified HanZi conversion server)
811 tserver (Chinese PinYin or ZhuYin to traditional HanZi conversion server)
812 kserver (Hangul-Hanja conversion server)
813Wnn 4.2 for several systems can be found at various places on the internet.
814Use the RPM or port for your system.
815
816
817- Input Style
818 *xim-input-style*
819 When inputting CJK, there are four areas:
820 1. The area to display of the input while it is being composed
821 2. The area to display the currently active input mode.
822 3. The area to display the next candidate for the selection.
823 4. The area to display other tools.
824
825 The third area is needed when converting. For example, in Japanese
826 inputting, multiple Kanji characters could have the same pronunciation, so
827 a sequence of Hira-gana characters could map to a distinct sequence of Kanji
828 characters.
829
830 The first and second areas are defined in international input of X with the
831 names of "Preedit Area", "Status Area" respectively. The third and fourth
832 areas are not defined and are left to be managed by the |IM-server|. In the
833 international input, four input styles have been defined using combinations
834 of Preedit Area and Status Area: |OnTheSpot|, |OffTheSpot|, |OverTheSpot|
835 and |Root|.
836
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200837 Currently, GUI Vim supports three styles, |OverTheSpot|, |OffTheSpot| and
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838 |Root|.
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +0200839 When compiled with |+GUI_GTK| feature, GUI Vim supports two styles,
840 |OnTheSpot| and |OverTheSpot|. You can select the style with the 'imstyle'
841 option.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000842
843*. on-the-spot *OnTheSpot*
844 Preedit Area and Status Area are performed by the client application in
845 the area of application. The client application is directed by the
846 |IM-server| to display all pre-edit data at the location of text
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000847 insertion. The client registers callbacks invoked by the input method
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 during pre-editing.
849*. over-the-spot *OverTheSpot*
850 Status Area is created in a fixed position within the area of application,
851 in case of Vim, the position is the additional status line. Preedit Area
852 is made at present input position of application. The input method
853 displays pre-edit data in a window which it brings up directly over the
854 text insertion position.
855*. off-the-spot *OffTheSpot*
856 Preedit Area and Status Area are performed in the area of application, in
857 case of Vim, the area is additional status line. The client application
858 provides display windows for the pre-edit data to the input method which
859 displays into them directly.
860*. root-window *Root*
861 Preedit Area and Status Area are outside of the application. The input
862 method displays all pre-edit data in a separate area of the screen in a
863 window specific to the input method.
864
865
Bram Moolenaar2f0936c2022-01-08 21:51:59 +0000866USING XIM *multibyte-input* *E284* *E285* *E286* *E287*
867 *E288* *E289*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868
869Note that Display and Input are independent. It is possible to see your
870language even though you have no input method for it. But when your Display
871method doesn't match your Input method, the text will be displayed wrong.
872
873 Note: You can not use IM unless you specify 'guifontset'.
874 Therefore, Latin users, you have to also use 'guifontset'
875 if you use IM.
876
877To input your language you should run the |IM-server| which supports your
878language and |conversion-server| if needed.
879
880The next 3 lines should be put in your ~/.Xdefaults file. They are common for
881all X applications which uses |XIM|. If you already use |XIM|, you can skip
882this. >
883
884 *international: True
885 *.inputMethod: your_input_server_name
886 *.preeditType: your_input_style
887<
888input_server_name is your |IM-server| name (check your |IM-server|
889 manual).
890your_input_style is one of |OverTheSpot|, |OffTheSpot|, |Root|. See
891 also |xim-input-style|.
892
Bram Moolenaar2547aa92020-07-26 17:00:44 +0200893*international may not be necessary if you use X11R6.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894*.inputMethod and *.preeditType are optional if you use X11R6.
895
896For example, when you are using kinput2 as |IM-server|, >
897
898 *international: True
899 *.inputMethod: kinput2
900 *.preeditType: OverTheSpot
901<
902When using |OverTheSpot|, GUI Vim always connects to the IM Server even in
903Normal mode, so you can input your language with commands like "f" and "r".
904But when using one of the other two methods, GUI Vim connects to the IM Server
905only if it is not in Normal mode.
906
907If your IM Server does not support |OverTheSpot|, and if you want to use your
908language with some Normal mode command like "f" or "r", then you should use a
909localized xterm or an xterm which supports |XIM|
910
911If needed, you can set the XMODIFIERS environment variable:
912
913 sh: export XMODIFIERS="@im=input_server_name"
914 csh: setenv XMODIFIERS "@im=input_server_name"
915
916For example, when you are using kinput2 as |IM-server| and sh, >
917
918 export XMODIFIERS="@im=kinput2"
919<
920
921FULLY CONTROLLED XIM
922
923You can fully control XIM, like with IME of MS-Windows (see |multibyte-ime|).
924This is currently only available for the GTK GUI.
925
926Before using fully controlled XIM, one setting is required. Set the
927'imactivatekey' option to the key that is used for the activation of the input
928method. For example, when you are using kinput2 + canna as IM Server, the
929activation key is probably Shift+Space: >
930
931 :set imactivatekey=S-space
932
933See 'imactivatekey' for the format.
934
935==============================================================================
9368. Input on MS-Windows *mbyte-IME*
937
938(Windows IME support) *multibyte-ime* *IME*
939
940{only works Windows GUI and compiled with the |+multi_byte_ime| feature}
941
Bram Moolenaar0ed0eea2010-07-26 22:21:27 +0200942To input multibyte characters on Windows, you can use an Input Method Editor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943(IME). In process of your editing text, you must switch status (on/off) of
944IME many many many times. Because IME with status on is hooking all of your
945key inputs, you cannot input 'j', 'k', or almost all of keys to Vim directly.
946
Bram Moolenaar396e8292019-07-13 23:04:31 +0200947The |+multi_byte_ime| feature helps for this. It reduces the number of times
948the IME status has to be switched manually. In Normal mode, there is almost
949no need to use IME, even when editing multibyte text. So when exiting Insert
950mode, Vim memorizes the last status of IME and turns off IME. When
951re-entering Insert mode, Vim sets the IME status to that memorized status
952automatically.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953
954This works on not only insert-normal mode, but also search-command input and
955replace mode.
Bram Moolenaar2547aa92020-07-26 17:00:44 +0200956The options 'iminsert', 'imsearch' and 'imcmdline' can be used to choose
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000957the different input methods or disable them temporarily.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000958
K.Takata4ac893f2022-01-20 12:44:28 +0000959On Windows 9x and Windows NT 4.0 there was *global-ime* , but this is no
960longer supported. You can still find documentation for Active Input Method
961Manager (Global IME) here:
Bram Moolenaara17d4c12010-05-30 18:30:36 +0200962 http://msdn.microsoft.com/en-us/library/aa741221(v=VS.85).aspx
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964NOTE: For IME to work you must make sure the input locales of your language
965are added to your system. The exact location of this depends on the version
Bram Moolenaar446cb832008-06-24 21:56:24 +0000966of Windows you use. For example, on my Windows 2000 box:
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671. Control Panel
9682. Regional Options
9693. Input Locales Tab
9704. Add Installed input locales -> Chinese(PRC)
971 The default is still English (United Stated)
972
973
974Cursor color when IME or XIM is on *CursorIM*
975 There is a little cute feature for IME. Cursor can indicate status of IME
976 by changing its color. Usually status of IME was indicated by little icon
977 at a corner of desktop (or taskbar). It is not easy to verify status of
978 IME. But this feature help this.
979 This works in the same way when using XIM.
980
981 You can select cursor color when status is on by using highlight group
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000982 CursorIM. For example, add these lines to your |gvimrc|: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983
984 if has('multi_byte_ime')
985 highlight Cursor guifg=NONE guibg=Green
986 highlight CursorIM guifg=NONE guibg=Purple
987 endif
988<
989 Cursor color with off IME is green. And purple cursor indicates that
990 status is on.
991
992==============================================================================
9939. Input with a keymap *mbyte-keymap*
994
995When the keyboard doesn't produce the characters you want to enter in your
996text, you can use the 'keymap' option. This will translate one or more
997(English) characters to another (non-English) character. This only happens
998when typing text, not when typing Vim commands. This avoids having to switch
999between two keyboard settings.
Bram Moolenaar6f1d9a02016-07-24 14:12:38 +02001000{only available when compiled with the |+keymap| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001
1002The value of the 'keymap' option specifies a keymap file to use. The name of
1003this file is one of these two:
1004
1005 keymap/{keymap}_{encoding}.vim
1006 keymap/{keymap}.vim
1007
1008Here {keymap} is the value of the 'keymap' option and {encoding} of the
1009'encoding' option. The file name with the {encoding} included is tried first.
1010
1011'runtimepath' is used to find these files. To see an overview of all
1012available keymap files, use this: >
1013 :echo globpath(&rtp, "keymap/*.vim")
1014
1015In Insert and Command-line mode you can use CTRL-^ to toggle between using the
1016keyboard map or not. |i_CTRL-^| |c_CTRL-^|
1017This flag is remembered for Insert mode with the 'iminsert' option. When
1018leaving and entering Insert mode the previous value is used. The same value
1019is also used for commands that take a single character argument, like |f| and
1020|r|.
1021For Command-line mode the flag is NOT remembered. You are expected to type an
1022Ex command first, which is ASCII.
1023For typing search patterns the 'imsearch' option is used. It can be set to
1024use the same value as for 'iminsert'.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001025 *lCursor*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026It is possible to give the GUI cursor another color when the language mappings
1027are being used. This is disabled by default, to avoid that the cursor becomes
1028invisible when you use a non-standard background color. Here is an example to
1029use a brightly colored cursor: >
1030 :highlight Cursor guifg=NONE guibg=Green
1031 :highlight lCursor guifg=NONE guibg=Cyan
1032<
Bram Moolenaar57657d82006-04-21 22:12:41 +00001033 *keymap-file-format* *:loadk* *:loadkeymap* *E105* *E791*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034The keymap file looks something like this: >
1035
1036 " Maintainer: name <email@address>
1037 " Last Changed: 2001 Jan 1
1038
1039 let b:keymap_name = "short"
1040
1041 loadkeymap
1042 a A
1043 b B comment
1044
1045The lines starting with a " are comments and will be ignored. Blank lines are
1046also ignored. The lines with the mappings may have a comment after the useful
1047text.
1048
1049The "b:keymap_name" can be set to a short name, which will be shown in the
1050status line. The idea is that this takes less room than the value of
1051'keymap', which might be long to distinguish between different languages,
1052keyboards and encodings.
1053
1054The actual mappings are in the lines below "loadkeymap". In the example "a"
1055is mapped to "A" and "b" to "B". Thus the first item is mapped to the second
1056item. This is done for each line, until the end of the file.
1057These items are exactly the same as what can be used in a |:lnoremap| command,
Bram Moolenaar34700a62013-03-07 13:20:54 +01001058using "<buffer>" to make the mappings local to the buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059You can check the result with this command: >
1060 :lmap
1061The two items must be separated by white space. You cannot include white
1062space inside an item, use the special names "<Tab>" and "<Space>" instead.
1063The length of the two items together must not exceed 200 bytes.
1064
1065It's possible to have more than one character in the first column. This works
1066like a dead key. Example: >
1067 'a á
1068Since Vim doesn't know if the next character after a quote is really an "a",
1069it will wait for the next character. To be able to insert a single quote,
1070also add this line: >
1071 '' '
1072Since the mapping is defined with |:lnoremap| the resulting quote will not be
1073used for the start of another character.
Bram Moolenaare2f98b92006-03-29 21:18:24 +00001074The "accents" keymap uses this. *keymap-accents*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075
Bram Moolenaar3a0d8092012-10-21 03:02:54 +02001076The first column can also be in |<>| form:
1077 <C-c> Ctrl-C
1078 <A-c> Alt-c
1079 <A-C> Alt-C
1080Note that the Alt mappings may not work, depending on your keyboard and
1081terminal.
1082
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083Although it's possible to have more than one character in the second column,
1084this is unusual. But you can use various ways to specify the character: >
1085 A a literal character
1086 A <char-97> decimal value
1087 A <char-0x61> hexadecimal value
1088 A <char-0141> octal value
1089 x <Space> special key name
1090
1091The characters are assumed to be encoded for the current value of 'encoding'.
1092It's possible to use ":scriptencoding" when all characters are given
1093literally. That doesn't work when using the <char-> construct, because the
1094conversion is done on the keymap file, not on the resulting character.
1095
1096The lines after "loadkeymap" are interpreted with 'cpoptions' set to "C".
1097This means that continuation lines are not used and a backslash has a special
1098meaning in the mappings. Examples: >
1099
1100 " a comment line
1101 \" x maps " to x
1102 \\ y maps \ to y
1103
1104If you write a keymap file that will be useful for others, consider submitting
1105it to the Vim maintainer for inclusion in the distribution:
1106<maintainer@vim.org>
1107
1108
1109HEBREW KEYMAP *keymap-hebrew*
1110
1111This file explains what characters are available in UTF-8 and CP1255 encodings,
1112and what the keymaps are to get those characters:
1113
1114glyph encoding keymap ~
Bram Moolenaar6e649222021-10-04 21:32:54 +01001115Char UTF-8 cp1255 hebrew hebrewp name ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116א 0x5d0 0xe0 t a 'alef
1117ב 0x5d1 0xe1 c b bet
1118ג 0x5d2 0xe2 d g gimel
1119ד 0x5d3 0xe3 s d dalet
1120ה 0x5d4 0xe4 v h he
1121ו 0x5d5 0xe5 u v vav
1122ז 0x5d6 0xe6 z z zayin
1123ח 0x5d7 0xe7 j j het
1124ט 0x5d8 0xe8 y T tet
1125י 0x5d9 0xe9 h y yod
1126ך 0x5da 0xea l K kaf sofit
1127כ 0x5db 0xeb f k kaf
1128ל 0x5dc 0xec k l lamed
1129ם 0x5dd 0xed o M mem sofit
1130מ 0x5de 0xee n m mem
1131ן 0x5df 0xef i N nun sofit
1132נ 0x5e0 0xf0 b n nun
1133ס 0x5e1 0xf1 x s samech
1134ע 0x5e2 0xf2 g u `ayin
1135ף 0x5e3 0xf3 ; P pe sofit
1136פ 0x5e4 0xf4 p p pe
1137ץ 0x5e5 0xf5 . X tsadi sofit
1138צ 0x5e6 0xf6 m x tsadi
1139ק 0x5e7 0xf7 e q qof
1140ר 0x5e8 0xf8 r r resh
1141ש 0x5e9 0xf9 a w shin
1142ת 0x5ea 0xfa , t tav
1143
1144Vowel marks and special punctuation:
1145הְ 0x5b0 0xc0 A: A: sheva
1146הֱ 0x5b1 0xc1 HE HE hataf segol
1147הֲ 0x5b2 0xc2 HA HA hataf patah
1148הֳ 0x5b3 0xc3 HO HO hataf qamats
1149הִ 0x5b4 0xc4 I I hiriq
1150הֵ 0x5b5 0xc5 AY AY tsere
1151הֶ 0x5b6 0xc6 E E segol
1152הַ 0x5b7 0xc7 AA AA patah
1153הָ 0x5b8 0xc8 AO AO qamats
1154הֹ 0x5b9 0xc9 O O holam
1155הֻ 0x5bb 0xcb U U qubuts
1156כּ 0x5bc 0xcc D D dagesh
1157הֽ 0x5bd 0xcd ]T ]T meteg
1158ה־ 0x5be 0xce ]Q ]Q maqaf
1159בֿ 0x5bf 0xcf ]R ]R rafe
1160ב׀ 0x5c0 0xd0 ]p ]p paseq
1161שׁ 0x5c1 0xd1 SR SR shin-dot
1162שׂ 0x5c2 0xd2 SL SL sin-dot
1163׃ 0x5c3 0xd3 ]P ]P sof-pasuq
1164װ 0x5f0 0xd4 VV VV double-vav
1165ױ 0x5f1 0xd5 VY VY vav-yod
1166ײ 0x5f2 0xd6 YY YY yod-yod
1167
Bram Moolenaar6e649222021-10-04 21:32:54 +01001168The following are only available in UTF-8
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169
1170Cantillation marks:
1171glyph
Bram Moolenaar6e649222021-10-04 21:32:54 +01001172Char UTF-8 hebrew name
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173ב֑ 0x591 C: etnahta
1174ב֒ 0x592 Cs segol
1175ב֓ 0x593 CS shalshelet
1176ב֔ 0x594 Cz zaqef qatan
1177ב֕ 0x595 CZ zaqef gadol
1178ב֖ 0x596 Ct tipeha
1179ב֗ 0x597 Cr revia
1180ב֘ 0x598 Cq zarqa
1181ב֙ 0x599 Cp pashta
1182ב֚ 0x59a C! yetiv
1183ב֛ 0x59b Cv tevir
1184ב֜ 0x59c Cg geresh
1185ב֝ 0x59d C* geresh qadim
1186ב֞ 0x59e CG gershayim
1187ב֟ 0x59f CP qarnei-parah
1188ב֪ 0x5aa Cy yerach-ben-yomo
1189ב֫ 0x5ab Co ole
1190ב֬ 0x5ac Ci iluy
1191ב֭ 0x5ad Cd dehi
1192ב֮ 0x5ae Cn zinor
1193ב֯ 0x5af CC masora circle
1194
1195Combining forms:
1196ﬠ 0xfb20 X` Alternative `ayin
1197ﬡ 0xfb21 X' Alternative 'alef
1198ﬢ 0xfb22 X-d Alternative dalet
1199ﬣ 0xfb23 X-h Alternative he
1200ﬤ 0xfb24 X-k Alternative kaf
1201ﬥ 0xfb25 X-l Alternative lamed
1202ﬦ 0xfb26 X-m Alternative mem-sofit
1203ﬧ 0xfb27 X-r Alternative resh
1204ﬨ 0xfb28 X-t Alternative tav
1205﬩ 0xfb29 X-+ Alternative plus
1206שׁ 0xfb2a XW shin+shin-dot
1207שׂ 0xfb2b Xw shin+sin-dot
1208שּׁ 0xfb2c X..W shin+shin-dot+dagesh
1209שּׂ 0xfb2d X..w shin+sin-dot+dagesh
1210אַ 0xfb2e XA alef+patah
1211אָ 0xfb2f XO alef+qamats
1212אּ 0xfb30 XI alef+hiriq (mapiq)
1213בּ 0xfb31 X.b bet+dagesh
1214גּ 0xfb32 X.g gimel+dagesh
1215דּ 0xfb33 X.d dalet+dagesh
1216הּ 0xfb34 X.h he+dagesh
1217וּ 0xfb35 Xu vav+dagesh
1218זּ 0xfb36 X.z zayin+dagesh
1219טּ 0xfb38 X.T tet+dagesh
1220יּ 0xfb39 X.y yud+dagesh
1221ךּ 0xfb3a X.K kaf sofit+dagesh
1222כּ 0xfb3b X.k kaf+dagesh
1223לּ 0xfb3c X.l lamed+dagesh
1224מּ 0xfb3e X.m mem+dagesh
1225נּ 0xfb40 X.n nun+dagesh
1226סּ 0xfb41 X.s samech+dagesh
1227ףּ 0xfb43 X.P pe sofit+dagesh
1228פּ 0xfb44 X.p pe+dagesh
1229צּ 0xfb46 X.x tsadi+dagesh
1230קּ 0xfb47 X.q qof+dagesh
1231רּ 0xfb48 X.r resh+dagesh
1232שּ 0xfb49 X.w shin+dagesh
1233תּ 0xfb4a X.t tav+dagesh
1234וֹ 0xfb4b Xo vav+holam
1235בֿ 0xfb4c XRb bet+rafe
1236כֿ 0xfb4d XRk kaf+rafe
1237פֿ 0xfb4e XRp pe+rafe
1238ﭏ 0xfb4f Xal alef-lamed
1239
1240==============================================================================
Bram Moolenaar6315a9a2017-11-25 15:20:02 +0100124110. Input with imactivatefunc() *mbyte-func*
1242
Bram Moolenaar2f058492017-11-30 20:27:52 +01001243Vim has the 'imactivatefunc' and 'imstatusfunc' options. These are useful to
Bram Moolenaar40962ec2018-01-28 22:47:25 +01001244activate/deactivate the input method from Vim in any way, also with an external
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01001245command. For example, fcitx provide fcitx-remote command: >
1246
1247 set iminsert=2
1248 set imsearch=2
1249 set imcmdline
1250
1251 set imactivatefunc=ImActivate
1252 function! ImActivate(active)
1253 if a:active
1254 call system('fcitx-remote -o')
1255 else
1256 call system('fcitx-remote -c')
1257 endif
1258 endfunction
1259
1260 set imstatusfunc=ImStatus
1261 function! ImStatus()
1262 return system('fcitx-remote')[0] is# '2'
1263 endfunction
1264
1265Using this script, you can activate/deactivate XIM via Vim even when it is not
1266compiled with |+xim|.
1267
1268==============================================================================
126911. Using UTF-8 *mbyte-utf8* *UTF-8* *utf-8* *utf8*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 *Unicode* *unicode*
1271The Unicode character set was designed to include all characters from other
1272character sets. Therefore it is possible to write text in any language using
1273Unicode (with a few rarely used languages excluded). And it's mostly possible
1274to mix these languages in one file, which is impossible with other encodings.
1275
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001276Unicode can be encoded in several ways. The most popular one is UTF-8, which
1277uses one or more bytes for each character and is backwards compatible with
1278ASCII. On MS-Windows UTF-16 is also used (previously UCS-2), which uses
127916-bit words. Vim can support all of these encodings, but always uses UTF-8
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280internally.
1281
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001282Vim has comprehensive UTF-8 support. It works well in:
Bram Moolenaar6e649222021-10-04 21:32:54 +01001283- xterm with UTF-8 support enabled
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001284- Motif and GTK GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285- MS-Windows GUI
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001286- several other platforms
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287
1288Double-width characters are supported. This works best with 'guifontwide' or
1289'guifontset'. When using only 'guifont' the wide characters are drawn in the
1290normal width and a space to fill the gap. Note that the 'guifontset' option
1291is no longer relevant in the GTK+ 2 GUI.
1292
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001293 *bom-bytes*
1294When reading a file a BOM (Byte Order Mark) can be used to recognize the
1295Unicode encoding:
Bram Moolenaar6e649222021-10-04 21:32:54 +01001296 EF BB BF UTF-8
1297 FE FF UTF-16 big endian
1298 FF FE UTF-16 little endian
1299 00 00 FE FF UTF-32 big endian
1300 FF FE 00 00 UTF-32 little endian
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001301
Bram Moolenaar6e649222021-10-04 21:32:54 +01001302UTF-8 is the recommended encoding. Note that it's difficult to tell utf-16
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001303and utf-32 apart. Utf-16 is often used on MS-Windows, utf-32 is not
1304widespread as file format.
1305
1306
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001307 *mbyte-combining* *mbyte-composing*
1308A composing or combining character is used to change the meaning of the
1309character before it. The combining characters are drawn on top of the
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00001310preceding character.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001311Up to two combining characters can be used by default. This can be changed
1312with the 'maxcombine' option.
1313When editing text a composing character is mostly considered part of the
1314preceding character. For example "x" will delete a character and its
1315following composing characters by default.
1316If the 'delcombine' option is on, then pressing 'x' will delete the combining
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317characters, one at a time, then the base character. But when inserting, you
1318type the first character and the following composing characters separately,
1319after which they will be joined. The "r" command will not allow you to type a
1320combining character, because it doesn't know one is coming. Use "R" instead.
1321
1322Bytes which are not part of a valid UTF-8 byte sequence are handled like a
1323single character and displayed as <xx>, where "xx" is the hex value of the
1324byte.
1325
1326Overlong sequences are not handled specially and displayed like a valid
1327character. However, search patterns may not match on an overlong sequence.
1328(an overlong sequence is where more bytes are used than required for the
1329character.) An exception is NUL (zero) which is displayed as "<00>".
1330
1331In the file and buffer the full range of Unicode characters can be used (31
Bram Moolenaar97293012011-07-18 19:40:27 +02001332bits). However, displaying only works for the characters present in the
1333selected font.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334
1335Useful commands:
1336- "ga" shows the decimal, hexadecimal and octal value of the character under
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00001337 the cursor. If there are composing characters these are shown too. (If the
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338 message is truncated, use ":messages").
1339- "g8" shows the bytes used in a UTF-8 character, also the composing
1340 characters, as hex numbers.
1341- ":set encoding=utf-8 fileencodings=" forces using UTF-8 for all files. The
1342 default is to use the current locale for 'encoding' and set 'fileencodings'
Bram Moolenaar446cb832008-06-24 21:56:24 +00001343 to automatically detect the encoding of a file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344
1345
1346STARTING VIM
1347
Bram Moolenaar6e649222021-10-04 21:32:54 +01001348If your current locale is in an UTF-8 encoding, Vim will automatically start
1349in UTF-8 mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350
1351If you are using another locale: >
1352
1353 set encoding=utf-8
1354
1355You might also want to select the font used for the menus. Unfortunately this
1356doesn't always work. See the system specific remarks below, and 'langmenu'.
1357
1358
h-east9c4389a2024-06-09 16:32:19 +02001359USING UTF-8 IN X-WINDOWS *utf-8-in-xwindows*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360
1361Note: This section does not apply to the GTK+ 2 GUI.
1362
1363You need to specify a font to be used. For double-wide characters another
1364font is required, which is exactly twice as wide. There are three ways to do
1365this:
1366
13671. Set 'guifont' and let Vim find a matching 'guifontwide'
13682. Set 'guifont' and 'guifontwide'
13693. Set 'guifontset'
1370
1371See the documentation for each option for details. Example: >
1372
1373 :set guifont=-misc-fixed-medium-r-normal--15-140-75-75-c-90-iso10646-1
1374
1375You might also want to set the font used for the menus. This only works for
1376Motif. Use the ":hi Menu font={fontname}" command for this. |:highlight|
1377
1378
1379TYPING UTF-8 *utf-8-typing*
1380
1381If you are using X-Windows, you should find an input method that supports
Christian Brabandtd24aaa92024-07-17 08:25:45 +02001382the UTF-8 encoding.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383
Bram Moolenaar6e649222021-10-04 21:32:54 +01001384If your system does not provide support for typing UTF-8, you can use the
1385'keymap' feature. This allows writing a keymap file, which defines a UTF-8
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386character as a sequence of ASCII characters. See |mbyte-keymap|.
1387
1388Another method is to set the current locale to the language you want to use
1389and for which you have a XIM available. Then set 'termencoding' to that
1390language and Vim will convert the typed characters to 'encoding' for you.
1391
1392If everything else fails, you can type any character as four hex bytes: >
1393
1394 CTRL-V u 1234
1395
1396"1234" is interpreted as a hex number. You must type four characters, prepend
1397a zero if necessary.
1398
1399
1400COMMAND ARGUMENTS *utf-8-char-arg*
1401
1402Commands like |f|, |F|, |t| and |r| take an argument of one character. For
Bram Moolenaardf177f62005-02-22 08:39:57 +00001403UTF-8 this argument may include one or two composing characters. These need
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404to be produced together with the base character, Vim doesn't wait for the next
1405character to be typed to find out if it is a composing character or not.
1406Using 'keymap' or |:lmap| is a nice way to type these characters.
1407
1408The commands that search for a character in a line handle composing characters
1409as follows. When searching for a character without a composing character,
1410this will find matches in the text with or without composing characters. When
1411searching for a character with a composing character, this will only find
1412matches with that composing character. It was implemented this way, because
1413not everybody is able to type a composing character.
1414
1415
1416==============================================================================
Bram Moolenaar6315a9a2017-11-25 15:20:02 +0100141712. Overview of options *mbyte-options*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418
Bram Moolenaar207f0092020-08-30 17:20:20 +02001419These options are relevant for editing multibyte files. Check the help in
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420options.txt for detailed information.
1421
1422'encoding' Encoding used for the keyboard and display. It is also the
1423 default encoding for files.
1424
1425'fileencoding' Encoding of a file. When it's different from 'encoding'
1426 conversion is done when reading or writing the file.
1427
1428'fileencodings' List of possible encodings of a file. When opening a file
1429 these will be tried and the first one that doesn't cause an
1430 error is used for 'fileencoding'.
1431
1432'charconvert' Expression used to convert files from one encoding to another.
1433
1434'formatoptions' The 'm' flag can be included to have formatting break a line
1435 at a multibyte character of 256 or higher. Thus is useful for
1436 languages where a sequence of characters can be broken
1437 anywhere.
1438
Bram Moolenaar207f0092020-08-30 17:20:20 +02001439'guifontset' The list of font names used for a multibyte encoding. When
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 this option is not empty, it replaces 'guifont'.
1441
1442'keymap' Specify the name of a keyboard mapping.
1443
1444==============================================================================
1445
Bram Moolenaar207f0092020-08-30 17:20:20 +02001446Contributions specifically for the multibyte features by:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 Chi-Deok Hwang <hwang@mizi.co.kr>
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +01001448 SungHyun Nam <goweol@gmail.com>
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 K.Nagano <nagano@atese.advantest.co.jp>
1450 Taro Muraoka <koron@tka.att.ne.jp>
1451 Yasuhiro Matsumoto <mattn@mail.goo.ne.jp>
1452
Bram Moolenaar91f84f62018-07-29 15:07:52 +02001453 vim:tw=78:ts=8:noet:ft=help:norl: