usr_45.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. *usr_45.txt* For Vim version 9.0. Last change: 2022 May 13
  2. VIM USER MANUAL - by Bram Moolenaar
  3. Select your language (locale)
  4. The messages in Vim can be given in several languages. This chapter explains
  5. how to change which one is used. Also, the different ways to work with files
  6. in various languages is explained.
  7. |45.1| Language for Messages
  8. |45.2| Language for Menus
  9. |45.3| Using another encoding
  10. |45.4| Editing files with a different encoding
  11. |45.5| Entering language text
  12. Next chapter: |usr_50.txt| Advanced Vim script writing
  13. Previous chapter: |usr_44.txt| Your own syntax highlighted
  14. Table of contents: |usr_toc.txt|
  15. ==============================================================================
  16. *45.1* Language for Messages
  17. When you start Vim, it checks the environment to find out what language you
  18. are using. Mostly this should work fine, and you get the messages in your
  19. language (if they are available). To see what the current language is, use
  20. this command: >
  21. :language
  22. If it replies with "C", this means the default is being used, which is
  23. English.
  24. Note:
  25. Using different languages only works when Vim was compiled to handle
  26. it. To find out if it works, use the ":version" command and check the
  27. output for "+gettext" and "+multi_lang". If they are there, you are
  28. OK. If you see "-gettext" or "-multi_lang" you will have to find
  29. another Vim.
  30. What if you would like your messages in a different language? There are
  31. several ways. Which one you should use depends on the capabilities of your
  32. system.
  33. The first way is to set the environment to the desired language before
  34. starting Vim. Example for Unix: >
  35. env LANG=de_DE.ISO_8859-1 vim
  36. This only works if the language is available on your system. The advantage is
  37. that all the GUI messages and things in libraries will use the right language
  38. as well. A disadvantage is that you must do this before starting Vim. If you
  39. want to change language while Vim is running, you can use the second method: >
  40. :language fr_FR.ISO_8859-1
  41. This way you can try out several names for your language. You will get an
  42. error message when it's not supported on your system. You don't get an error
  43. when translated messages are not available. Vim will silently fall back to
  44. using English.
  45. To find out which languages are supported on your system, find the
  46. directory where they are listed. On my system it is "/usr/share/locale". On
  47. some systems it's in "/usr/lib/locale". The manual page for "setlocale"
  48. should give you a hint where it is found on your system.
  49. Be careful to type the name exactly as it should be. Upper and lowercase
  50. matter, and the '-' and '_' characters are easily confused.
  51. You can also set the language separately for messages, edited text and the
  52. time format. See |:language|.
  53. DO-IT-YOURSELF MESSAGE TRANSLATION
  54. If translated messages are not available for your language, you could write
  55. them yourself. To do this, get the source code for Vim and the GNU gettext
  56. package. After unpacking the sources, instructions can be found in the
  57. directory src/po/README.txt.
  58. It's not too difficult to do the translation. You don't need to be a
  59. programmer. You must know both English and the language you are translating
  60. to, of course.
  61. When you are satisfied with the translation, consider making it available
  62. to others. Upload it at vim-online (http://vim.sf.net) or e-mail it to
  63. the Vim maintainer <maintainer@vim.org>. Or both.
  64. ==============================================================================
  65. *45.2* Language for Menus
  66. The default menus are in English. To be able to use your local language, they
  67. must be translated. Normally this is automatically done for you if the
  68. environment is set for your language, just like with messages. You don't need
  69. to do anything extra for this. But it only works if translations for the
  70. language are available.
  71. Suppose you are in Germany, with the language set to German, but prefer to
  72. use "File" instead of "Datei". You can switch back to using the English menus
  73. this way: >
  74. :set langmenu=none
  75. It is also possible to specify a language: >
  76. :set langmenu=nl_NL.ISO_8859-1
  77. Like above, differences between "-" and "_" matter. However, upper/lowercase
  78. differences are ignored here.
  79. The 'langmenu' option must be set before the menus are loaded. Once the
  80. menus have been defined changing 'langmenu' has no direct effect. Therefore,
  81. put the command to set 'langmenu' in your vimrc file.
  82. If you really want to switch menu language while running Vim, you can do it
  83. this way: >
  84. :source $VIMRUNTIME/delmenu.vim
  85. :set langmenu=de_DE.ISO_8859-1
  86. :source $VIMRUNTIME/menu.vim
  87. There is one drawback: All menus that you defined yourself will be gone. You
  88. will need to redefine them as well.
  89. DO-IT-YOURSELF MENU TRANSLATION
  90. To see which menu translations are available, look in this directory:
  91. $VIMRUNTIME/lang ~
  92. The files are called menu_{language}.vim. If you don't see the language you
  93. want to use, you can do your own translations. The simplest way to do this is
  94. by copying one of the existing language files, and change it.
  95. First find out the name of your language with the ":language" command. Use
  96. this name, but with all letters made lowercase. Then copy the file to your
  97. own runtime directory, as found early in 'runtimepath'. For example, for Unix
  98. you would do: >
  99. :!cp $VIMRUNTIME/lang/menu_ko_kr.euckr.vim ~/.vim/lang/menu_nl_be.iso_8859-1.vim
  100. You will find hints for the translation in "$VIMRUNTIME/lang/README.txt".
  101. ==============================================================================
  102. *45.3* Using another encoding
  103. Vim guesses that the files you are going to edit are encoded for your
  104. language. For many European languages this is "latin1". Then each byte is
  105. one character. That means there are 256 different characters possible. For
  106. Asian languages this is not sufficient. These mostly use a double-byte
  107. encoding, providing for over ten thousand possible characters. This still
  108. isn't enough when a text is to contain several different languages. This is
  109. where Unicode comes in. It was designed to include all characters used in
  110. commonly used languages. This is the "Super encoding that replaces all
  111. others". But it isn't used that much yet.
  112. Fortunately, Vim supports these three kinds of encodings. And, with some
  113. restrictions, you can use them even when your environment uses another
  114. language than the text.
  115. Nevertheless, when you only edit files that are in the encoding of your
  116. language, the default should work fine and you don't need to do anything. The
  117. following is only relevant when you want to edit different languages.
  118. USING UNICODE IN THE GUI
  119. The nice thing about Unicode is that other encodings can be converted to it
  120. and back without losing information. When you make Vim use Unicode
  121. internally, you will be able to edit files in any encoding.
  122. Unfortunately, the number of systems supporting Unicode is still limited.
  123. Thus it's unlikely that your language uses it. You need to tell Vim you want
  124. to use Unicode, and how to handle interfacing with the rest of the system.
  125. Let's start with the GUI version of Vim, which is able to display Unicode
  126. characters. This should work: >
  127. :set encoding=utf-8
  128. :set guifont=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
  129. The 'encoding' option tells Vim the encoding of the characters that you use.
  130. This applies to the text in buffers (files you are editing), registers, Vim
  131. script files, etc. You can regard 'encoding' as the setting for the internals
  132. of Vim.
  133. This example assumes you have this font on your system. The name in the
  134. example is for the X Window System. This font is in a package that is used to
  135. enhance xterm with Unicode support. If you don't have this font, you might
  136. find it here:
  137. http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz ~
  138. For MS-Windows, some fonts have a limited number of Unicode characters. Try
  139. using the "Courier New" font. You can use the Edit/Select Font... menu to
  140. select and try out the fonts available. Only fixed-width fonts can be used
  141. though. Example: >
  142. :set guifont=courier_new:h12
  143. If it doesn't work well, try getting a fontpack. If Microsoft didn't move it,
  144. you can find it here:
  145. http://www.microsoft.com/typography/fonts/default.aspx ~
  146. Now you have told Vim to use Unicode internally and display text with a
  147. Unicode font. Typed characters still arrive in the encoding of your original
  148. language. This requires converting them to Unicode. Tell Vim the language
  149. from which to convert with the 'termencoding' option. You can do it like
  150. this: >
  151. :let &termencoding = &encoding
  152. :set encoding=utf-8
  153. This assigns the old value of 'encoding' to 'termencoding' before setting
  154. 'encoding' to utf-8. You will have to try out if this really works for your
  155. setup. It should work especially well when using an input method for an Asian
  156. language, and you want to edit Unicode text.
  157. USING UNICODE IN A UNICODE TERMINAL
  158. There are terminals that support Unicode directly. The standard xterm that
  159. comes with XFree86 is one of them. Let's use that as an example.
  160. First of all, the xterm must have been compiled with Unicode support. See
  161. |UTF8-xterm| how to check that and how to compile it when needed.
  162. Start the xterm with the "-u8" argument. You might also need so specify a
  163. font. Example: >
  164. xterm -u8 -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
  165. Now you can run Vim inside this terminal. Set 'encoding' to "utf-8" as
  166. before. That's all.
  167. USING UNICODE IN AN ORDINARY TERMINAL
  168. Suppose you want to work with Unicode files, but don't have a terminal with
  169. Unicode support. You can do this with Vim, although characters that are not
  170. supported by the terminal will not be displayed. The layout of the text
  171. will be preserved. >
  172. :let &termencoding = &encoding
  173. :set encoding=utf-8
  174. This is the same as what was used for the GUI. But it works differently: Vim
  175. will convert the displayed text before sending it to the terminal. That
  176. avoids that the display is messed up with strange characters.
  177. For this to work the conversion between 'termencoding' and 'encoding' must
  178. be possible. Vim will convert from latin1 to Unicode, thus that always works.
  179. For other conversions the |+iconv| feature is required.
  180. Try editing a file with Unicode characters in it. You will notice that Vim
  181. will put a question mark (or underscore or some other character) in places
  182. where a character should be that the terminal can't display. Move the cursor
  183. to a question mark and use this command: >
  184. ga
  185. Vim will display a line with the code of the character. This gives you a hint
  186. about what character it is. You can look it up in a Unicode table. You could
  187. actually view a file that way, if you have lots of time at hand.
  188. Note:
  189. Since 'encoding' is used for all text inside Vim, changing it makes
  190. all non-ASCII text invalid. You will notice this when using registers
  191. and the 'viminfo' file (e.g., a remembered search pattern). It's
  192. recommended to set 'encoding' in your vimrc file, and leave it alone.
  193. ==============================================================================
  194. *45.4* Editing files with a different encoding
  195. Suppose you have setup Vim to use Unicode, and you want to edit a file that is
  196. in 16-bit Unicode. Sounds simple, right? Well, Vim actually uses utf-8
  197. encoding internally, thus the 16-bit encoding must be converted, since there
  198. is a difference between the character set (Unicode) and the encoding (utf-8 or
  199. 16-bit).
  200. Vim will try to detect what kind of file you are editing. It uses the
  201. encoding names in the 'fileencodings' option. When using Unicode, the default
  202. value is: "ucs-bom,utf-8,latin1". This means that Vim checks the file to see
  203. if it's one of these encodings:
  204. ucs-bom File must start with a Byte Order Mark (BOM). This
  205. allows detection of 16-bit, 32-bit and utf-8 Unicode
  206. encodings.
  207. utf-8 utf-8 Unicode. This is rejected when a sequence of
  208. bytes is illegal in utf-8.
  209. latin1 The good old 8-bit encoding. Always works.
  210. When you start editing that 16-bit Unicode file, and it has a BOM, Vim will
  211. detect this and convert the file to utf-8 when reading it. The 'fileencoding'
  212. option (without s at the end) is set to the detected value. In this case it
  213. is "utf-16le". That means it's Unicode, 16-bit and little-endian. This
  214. file format is common on MS-Windows (e.g., for registry files).
  215. When writing the file, Vim will compare 'fileencoding' with 'encoding'. If
  216. they are different, the text will be converted.
  217. An empty value for 'fileencoding' means that no conversion is to be done.
  218. Thus the text is assumed to be encoded with 'encoding'.
  219. If the default 'fileencodings' value is not good for you, set it to the
  220. encodings you want Vim to try. Only when a value is found to be invalid will
  221. the next one be used. Putting "latin1" first doesn't work, because it is
  222. never illegal. An example, to fall back to Japanese when the file doesn't
  223. have a BOM and isn't utf-8: >
  224. :set fileencodings=ucs-bom,utf-8,sjis
  225. See |encoding-values| for suggested values. Other values may work as well.
  226. This depends on the conversion available.
  227. FORCING AN ENCODING
  228. If the automatic detection doesn't work you must tell Vim what encoding the
  229. file is. Example: >
  230. :edit ++enc=koi8-r russian.txt
  231. The "++enc" part specifies the name of the encoding to be used for this file
  232. only. Vim will convert the file from the specified encoding, Russian in this
  233. example, to 'encoding'. 'fileencoding' will also be set to the specified
  234. encoding, so that the reverse conversion can be done when writing the file.
  235. The same argument can be used when writing the file. This way you can
  236. actually use Vim to convert a file. Example: >
  237. :write ++enc=utf-8 russian.txt
  238. <
  239. Note:
  240. Conversion may result in lost characters. Conversion from an encoding
  241. to Unicode and back is mostly free of this problem, unless there are
  242. illegal characters. Conversion from Unicode to other encodings often
  243. loses information when there was more than one language in the file.
  244. ==============================================================================
  245. *45.5* Entering language text
  246. Computer keyboards don't have much more than a hundred keys. Some languages
  247. have thousands of characters, Unicode has over hundred thousand. So how do
  248. you type these characters?
  249. First of all, when you don't use too many of the special characters, you
  250. can use digraphs. This was already explained in |24.9|.
  251. When you use a language that uses many more characters than keys on your
  252. keyboard, you will want to use an Input Method (IM). This requires learning
  253. the translation from typed keys to resulting character. When you need an IM
  254. you probably already have one on your system. It should work with Vim like
  255. with other programs. For details see |mbyte-XIM| for the X Window system and
  256. |mbyte-IME| for MS-Windows.
  257. KEYMAPS
  258. For some languages the character set is different from latin, but uses a
  259. similar number of characters. It's possible to map keys to characters. Vim
  260. uses keymaps for this.
  261. Suppose you want to type Hebrew. You can load the keymap like this: >
  262. :set keymap=hebrew
  263. Vim will try to find a keymap file for you. This depends on the value of
  264. 'encoding'. If no matching file was found, you will get an error message.
  265. Now you can type Hebrew in Insert mode. In Normal mode, and when typing a ":"
  266. command, Vim automatically switches to English. You can use this command to
  267. switch between Hebrew and English: >
  268. CTRL-^
  269. This only works in Insert mode and Command-line mode. In Normal mode it does
  270. something completely different (jumps to alternate file).
  271. The usage of the keymap is indicated in the mode message, if you have the
  272. 'showmode' option set. In the GUI Vim will indicate the usage of keymaps with
  273. a different cursor color.
  274. You can also change the usage of the keymap with the 'iminsert' and
  275. 'imsearch' options.
  276. To see the list of mappings, use this command: >
  277. :lmap
  278. To find out which keymap files are available, in the GUI you can use the
  279. Edit/Keymap menu. Otherwise you can use this command: >
  280. :echo globpath(&rtp, "keymap/*.vim")
  281. DO-IT-YOURSELF KEYMAPS
  282. You can create your own keymap file. It's not very difficult. Start with
  283. a keymap file that is similar to the language you want to use. Copy it to the
  284. "keymap" directory in your runtime directory. For example, for Unix, you
  285. would use the directory "~/.vim/keymap".
  286. The name of the keymap file must look like this:
  287. keymap/{name}.vim ~
  288. or
  289. keymap/{name}_{encoding}.vim ~
  290. {name} is the name of the keymap. Chose a name that is obvious, but different
  291. from existing keymaps (unless you want to replace an existing keymap file).
  292. {name} cannot contain an underscore. Optionally, add the encoding used after
  293. an underscore. Examples:
  294. keymap/hebrew.vim ~
  295. keymap/hebrew_utf-8.vim ~
  296. The contents of the file should be self-explanatory. Look at a few of the
  297. keymaps that are distributed with Vim. For the details, see |mbyte-keymap|.
  298. LAST RESORT
  299. If all other methods fail, you can enter any character with CTRL-V:
  300. encoding type range ~
  301. 8-bit CTRL-V 123 decimal 0-255
  302. 8-bit CTRL-V x a1 hexadecimal 00-ff
  303. 16-bit CTRL-V u 013b hexadecimal 0000-ffff
  304. 31-bit CTRL-V U 001303a4 hexadecimal 00000000-7fffffff
  305. Don't type the spaces. See |i_CTRL-V_digit| for the details.
  306. ==============================================================================
  307. Next chapter: |usr_50.txt| Advanced Vim script writing
  308. Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: