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