Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm used to holding the left Alt and entering the ASCII character whenever I'm using an unknown keyboard configuration and want to type a special character.

For example, Alt + 0 + 9 + 2 makes a backslash (\).

That's on Windows. Is there a way to do this in Ubuntu?

Note: I also want to be able to use this in console mode. That means I don't want a solution involving software with a GUI.

share|improve this question

4 Answers 4

up vote 8 down vote accepted

If you are using Gnome (stock Ubuntu does) you can do that by holding down both the Ctrl and Shift keys and typing u followed by the hexadecimal value of the character.

To produce the backslash \, you would hold Ctrl + Shift and press U, 5 and C.

On Windows you type the decimal value while on Linux you type the hexadecimal value (which is usually shorter if you go in the higher numbers). The u stands for Unicode.

A pretty complete table of hexadecimal values can be found here. Warning, page can take a long time to load!

share|improve this answer
2  
The "hexadecimal value" is in fact the Unicode codepoint, unlike "Alt codes" which are ASCII –  grawity Oct 7 '10 at 18:33
    
Wow. Exactly what I needed ! Works everywhere like a charm. Thank you. –  Philippe Carriere Oct 12 '10 at 15:08
1  
Now I only need to learn all the codes in hexa.... :( –  Philippe Carriere Oct 12 '10 at 15:14

Another option (but it does not insert a character by ASCII/Unicode code) is to activate the ComposeKey (like right Alt in my case), so that you can then type things like:

  • Alt + = + e → €
  • Alt + ' + e → é
  • Alt + ^ + e → ê

etc. In case you want to enter frequently used latin letters (as in Spanish, French, etc), this might be faster than having to learn the Unicode code points. It's all about having choice!

share|improve this answer
    
Don't you need an non-US keyboard layout for this? –  Cristian Ciupitu Jun 1 at 0:23
1  
@CristianCiupitu: No, you need to enable a Compose key. –  Ignacio Vazquez-Abrams Jul 14 at 9:48
    
@IgnacioVazquez-Abrams, you're right. It seems that my XFCE 4.10 desktop environment didn't set the Compose key at all, but after setting it to the right Alt key, the answer worked (therefore +1 from me). –  Cristian Ciupitu Jul 14 at 18:41

Linux's console driver doesn't have a facility for entering characters this way... but it isn't really needed since shells can handle this themselves.

$ echo $'\x5c'
\
share|improve this answer
    
Thats a very nice method.... I can't even find it in the man pages of echo but it works! Is there a way to provide the decimal code instead of the hexidecimal one ? (I learned the decimal codes by heart) –  Philippe Carriere Oct 7 '10 at 13:15
    
Is there a way to use this when I'm in vi or nano ? –  Philippe Carriere Oct 7 '10 at 13:17
1  
No, they can only be entered in hex (\xNN) or octal (\NNN). You can use printf if you want to see the hex code for a value. In vim you can type Ctrl-V U and then the 4-digit Unicode codepoint. Also, QUOTING section. –  Ignacio Vazquez-Abrams Oct 7 '10 at 14:06
2  
@Silence: (1) Because it's a feature of your shell (usually bash), not of echo. –  grawity Oct 7 '10 at 18:33
    
@PhilippeCarriere In vi you can execute shell commands by prepending :! like :!ls. You can also insert the output into the current buffer using :r !. I often lack the tilde character so I use :r !echo $'\x7e'. A little more on that here. –  valid Jul 14 at 9:54

From the UTF-8 and Unicode FAQ for Unix/Linux by Markus Kuhn:

Extend your keyboard mapping using xmodmap. This is particularly convenient if your keyboard has an AltGr key, which is meant for exactly this purpose (some US keyboards have instead of AltGr just a right Alt key, others lack that key entirely unfortunately, in which case some other key must be assigned the Mode_switch function). Write a file ~/.Xmodmap with entries such as

keycode 113 = Mode_switch Mode_switch
keysym d = d NoSymbol degree        NoSymbol
keysym m = m NoSymbol emdash        mu
keysym n = n NoSymbol endash        NoSymbol
keysym 2 = 2 quotedbl twosuperior   NoSymbol
keysym 3 = 3 sterling threesuperior NoSymbol
keysym 4 = 4 dollar   EuroSign      NoSymbol
keysym space = space  NoSymbol      nobreakspace NoSymbol
keysym minus = minus  underscore    U2212        NoSymbol
keycode 34 = bracketleft  braceleft  leftsinglequotemark  leftdoublequotemark
keycode 35 = bracketright braceright rightsinglequotemark rightdoublequotemark
keysym KP_Subtract = KP_Subtract NoSymbol U2212    NoSymbol
keysym KP_Multiply = KP_Multiply NoSymbol multiply NoSymbol
keysym KP_Divide   = KP_Divide   NoSymbol division NoSymboll

and load it with xmodmap ~/.Xmodmap from your X11 startup script into your X server. You will then find that you get with AltGr easily the following new characters out of your keyboard:

  • AltGr+d → °
  • AltGr+[ → ‘
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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