5

This may seem a bit of a strange question, but it occurred to me that when typing a command such as the following, I always have to copy and paste the character from Wikipedia.

echo '5 μs' >> /tmp/Output

Is there a way to input such a character directly using an escape sequence on keyboard shortcut on a standard English keyboard?

For example, in Vim, one can do C-k,m* to produce this character.

  • Standard (UK) English keyboard with Compose enabled. à á å ä æ § ¥ € £ ß µ. And many others. – roaima Dec 11 '18 at 10:02
  • Note that the character actually used here in the question title and body is U+00B5, the SI prefix in μs. – JdeBP Dec 11 '18 at 13:46
  • Both M-x set-input-method RET greek and C-x RET C-\ greek will set emacs to a greek keyboard where the usual place for m is the greek letter μ (and alpha is a beta is b, etc.). – Isaac Dec 11 '18 at 13:50
  • @JdeBP Actually the question characters are U+03bc (the Greek ones), not U+00b5 (the micro ones). But the use is obviously micro as in micro-seconds. So, the question is actually conflicting on this issue. Anyway, we've got solutions for everything now. – Isaac Dec 11 '18 at 14:15
  • I did copy and paste the question text to check. The characters came out as U+00B5 here. – JdeBP Dec 11 '18 at 17:29
13

Yes, there are at least this four (five?) ways:

  1. AltGr
    Make your keyboard layout English (international AltGr dead keys).
    Then the right Alt key is the AltGr key. Pressing AltGr-m will generate a µ. Many other keys also generate other characters: AltGr-s for ß, and Shift-AltGr-s for §.

    There is a separate keyboard layout for the console (the true consoles at AltCtrlF1 up to F6) and one for the GUI in X. Changing either depends on your distro (CentOS, Fedora, Debian, etc.) and Display manager (gnome, kde, xfce, etc.). For example, installing xfce4-xkb-plugin will allow a button on a panel to configure the keyboard and switch between several keyboard layouts for X in XFCE.

  2. Compose
    Make some key the Compose key. Then, presing Compose, releasing it, pressing /, releasing it, and then u will generate a µ.

    Defining a Compose key is usually done with xkb or with a keyboard layout applet.
    For example, in Gnome usually available at Region & Language section, or maybe, Switch Keyboard Layout Easily.

  3. Unicode
    There is a generic way to type any Unicode character (if your console supports it). Yes any codepoint of the 1,111,998 possible characters (visible if your font(s) could draw them). Press, as one chord (at the same time) ShiftCtrlu, release them (Probably, an underlined u̲ will appear), then type b5 which is the Unicode codepoint (always in Hex) for the character. And to end, type space or enter (at least).

  4. Readline
    In a bash prompt (as you tagged the question) is possible to use readline to generate a µ (mu).

     bind '"\eu": "µ"'
    

    Or add the line:

     "\eu": "µ"
    

    to ~/.inputrc, read it with Alt-x Alt-r or start a new bash shell (execute bash) and when you type:

    Alt-u

    An µ will appear.

  5. Input method
    Probably too much for a short answer like this.


A mistake: Technically, the character requested in the question was Unicode \U3bc while this answer has provided solutions for \Ub5. Yes, they are different, my mistake, sorry.

 $ unicode $(printf '\U3bc\Ub5')
 U+03BC GREEK SMALL LETTER MU
 UTF-8: ce bc UTF-16BE: 03bc Decimal: μ Octal: \01674
 μ (Μ)
 Uppercase: 039C
 Category: Ll (Letter, Lowercase)
 Unicode block: 0370..03FF; Greek and Coptic
 Bidi: L (Left-to-Right)

 U+00B5 MICRO SIGN
 UTF-8: c2 b5 UTF-16BE: 00b5 Decimal: µ Octal: \0265
 µ (Μ)
 Uppercase: 039C
 Category: Ll (Letter, Lowercase)
 Unicode block: 0080..00FF; Latin-1 Supplement
 Bidi: L (Left-to-Right)
 Decomposition: <compat> 03BC

And technically, the only valid solutions are number 3 and 4. In 3 the Unicode number could be changed from b5 to 3bc to get even this Greek character. In 4 just copy the correct character and done.

Not in my defense, but

  1. Both b5 and 3bc have as Uppercase 39c. So, both are the lowercase of MU.
  2. Both look very, very similar (probably the same glyph from the font):

enter image description here

