The keyboard does not send characters; it sends scan codes. For example, when you press the key labelled "e" on a typical American keyboard, it sends a scan code which essentially says "3rd key from the left on the 2nd row of alphanumeric keys in the main group". This scan code is converted into a character (or in general into a key symbol, think of keys such as "Print Screen") by the kernel (or some other component of the operating system) and, specifically in Linux, possibly by the graphical subsystem.
Generally the operating system or the graphical subsystem provide one or more utilities which control the conversion tables; for example, both in Windows and in Linux you can install as many keyboard layouts as you please and switch among them with ease.
What the application gets depends on the conventions of the operating system. On Windows, console applications get a character encoded according to the current console code page set by the command chcp
; graphical applications get a key symbol which usually gets translated into a UTF-16 encoded character. On Linux, applications usually get a UTF-8 encoded character. For example, if I press the key labelled ă
(LATIN SMALL LETTER A WITH BREVE, U+0103) with the keyboard layout set correctly,
- A console application on Windows with
chcp 1250
will get one byte '\xE3'
(227 decimal).
- A console application on Windows with
chcp 852
will get one byte '\xC7'
(199 decimal).
- A graphical application on Windows will get a suitable key symbol, which usually will get stored/processed as two bytes
'\x03'
'\x01'
(or as the short integer 0x103
).
- A terminal application on Linux will get two bytes
'\xC4'
'\x83'
(<U+0103> in UTF-8 encoding).
- A graphical application on Linux will get a suitable key symbol, which usually will get stored/processed as two bytes
'\xC4'
'\x83'
(<U+0103> in UTF-8 encoding).
(Note that by Windows I mean Windows NT and its successors such as Windows XP, Windows Vista, 7 or 10. Windows 95 etc. are an entirely different line of operating systems, thankfully no longer in use.)
In Vim you get two new layers of translation:
You can install a keyboard translation map with set keymap
; see :help 'keymap'
and :help mbyte-keymap
. This helps with entering text in the desired language on systems where you cannot install a keyboard layout at the operating system level.
You can define a mapping with the :map
command. See :help :map
.