123

Accidently I mapped Enter via xkbset to Pointer_button2.

Now every time I hit Enter some gibberish text appears.

I thought of a workaround involving remapping it back, but that means I will have to run a command xmodmap -e "keycode 135 = Pointer_Button2" (or any other keycode but that of Enter). But I'm not able to run this command in terminal, without hitting Enter.

How do I do so?

I'm running Ubuntu 12.04.

polym
  • 10,852
user13107
  • 5,335
  • 6
    One day computers will be able to undo anything. Like we have with file system snapshots now, but with the contents of RAM... like rolling back what we are doing. Un-enter a command. Un-open a file. Un-run a program. Un-Do last 5 minutes. Then, later the internet will catch up ... Un-read a web-site: You were never there! Maybe one day we will be able to un-do motor car accidents, restore the lamp posts to upright, etc. – Johan Mar 15 '13 at 16:14
  • 4
    @Johan What kind of substances did you take when you wrote this comment ? – Luc M Aug 31 '13 at 19:25

6 Answers6

133

You can use CTRL+J or CTRL+M as an alternative to Enter. They are the control characters for linefeed (LF) and carriage return (CR).

camh
  • 39,069
  • 6
    Sheesh… why can't folks with 6,705 points let some of these easy questions through to the vast unwashed masses to answer? (Just kidding -- +1 for the answer I was going to post.) – Jan Steinman Oct 17 '12 at 21:29
  • 5
    @JanSteinman Because then they would only have 6,330 points (6705 - 15 - 36*10). :P – ernie Oct 17 '12 at 23:35
  • 3
    @JanSteinman: I did let it through! There were already three other answers when I answered, and one was accepted. It seems kids these days don't know their ASCII :-) (@ernie: there's a daily reputation cap, so you don't get all those points). – camh Oct 18 '12 at 10:25
  • Thanks for accepting some good-natured ribbing -- no slight intended at all. If you know it, show it! – Jan Steinman Oct 19 '12 at 00:09
  • @JanSteinman and camh, are there any historical reasons behind this convention (Enter ~= Ctrl+M/J)? – user13107 Oct 20 '12 at 15:51
  • 2
    @user13107 Not so much historical as just the ASCII code definition itself. When ASCII was pretty much all there was (unless you were in IBM land) the Return and Linefeed keys had to be coded as something so we could type them on our trusty ASR-33 teletypes or our punch cards. There's even an ascii package you can install that will display it. The Ctrl key just took the code for one of the first 32 characters and set one bit back to 0. For M, it changed a 4D to a 0D which is a carriage return (and there really was a carriage on an ASR-33.) – Joe Oct 20 '12 at 20:19
  • @Joe But ASR-33 already had return and linefeed keys right? Hence, are you sure that the reason for ^-J ^-M being interpreted as Enter really this? – Utku May 15 '16 at 08:29
  • 1
    @Utku - They had those keys, but they only had 8 bits to play with and one of them was for rubouts - so characters on the paper tapes could be "erased". With 7 bits, things got pretty squashed together. Another was the difference between lower and uppercase. Another was for Ctrl. That left just 6 bits to get everything else done. So the Return key really just sent the same code as Ctrl+M and the Linefeed key just sent Ctrl-J. It was an artifact of the hardware/coding limitations. It was amazing how much they squeezed out of that little! – Joe May 16 '16 at 08:54
  • @Utku - Later, when paper tape went away, that bit was freed up and we got non-standard extended ASCII codes so you could put a heart or a club on the screen or a line drawing character. That was a big deal back then. It's hard to imagine now. My previous comment isn't precisely correct, but it's close. – Joe May 16 '16 at 08:59
26

Run the command from a non-X terminal.

CTRL+ALT+F2 should get you to a normal console. Login as your normal user, and then run the command there.

xmodmap only affects X sessions so it needs DISPLAY to work outside the X server, like this:

DISPLAY=:0 xmodmap
Braiam
  • 35,991
14

You could put it into a script (.sh) and then double click it. Most modern desktop environments give the option of running a script instead of opening it in a text file.

terdon
  • 242,166
12

If you have a mouse and graphical display you can copy the end of a previous line in your terminal and paste it onto the end of your command.

Eric Layton
  • 129
  • 2
4

CTRL+O is another option. With bash it executes the command and moves to the next most recent in history, it is useful to cycle back through a chain of previously executed commands.

Graeme
  • 34,027
1

If you have a mouse then just copy this -> "

"

and paste next to your command and then paste entire command in the terminal.

Like enter image description here

xeon
  • 19