annotate runtime/doc/usr_45.txt @ 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents f8116058ca76
children 4635e43f2c6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29314
f8116058ca76 release version 9.0
Bram Moolenaar <Bram@vim.org>
parents: 28862
diff changeset
1 *usr_45.txt* For Vim version 9.0. Last change: 2022 May 13
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
20856
83cfa1ef1bf2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18879
diff changeset
5 Select your language (locale)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 The messages in Vim can be given in several languages. This chapter explains
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 how to change which one is used. Also, the different ways to work with files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 in various languages is explained.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 |45.1| Language for Messages
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |45.2| Language for Menus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |45.3| Using another encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |45.4| Editing files with a different encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |45.5| Entering language text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
28862
82244cfc4694 Update runtime files, new color schemes
Bram Moolenaar <Bram@vim.org>
parents: 20856
diff changeset
18 Next chapter: |usr_50.txt| Advanced Vim script writing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Previous chapter: |usr_44.txt| Your own syntax highlighted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 *45.1* Language for Messages
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 When you start Vim, it checks the environment to find out what language you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 are using. Mostly this should work fine, and you get the messages in your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 language (if they are available). To see what the current language is, use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 :language
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 If it replies with "C", this means the default is being used, which is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 English.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 Using different languages only works when Vim was compiled to handle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 it. To find out if it works, use the ":version" command and check the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 output for "+gettext" and "+multi_lang". If they are there, you are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 OK. If you see "-gettext" or "-multi_lang" you will have to find
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 another Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 What if you would like your messages in a different language? There are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 several ways. Which one you should use depends on the capabilities of your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 system.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 The first way is to set the environment to the desired language before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 starting Vim. Example for Unix: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 env LANG=de_DE.ISO_8859-1 vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 This only works if the language is available on your system. The advantage is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 that all the GUI messages and things in libraries will use the right language
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 as well. A disadvantage is that you must do this before starting Vim. If you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 want to change language while Vim is running, you can use the second method: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 :language fr_FR.ISO_8859-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 This way you can try out several names for your language. You will get an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 error message when it's not supported on your system. You don't get an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 when translated messages are not available. Vim will silently fall back to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 using English.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 To find out which languages are supported on your system, find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 directory where they are listed. On my system it is "/usr/share/locale". On
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 some systems it's in "/usr/lib/locale". The manual page for "setlocale"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 should give you a hint where it is found on your system.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 Be careful to type the name exactly as it should be. Upper and lowercase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 matter, and the '-' and '_' characters are easily confused.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 You can also set the language separately for messages, edited text and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 time format. See |:language|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 DO-IT-YOURSELF MESSAGE TRANSLATION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 If translated messages are not available for your language, you could write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 them yourself. To do this, get the source code for Vim and the GNU gettext
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 package. After unpacking the sources, instructions can be found in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 directory src/po/README.txt.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 It's not too difficult to do the translation. You don't need to be a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 programmer. You must know both English and the language you are translating
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 to, of course.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 When you are satisfied with the translation, consider making it available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 to others. Upload it at vim-online (http://vim.sf.net) or e-mail it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 the Vim maintainer <maintainer@vim.org>. Or both.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 *45.2* Language for Menus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 The default menus are in English. To be able to use your local language, they
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 must be translated. Normally this is automatically done for you if the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 environment is set for your language, just like with messages. You don't need
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 to do anything extra for this. But it only works if translations for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 language are available.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 Suppose you are in Germany, with the language set to German, but prefer to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 use "File" instead of "Datei". You can switch back to using the English menus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 this way: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 :set langmenu=none
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 It is also possible to specify a language: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 :set langmenu=nl_NL.ISO_8859-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 Like above, differences between "-" and "_" matter. However, upper/lowercase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 differences are ignored here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 The 'langmenu' option must be set before the menus are loaded. Once the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 menus have been defined changing 'langmenu' has no direct effect. Therefore,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 put the command to set 'langmenu' in your vimrc file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 If you really want to switch menu language while running Vim, you can do it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 this way: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 :source $VIMRUNTIME/delmenu.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 :set langmenu=de_DE.ISO_8859-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 :source $VIMRUNTIME/menu.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 There is one drawback: All menus that you defined yourself will be gone. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 will need to redefine them as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 DO-IT-YOURSELF MENU TRANSLATION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 To see which menu translations are available, look in this directory:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 $VIMRUNTIME/lang ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 The files are called menu_{language}.vim. If you don't see the language you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 want to use, you can do your own translations. The simplest way to do this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 by copying one of the existing language files, and change it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 First find out the name of your language with the ":language" command. Use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 this name, but with all letters made lowercase. Then copy the file to your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 own runtime directory, as found early in 'runtimepath'. For example, for Unix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 you would do: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 :!cp $VIMRUNTIME/lang/menu_ko_kr.euckr.vim ~/.vim/lang/menu_nl_be.iso_8859-1.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 You will find hints for the translation in "$VIMRUNTIME/lang/README.txt".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 *45.3* Using another encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 Vim guesses that the files you are going to edit are encoded for your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 language. For many European languages this is "latin1". Then each byte is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 one character. That means there are 256 different characters possible. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 Asian languages this is not sufficient. These mostly use a double-byte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 encoding, providing for over ten thousand possible characters. This still
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 isn't enough when a text is to contain several different languages. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 where Unicode comes in. It was designed to include all characters used in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 commonly used languages. This is the "Super encoding that replaces all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 others". But it isn't used that much yet.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 Fortunately, Vim supports these three kinds of encodings. And, with some
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 restrictions, you can use them even when your environment uses another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 language than the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 Nevertheless, when you only edit files that are in the encoding of your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 language, the default should work fine and you don't need to do anything. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 following is only relevant when you want to edit different languages.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 USING UNICODE IN THE GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 The nice thing about Unicode is that other encodings can be converted to it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 and back without losing information. When you make Vim use Unicode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 internally, you will be able to edit files in any encoding.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 Unfortunately, the number of systems supporting Unicode is still limited.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 Thus it's unlikely that your language uses it. You need to tell Vim you want
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 to use Unicode, and how to handle interfacing with the rest of the system.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 Let's start with the GUI version of Vim, which is able to display Unicode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 characters. This should work: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 :set encoding=utf-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 :set guifont=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 The 'encoding' option tells Vim the encoding of the characters that you use.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 This applies to the text in buffers (files you are editing), registers, Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 script files, etc. You can regard 'encoding' as the setting for the internals
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 of Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 This example assumes you have this font on your system. The name in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 example is for the X Window System. This font is in a package that is used to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 enhance xterm with Unicode support. If you don't have this font, you might
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 find it here:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 For MS-Windows, some fonts have a limited number of Unicode characters. Try
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 using the "Courier New" font. You can use the Edit/Select Font... menu to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 select and try out the fonts available. Only fixed-width fonts can be used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 though. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 :set guifont=courier_new:h12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 If it doesn't work well, try getting a fontpack. If Microsoft didn't move it,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 you can find it here:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
1618
46bbe11644e0 updated for version 7.2a
vimboss
parents: 1231
diff changeset
192 http://www.microsoft.com/typography/fonts/default.aspx ~
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 Now you have told Vim to use Unicode internally and display text with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 Unicode font. Typed characters still arrive in the encoding of your original
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 language. This requires converting them to Unicode. Tell Vim the language
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 from which to convert with the 'termencoding' option. You can do it like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 :let &termencoding = &encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 :set encoding=utf-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 This assigns the old value of 'encoding' to 'termencoding' before setting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 'encoding' to utf-8. You will have to try out if this really works for your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 setup. It should work especially well when using an input method for an Asian
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 language, and you want to edit Unicode text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 USING UNICODE IN A UNICODE TERMINAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 There are terminals that support Unicode directly. The standard xterm that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 comes with XFree86 is one of them. Let's use that as an example.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 First of all, the xterm must have been compiled with Unicode support. See
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 |UTF8-xterm| how to check that and how to compile it when needed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 Start the xterm with the "-u8" argument. You might also need so specify a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 font. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 xterm -u8 -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 Now you can run Vim inside this terminal. Set 'encoding' to "utf-8" as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 before. That's all.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 USING UNICODE IN AN ORDINARY TERMINAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 Suppose you want to work with Unicode files, but don't have a terminal with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 Unicode support. You can do this with Vim, although characters that are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 supported by the terminal will not be displayed. The layout of the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 will be preserved. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 :let &termencoding = &encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 :set encoding=utf-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 This is the same as what was used for the GUI. But it works differently: Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 will convert the displayed text before sending it to the terminal. That
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 avoids that the display is messed up with strange characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 For this to work the conversion between 'termencoding' and 'encoding' must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 be possible. Vim will convert from latin1 to Unicode, thus that always works.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 For other conversions the |+iconv| feature is required.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 Try editing a file with Unicode characters in it. You will notice that Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 will put a question mark (or underscore or some other character) in places
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 where a character should be that the terminal can't display. Move the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 to a question mark and use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 ga
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 Vim will display a line with the code of the character. This gives you a hint
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 about what character it is. You can look it up in a Unicode table. You could
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 actually view a file that way, if you have lots of time at hand.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 Since 'encoding' is used for all text inside Vim, changing it makes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 all non-ASCII text invalid. You will notice this when using registers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 and the 'viminfo' file (e.g., a remembered search pattern). It's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 recommended to set 'encoding' in your vimrc file, and leave it alone.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 *45.4* Editing files with a different encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 Suppose you have setup Vim to use Unicode, and you want to edit a file that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 in 16-bit Unicode. Sounds simple, right? Well, Vim actually uses utf-8
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
262 encoding internally, thus the 16-bit encoding must be converted, since there
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 is a difference between the character set (Unicode) and the encoding (utf-8 or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 16-bit).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 Vim will try to detect what kind of file you are editing. It uses the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 encoding names in the 'fileencodings' option. When using Unicode, the default
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 value is: "ucs-bom,utf-8,latin1". This means that Vim checks the file to see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 if it's one of these encodings:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 ucs-bom File must start with a Byte Order Mark (BOM). This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 allows detection of 16-bit, 32-bit and utf-8 Unicode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 encodings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 utf-8 utf-8 Unicode. This is rejected when a sequence of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 bytes is illegal in utf-8.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 latin1 The good old 8-bit encoding. Always works.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 When you start editing that 16-bit Unicode file, and it has a BOM, Vim will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 detect this and convert the file to utf-8 when reading it. The 'fileencoding'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 option (without s at the end) is set to the detected value. In this case it
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
280 is "utf-16le". That means it's Unicode, 16-bit and little-endian. This
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 file format is common on MS-Windows (e.g., for registry files).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 When writing the file, Vim will compare 'fileencoding' with 'encoding'. If
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 they are different, the text will be converted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 An empty value for 'fileencoding' means that no conversion is to be done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 Thus the text is assumed to be encoded with 'encoding'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 If the default 'fileencodings' value is not good for you, set it to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 encodings you want Vim to try. Only when a value is found to be invalid will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 the next one be used. Putting "latin1" first doesn't work, because it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 never illegal. An example, to fall back to Japanese when the file doesn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 have a BOM and isn't utf-8: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 :set fileencodings=ucs-bom,utf-8,sjis
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 See |encoding-values| for suggested values. Other values may work as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 This depends on the conversion available.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 FORCING AN ENCODING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 If the automatic detection doesn't work you must tell Vim what encoding the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 file is. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 :edit ++enc=koi8-r russian.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 The "++enc" part specifies the name of the encoding to be used for this file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 only. Vim will convert the file from the specified encoding, Russian in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 example, to 'encoding'. 'fileencoding' will also be set to the specified
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 encoding, so that the reverse conversion can be done when writing the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 The same argument can be used when writing the file. This way you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 actually use Vim to convert a file. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 :write ++enc=utf-8 russian.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 Conversion may result in lost characters. Conversion from an encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 to Unicode and back is mostly free of this problem, unless there are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 illegal characters. Conversion from Unicode to other encodings often
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 loses information when there was more than one language in the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 *45.5* Entering language text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 Computer keyboards don't have much more than a hundred keys. Some languages
5362
ab1508486b12 Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents: 5294
diff changeset
325 have thousands of characters, Unicode has over hundred thousand. So how do
ab1508486b12 Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents: 5294
diff changeset
326 you type these characters?
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 First of all, when you don't use too many of the special characters, you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 can use digraphs. This was already explained in |24.9|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 When you use a language that uses many more characters than keys on your
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 keyboard, you will want to use an Input Method (IM). This requires learning
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 the translation from typed keys to resulting character. When you need an IM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 you probably already have one on your system. It should work with Vim like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 with other programs. For details see |mbyte-XIM| for the X Window system and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 |mbyte-IME| for MS-Windows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 KEYMAPS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 For some languages the character set is different from latin, but uses a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 similar number of characters. It's possible to map keys to characters. Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 uses keymaps for this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 Suppose you want to type Hebrew. You can load the keymap like this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 :set keymap=hebrew
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 Vim will try to find a keymap file for you. This depends on the value of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 'encoding'. If no matching file was found, you will get an error message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 Now you can type Hebrew in Insert mode. In Normal mode, and when typing a ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 command, Vim automatically switches to English. You can use this command to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 switch between Hebrew and English: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 CTRL-^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 This only works in Insert mode and Command-line mode. In Normal mode it does
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 something completely different (jumps to alternate file).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 The usage of the keymap is indicated in the mode message, if you have the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 'showmode' option set. In the GUI Vim will indicate the usage of keymaps with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 a different cursor color.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 You can also change the usage of the keymap with the 'iminsert' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 'imsearch' options.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 To see the list of mappings, use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 :lmap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 To find out which keymap files are available, in the GUI you can use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 Edit/Keymap menu. Otherwise you can use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 :echo globpath(&rtp, "keymap/*.vim")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 DO-IT-YOURSELF KEYMAPS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 You can create your own keymap file. It's not very difficult. Start with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 a keymap file that is similar to the language you want to use. Copy it to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 "keymap" directory in your runtime directory. For example, for Unix, you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 would use the directory "~/.vim/keymap".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 The name of the keymap file must look like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 keymap/{name}.vim ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 keymap/{name}_{encoding}.vim ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 {name} is the name of the keymap. Chose a name that is obvious, but different
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 from existing keymaps (unless you want to replace an existing keymap file).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 {name} cannot contain an underscore. Optionally, add the encoding used after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 an underscore. Examples:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 keymap/hebrew.vim ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 keymap/hebrew_utf-8.vim ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 The contents of the file should be self-explanatory. Look at a few of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 keymaps that are distributed with Vim. For the details, see |mbyte-keymap|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 LAST RESORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 If all other methods fail, you can enter any character with CTRL-V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 encoding type range ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 8-bit CTRL-V 123 decimal 0-255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 8-bit CTRL-V x a1 hexadecimal 00-ff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 16-bit CTRL-V u 013b hexadecimal 0000-ffff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 31-bit CTRL-V U 001303a4 hexadecimal 00000000-7fffffff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 Don't type the spaces. See |i_CTRL-V_digit| for the details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410
28862
82244cfc4694 Update runtime files, new color schemes
Bram Moolenaar <Bram@vim.org>
parents: 20856
diff changeset
411 Next chapter: |usr_50.txt| Advanced Vim script writing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412
14519
5c5908e81e93 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13963
diff changeset
413 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: