On Codecademy's Command Line Course, when trying to use the keyboard shortcut Alt+Shift+# (which is supposed to comment the current line) in the command prompt, it switches the prompt from $ to (arg: 3) instead of adding a dash at the beginning of the line. Alt+Shift+@ will make it display (arg: 2) instead, etc. See the last line in the screenshot below. Before I hit Alt+Shift+# it was just $.


The shortcut works fine on my machine.

  1. What is this (arg: n) thing?
  2. What do keyboard shortcuts depend on to work? Keyboard layout? OS distro? Terminal emulator? Default CLI? What?

This is the readline library’s prompt when you’re inputting a numeric argument. By typing AltShift@ on your keyboard, you’re apparently entering Alt2 which maps to M-2, which runs digit-argument in readline by default, and starts entering a numeric argument. If you then press Alt3 (which AltShift# maps to in your case) you’ll see the prompt change to (arg: 23); you can continue with any Alt-digit combination.

These arguments are used for certain readline functions, for example yank-nth-arg. To see this in action, run

echo Hello my friend

then press Alt2 followed by CtrlAltY; you’ll see the (arg: 2) prompt appear, then disappear, and the second argument of the previous command (“my”) will be appended to your current command line.

See the linked documentation above for details. Bash uses readline to handle its input; other shells won’t show the same behaviour.

Some terminal emulators use some of these key combinations for their own purposes; for example in GNOME Terminal, Alt-digit switches to the nth tab. You’ll need to disable these combinations to use the readline functions.

In your case, the Codecademy web-based terminal emulator doesn’t seem to handle AltShift combinations very well. If you don’t need the numeric argument shortcuts, you can repurpose them by running

bind Meta-3:insert-comment

In theory you should be able to store this permanently by adding

Meta-3: insert-comment

to an ~/.inputrc file, but I couldn’t get that to work on Codecademy.

  • 1
    Thank you. How do I disable readline or otherwise just use a keyboard shortcut to comment the current command line? – user331380 Jan 14 at 10:17
  • What terminal emulator are you using? – Stephen Kitt Jan 14 at 10:39
  • I want to know how to do it on Codecademy, I don't have a way to right-click and find out. ps -o 'cmd=' -p $(ps -o 'ppid=' -p $$) outputs /usr/local/bin/ein -service-port 4006 -http-port 4007. Does this help? – user331380 Jan 14 at 10:47
  • 1
    @user331380 Likely you are using bash shell on Codeacademy there. In interactive shell, you could start a new instance with bash --noediting. That will disable readline, but keep in mind that readline library is responsible for a lot of line editing features, which may make interactive use of shell slightly more uncomfortable – Sergiy Kolodyazhnyy Jan 14 at 17:08
  • Might be worth mentioning that it also happens on vi-keybindings when you simply type the number in normal-mode to represent the numeric argument to the next normal-mode command you type. – JoL Jan 14 at 18:31

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.