Search code examples
vim

How does one add a mathematical bar over a character in Vim?


I'd like to be able to type characters "a bar," "e bar," and so on - as variable names for vectors, let's say - but I can't find them in :digraphs. I've tried searching digraphs.txt and come up empty. It's possible this isn't an option in Vim, but I thought I'd ask here before writing it off.


Solution

  • You will have to be more precise about what you want, because it is very easy to obtain a character with a macron:

    <C-k>a-
    

    which :digraphs definitely has:

    :digraphs

    which is also listed in :help digraphs under :help digraph-table-mbyte:

    help

    a list that is a bit redundant given this other list:

    char name           char    meaning
    Exclamation mark    !       Grave
    Apostrophe          '       Acute accent
    Greater-Than sign   >       Circumflex accent
    Question mark       ?       Tilde
    Hyphen-Minus        -       Macron
    Left parenthesis    (       Breve
    Full stop           .       Dot above
    Colon               :       Diaeresis
    Comma               ,       Cedilla
    Underline           _       Underline
    Solidus             /       Stroke
    Quotation mark      "       Double acute accent
    Semicolon           ;       Ogonek
    Less-Than sign      <       Caron
    Zero                0       Ring above
    Two                 2       Hook
    Nine                9       Horn
    
    Equals              =       Cyrillic (= used as second char)
    Asterisk            *       Greek
    Percent sign        %       Greek/Cyrillic special
    Plus                +       smalls: Arabic, capitals: Hebrew
    Three               3       some Latin/Greek/Cyrillic letters
    Four                4       Bopomofo
    Five                5       Hiragana
    Six                 6       Katakana
    

    found under :help digraphs-default.

    Note that, as mentioned in the doc, the whole thing is designed after RFC 1345, and Unicode, which don't have any other way to produce "bar over character".

    Note also that:

    • <C-k>d- produces a ð and not really a d with a macron over it,
    • and some combinations don't produce anything useful, like b-, c-, etc. YMMV.

    Note also that there is no "overline" styling possible in Vim so all you have, really, is digraphs using a macron, with all their limitations.