Alternatives.

  1. AltGr

    Its quite possible and already done by changing the AltGr-g (with xkb) to:

     key <AC05>  { [         g,          G,       dead_greek,   dead_greek ]};
    

    And then typing AltGr-g m to get a true greek-mu.

  2. Compose

    The Compose table is incorrect, even the Greek Compose file (/usr/share/X11/locale/el_GR.UTF-8/Compose) lists:

     <Multi_key> <slash> <u>                 : "µ"   mu
     <Multi_key> <u> <slash>                 : "µ"   mu
     <Multi_key> <slash> <U>                 : "µ"   mu
     <Multi_key> <U> <slash>                 : "µ"   mu
    

    Those compositions as Greek, which they are not.

    The correct solution for compose is to include an ~/.XCompose for greek and reboot.

  3. Unicode

    Works as posted, with unicode number 3bc

  4. Readline

    Works as posted, change the effective character to any wanted.

  • Method 3 unicode, does not work for me. – ctrl-alt-delor Dec 11 '18 at 7:59
  • Older debian didn't have this option. Which distro and which console? konsole, gnome-terminal, terminator, etc ? @ctrl-alt-delor – Isaac Dec 11 '18 at 8:02
  • I just want to know why do method 3 work. It doesn't seem to be related to X's keyboard layout or Xcb. – 炸鱼薯条德里克 Dec 11 '18 at 8:30
  • No it is not related to keyboard, xkb, input method, or desktop shortcut. It is an option that some (many, it seems now) programs provide/support, something like using some specific set of colors to match TTY colors. Not long ago some terminals didn't have it, yet. Most do now. @神秘德里克 – Isaac Dec 11 '18 at 8:37
  • 2
    On the note of the two characters, they are typographically equivalent, but the Unicode standard is encoding a semantic difference. The lower codwpoint is a mathematical symbol, while the upper one is a letter from the Greek alphabet. The semantic difference usually doesn't matter, but it might if the text is being processed beyond just displaying it on screen. – Austin Hemmelgarn Dec 11 '18 at 16:23
4

If you enable your compose key, you can print this symbol with the compose/u sequence, like so: µ

The full range of symbols available, and their respective key sequences, is documented on the Ubuntu wiki.

3

Using input methods

CIN-file input methods are usable in X11 and in my user-space virtual terminals. One of the commonly-collected ones, greek.cin, has the mu character. One simply enters m (lower case) and it is the only conversion.

One can modify greek.cin to add micro, providing a second conversion, although visually it will be quite confusing, making it hard to select the correct one during conversion selection, if they both map from m. A better conversion would map micro to U+00B5:

micro    μ

Using the ISO 9995 common secondary group

Your X11 keyboard map or your virtual terminal might not implement this, but if it does there is a standard country-independent key sequence (of two key chords) for the mu character defined by ISO/IEC 9995: ⇨ Group 2 Select B07

  • ⇨ Group 2 Select is conventionally the chord ⇧ Level 2 Shift+⇮ Level 3 Shift because the USB HID specification and others lack a code for a proper ⇨ Group 2 Select key and such a key does not exist on most keyboards.
  • ⇮ Level 3 Shift is usually engraved ⌥ Option or ⇮ AltGr on 105/106/107/109-key keyboards or ⎇ Alt on 104-key keyboards.
  • B07 is the standard ISO/IEC 9995 notation for a physical position on row "B" and column "07", and the key there is usually engraved M.

Where implemented, this so-called common secondary group of ISO/IEC 9995 is not supposed to vary by the selected country's layout, and is always available.

However, there is no common secondary group sequence for the micro prefix character.

Using whatever chord is defined in your keyboard layout

The specifics of keyboard layouts are beyond the scope of this answer, and there are plenty of answers here dealing with them.

Précis:

There is a keyboard layout for X11 applications, there is a possibly related keyboard layout for kernel virtual terminals (if your operating system has such), and there is are keyboard layouts for user-space virtual terminals (if you are using such). Layouts generally provide such characters as a chord with ⇧ Level 2 Shift or ⇮ Level 3 Shift in conjunction with a main keypad key.

Some X11 keyboard maps furthermore define (as an optional addendum) a compose key which begins key sequences (of multiple key chords) that map to such characters. In the conventional X11 composition set, as documented by David Monniaux years ago, the mu character is the sequence Compose M U or the sequence Compose / U. Note that it is conflated with the micro prefix character.

Consult your VT and X11 keyboard maps for information about what chord is mapped, if any. Check your configuration for whether you have enabled the compose key option in X11.

Examples:

The ch, de, it, nl, and no virtual terminal keyboard maps in FreeBSD provide the mu character as the chord ⇮ Level 3 Shift+B07 (M):

% sed -n -e '2,5p;/0xb5/p' /usr/share/vt/keymaps/de.kbd                                                         /usr/share/vt/keymaps [pts/4.10009.1]
#                                                         alt
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
  050   'm'    'M'    cr     cr     0xb5   0xb5   cr     cr      C
% 

But other maps either do not have it or define a different chord. In the fr keyboard map it is ⇧ Level 2 Shift+C12 (EUROPE1):

% sed -n -e '2,5p;/0xb5/p' /usr/share/vt/keymaps/fr.kbd                                                         /usr/share/vt/keymaps [pts/4.10011.1]
#                                                         alt   
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
  043   '*'    0xb5   nop    nop    '#'    '~'    nop    nop     O
%

And it is not mapped in the uk keyboard map at all. Nor do any of them have the micro prefix character.

Other methods

Other methods are specific to application input handling libraries or to particular terminal emulators, whereas input methods and X11/VT keyboard maps are not application-specific.

Some terminal emulators provide other ways of entering characters, by their Unicode code points. Readline can of course be configured to map input sequences to this character, as also can ZLE. And you have already mentioned VIM in the question.

Further reading

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.