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 the default and alternate keymaps while in Insert,
Replace, or Command-line mode (but not Normal mode), use
Ctrl+^ (Ctrl+6).
Changing the keymap affects text input only; keyboard behavior 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, say, the 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 imsearch=-1
See :help iminsert
and :help imsearch
for the detailed explanation.
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
the keymap
way 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 ‘Vim “annoyance”
with keyboard layouts’ that has been asked since I originally
gave this answer.