So I am giving Vim a serious try for coding my Python apps.
However Vim is proving so flexible, I was thinking to use it as my main editor at work (lawyer/legal documents). The problem is that my mother tongue is not English but Greek. So I have mapped Alt+Shift to change between English and Greek keyboard layout. The issue I am experiencing is that I have to press Alt+Shift each time I want to enter a Vim command (to return back to English). So its Alt+Shift when I type my document, then Alt+Shift again to enter Vim commands. This defeats the purpose of using Vim, speed of use.
So my question is simple, is there any way to avoid Alt+Shift for using Vim commands with the Greek language?
This problem can be solved with the help of the keymap
option. It
allows to define an alternate keyboard mapping to use in modes requiring
text input.
To switch between default and alternate keymaps while in Insert,
Replace, or Command-line mode, use Ctrl+^
(Ctrl+6). Changing keymap affects text input
only; keyboard behaviour in Normal mode stays the same regardless of the
current keymap setting. One can leave Insert mode writing in Greek and
immediately use Normal-mode keybindings without switching to a different
keyboard layout. If one then returns to Insert mode or, for example,
starts a search by typing /
, Vim switches the keymap back to Greek
automatically.
The current keymap used in those text-entering modes is remembered
between switchings to other modes. The only exception from this
behaviour is made for Command-line mode which always starts with the
default keymap, since most of the time it is required to type an Ex
command (in ASCII). With the keymap
option set, user is supposed to
work in Vim keeping system keyboard layout set to English while
switching Vim keymap with Ctrl+^ (instead of the
system-wide layout switch).
To enable UTF-8 Greek keymap permanently, add the following line to your
.vimrc
file.
:set keymap=greek_utf-8
There are many predefined keymaps for a large set of languages, you can
browse them all in Vim itself using :e $VIMRUNTIME/keymap
. Note that
usually there are several keymaps provided for one language which differ
only by character encoding, so that anybody could choose one that suits
their configuration.
I also recommend setting the options below to specify whether the keymap should be enabled by default in Insert mode and when entering a search pattern.
:set iminsert=0
:set imsearch=-1
See :help iminsert
and :help imsearch
for their detailed
explanations.
There is also a special language mode that, if I am not mistaken, was
introduced in Vim earlier than keymap
. It allows to achieve the
behaviour similar to the one provided by keymap
through manually
specifying letter pairs that correspond to the keys on keyboard in
a long string to be saved in the langmap
option. Personally—my native
language is not English, too—I prefer (and recommend) using keymap
instead.
In conclusion, I should emphasize that all of the above is equally applicable to any other language Vim has (or can be configured to have) a keymap for.
See also my answer to a similar question that has been asked later. It includes a bit more extensive explanation.
来源:https://stackoverflow.com/questions/3776728/using-vim-with-the-greek-language