usr_45.txt 15 KB

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