3

If in Vim I type CTRL-K followed by 1 and S, I can get a superscript such as 10¹.

How though do I write something like 10 to the power of 18?

Further info

I ask this on the assumption that there must or ought to be a way of specifying a multi-digit exponent, because when I try typing one after the other, they came out with little gaps between them, to make it appear as though they were not quite the same exponent.

So if I try to write 10 to the power of 18 by typing 10 CTRL-K 1 S CTRL-K 8 S, I do get 10 followed by a superscript 1 and 8, but the 1 and 8 appear as 1 8 instead of 18.

The font seems to make a difference. In Gedit, at least, by using the Linux desktops invocation of superscript chars -- typing CTRL-shift-U B 9 CTRL-shift-U 2078 gets a superscript of 1 8 when my font is monospace, but 18 when my font is, say Navilu normal. If however I set my font to Nakula Regular, I get 18, but the 1 is dropped slightly, so it looks out of kilter with the 8.

The same thing happens in Vim. All the fonts render the 1, 2 and 3 differently in comparison to exponents of other numbers, sometimes with markedly different sizes, and usually with the 1,2 and 3 dropped.

Indeed, the same thing seems to happen in Stack Overflow: ¹⁸⁹⁴²³⁰.

1
  • Now the exponents I typed in above to illustrate the problem did not of course come out as they are in the different fonts from which they were copied. The copy did not preserve the font. But you can see at least that even in the Stackoverflow font, the problem is apparent.
    – markling
    Oct 29, 2021 at 14:40

1 Answer 1

3

Vim only ships digraphs for the superscripts for 1 through 3.

You can find the additional superscripts for 4 through 9 and 0 in the Unicode ranges U+2074 through U+2079 and U+2070, which you can technically enter directly in Vim with Ctrl+V, u followed by 2078 (for superscript 8, for example.)

You can also create new digraphs for the remaining numbers. For example, if you want to keep the same syntax of the digit followed by a S, you can create them with the following commands (in your vimrc or similar):

dig 4S 8308
dig 5S 8309
dig 6S 8310
dig 7S 8311
dig 8S 8312
dig 9S 8313
dig 0S 8304

(The numbers at the end are the decimal representation of the Unicode hex numbers mentioned above.)

Once you have that configured, you can simply use Ctrl+K, 8, S to get a superscript 8.

2
  • 2
    worth pointing out that the reason vim supports out of the box digraphs for 1,2,3 is that they live in "Latin-1 supplement" which in some encodings live in effectively the "second half" of the 8 bits of ASCII. Whereas 4-9,0 were added later in unicode and have high codes (and you'll note x2071 x2072 x2073 are not 1,2,3 even though it would make logical sense)
    – Mass
    Oct 28, 2021 at 18:59
  • 1
    Thnx for clarifying this. I'm actually using Gvim. The diagraphs you suggest creating already exist, if I understand you correctly. I can type CTRL-K [digit] S for any digit 0-9, and get a superscript of that number
    – markling
    Oct 29, 2021 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.