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.
- 55,929
- 26
- 146
- 227
- 124
- 3
- 10
-
1In vim you can type `
12`. – Toothrot Oct 18 '16 at 13:01 -
is it ctrl+k +1+2 – api1411 Oct 19 '16 at 07:41
2 Answers
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).
- 11,664
- 1
- 34
- 48
-
Hi Ingo, Where do i check "A comfortable one is :help digraphs. The table at :help digraph-table lists that particular character" – api1411 Oct 18 '16 at 13:49
-
These are links to the built-in help. Just type the `:help digraphs` inside Vim, and hit Enter. A split window with that help topic should open. – Ingo Karkat Oct 18 '16 at 13:51
-
-
-
Oh, your default `vi` is a stripped-down version of Vim. You may need to use / install the full `vim` to get the help. – Ingo Karkat Oct 18 '16 at 14:02
-
-
i see the line below line ½ 12 0xbd 189 VULGAR FRACTION ONE HALF. When i am going to edit it with CTRL+K followed by 1 and 2 . Nothing happened. – api1411 Oct 18 '16 at 14:05
-
With the `:help digraph-table`, I just wanted to show where I've got the `12` from; there are many more digraphs available. To insert (in any buffer, not the help), just press Ctrl-K 1 2 in insert mode. – Ingo Karkat Oct 18 '16 at 15:16
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-8command is likely the best course of action. But you might find yourself adjusting environment variables, too.
- 66,967
- 12
- 159
- 343