1

I want to type ½ in vi mode but it is coming with extra character ½. I am pressing ALT+0189. I have searched a lot on the same but failed to get.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
api1411
  • 124
  • 3
  • 10

2 Answers2

3

If the entry via the terminal doesn't work (it looks like there's an encoding mismatch), you can fall back to Vim's built-in methods for entry of special characters.

digraphs

A comfortable one is :help digraphs. The table at :help digraph-table lists that particular character:

½   12  0xbd    189 VULGAR FRACTION ONE HALF

To insert, type Ctrl + K, followed by 1 and 2.

entry by number

This is described under :help i_CTRL-V_digit. With the decimal number, enter Ctrl + V, 1 8 9. You could also use the hexadecimal representation (xbd).

Ingo Karkat
  • 11,664
  • 1
  • 34
  • 48
2

I want to type ½ in vi mode but it is coming with extra character ½.

No.

What's happening is that your terminal is sending that character encoded as UTF-8. The character is U+00BD and its UTF-8 encoding is the two 8-bit character sequence whose hexadecimal values are C2 BD.

vim thinks that you aren't typing in UTF-8, though. It thinks that you typed two 8-bit characters, first character U+00C2 and then character U+00BD. Hence it is inserting those two characters.

Making vim believe that you are using UTF-8 is a trip into the complex world of locales and encodings. vim currently believes that your terminal generates Latin-1 (ISO 8859-1) input. You need vim to believe that your terminal generates UTF-8 input.

Moreover: It's also apparent, from what is buried in comments to another answer, that your help text isn't being treated as UTF-8 either, indicating that it isn't working internally in UTF-8, probably because your environment variables (LANG, LC_ALL, and so forth) are not specifying a UTF-8 locale. In order for vim to properly handle UTF-8 input, it is best for it to be using UTF-8 internally, as its overall encoding.

Something such as the

:set termencoding=utf-8 encoding=utf-8
command is likely the best course of action. But you might find yourself adjusting environment variables, too.
JdeBP
  • 66,967
  • 12
  • 159
  • 343