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