You might know that the Tab> key will expand the next non-whitespace character on a line when you press it. However, you might have noticed that when you press Tab> and then press a non-ASCII character, such as ‘¡’ (U+00E9 LATIN SMALL LETTER ACUTE) or ‘¤’ (U+00E2 LATIN CAPITAL HEXACENTER), then the input sequence will be interpreted as an illegal character. This is due to the fact that Vim has an ‘input mode’ which maps non-ASCII characters to the corresponding ASCII characters. Once you start editing a non-ASCII character, it will be visible in the status line. If you then press Tab> the status line will show you the next legal input character. If you then press a non-ASCII character, the status line will not show that as an illegal character, but it will show it as the next input character. This might seem like a minor issue, but it is actually quite a dangerous one. You should always be careful when editing non-ASCII characters.
How do I edit non-ASCII characters?
To avoid this issue, you should use the input method that is not in ‘input mode’. If you are editing a file which has been opened with the -u command line flag, then the input mode will be disabled. This is because the -u flag sets ‘utf-8’ as the encoding for files. When you edit such a file, non-ASCII characters will be displayed correctly.
Who Is Affected By This?
This issue affects all users of Vim, so everyone should be careful when editing. It also affects anyone who uses the input mode.
If you are using a terminal emulator and want to avoid this issue, you can use shell escape sequences (like the one above) to type non-ASCII characters into your terminal emulator’s input stream. This will be done by pressing Ctrl+Alt+V followed by an ASCII character. If you do not want to use these escape sequences, then it is recommended that you switch input mode off whenever you are typing in a non-ASCII character.
How to enable non-ASCII characters in Vim
There are two ways to enable non-ASCII characters in Vim. The first way is to use the :set input method=imap . This will map non-ASCII characters to corresponding ASCII ones, which will work just like the Tab> key. You can then edit non-ASCII characters as normal by pressing enter and then typing the desired character. However, this solution affects all non-ASCII characters that you type into the console, so it might not be ideal for your situation. The other way is to use an input method plugin like uim or imsx .
How to fix it?
To get around this issue, you can disable your input mode. To do so, you would use the command ‘:set iskeymap=us’. This will disable the ‘input mode’ and show all input as legal characters from then on.