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