Vim Recipes ‣ Typing ‣ Inserting Accented or "Foreign" Characters
You want to type characters which don't exist on your keyboard.
For example, you want to type some words in another language, so need to insert accented characters. Or you want to type a symbol such as ±.
If you haven't already, set up Vim to use UTF-8 by following the sidebar. It makes this process far easier.
Enabling UTF-8 Support
Vim uses the encoding specified by the user's environment. On Linux this is set with the $LANG variable. To override this use :set encoding=utf-8.
If you're using Vim from a terminal your terminal software must also be configured to use UTF-8. Instructions for that are outside the scope of this recipe.
When editing files their current encoding is maintained, so if you opened a file in ISO-8859-2, your changes would be written in that encoding. To force UTF-8 for all files use :set encoding=utf-8 fileencodings=.
To insert an accented character you press <Ctrl>-K, the unadorned character, then another character indicating the accent type. This method can also be used to produce translations of characters in a given script.
For example, to insert an e acute (the last letter in café) you hold down <Ctrl>-K, type e, then type an apostrophe (').
The following table shows the different types of characters you can produce:
| Character | Meaning |
|---|---|
| ! | Grave |
| ' | Acute accent |
| > | Circumflex accent |
| ? | Tilde |
| - | Macron |
| ( | Breve |
| . | Dot above |
| : | Diaeresis |
| , | Cedilla |
| _ | Underline |
| / | Stroke |
| " | Double acute (Hungarumlaut) |
| ; | Ogonek |
| < | Caron |
| 0 | Ring above |
| 2 | Hook |
| 9 | Horn |
| = | Cyrillic |
| * | Greek |
| % | Greek/Cyrillic special |
| + | Smalls: Arabic, caps: Hebrew |
| 3 | Some Latin/Greek/Cyrillic |
| 4 | Bopomofo |
| 5 | Hiragana |
| 6 | Katakana |
This method of input is most suitable for occasionally typing unusual characters. For regular use, Vim supports most input methods. See :help keymap and :help termencoding for more details.
Vim refers to printable, non-ASCII characters as digraphs. A list of digraphs available on your system can be obtained with the command :digraphs. The output may appear chaotic, but that's mainly because it's so dense. It lists, in columns, the character's internal name, the literal character, and the character code in decimal.
You can also insert characters using their character code. If you're one of the slackers who haven't memorised the Unicode specification yet, you can use the :digraphs command, or any other reference, to lookup the code. Hit <Ctrl>-V, then type the code in either hexadecimal or decimal. Continuing the above example of producing é, you could enter either <Ctrl>-V xe9 or <Ctrl>-V 233.
The internal name :digraphs lists corresponds with the shortcut table above. That is to say, the internal name for é is e'. Thus, we can generalise the <Ctrl>-K approach for any character we know the name of. For example, to produce the ± sign you hit <Ctrl>-K-+-.