vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

usr_45.txt (17676B)


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