I am inside a screen (screen -Ra). I have a long command, and I am at the end. Instead of keeping the left arrow, how can you go to the beginning of the line?

CTRL-A works when I am in a normal window, but when I am inside a screen pressing CTRL-A gives me a message "No other window" - seems like CTRL-A is dispatched to the screen.

How do you go to the beginning of a line in a screen?

  • 3
    Quick fix: press the Home key to get to the beginning, and End to get to the end of line. – user13742 Jan 19 '12 at 12:23
  • 1
    This is also highly dependent upon the shell and input mode youre using, though I'm assuming youre using bash and the default emacs bindings. – phemmer Jan 19 '12 at 13:18
  • 1
    @hesse given your keyboard has a Home button. Not always the case – Matteo Jan 19 '12 at 15:04
  • The OP might be interested in this related question. – dotancohen Nov 30 '12 at 10:22

Use Ctrl-a a, or change screen's escape keystroke (option -e).

  • 6
    In case it is not clear you press Ctrl-a, release both keys, and then press a. Do not make the same mistake I made keeping Ctrl pressed. Good reference card for this and other key bindings: aperiodic.net/screen/quick_reference – Yzmir Ramirez Nov 5 '15 at 22:21

Ctrl-x-Ctrl-x lets you go to the first character of the line for any readline-compatible environment like Bash, python and mysql. GNU SCREEN safely ignores this. No customized configuration necessary.

If you use this instead of Ctrl-a-a, you use a consistant shortcut key - you don't have to keep in mind whether you are in GNU SCREEN or not.

For anyone interested, the same shortcut key also lets you go to the end of the line if you are already at the begining.

  • 7
    Actually, C-x C-x is exchange-point-and-mark. It just happens that mark is at the beginning of the line by default. You can use C-space to set the mark somewhere else. – Ivan Andrus Apr 21 '14 at 17:29
  • Ivan, typically what can you do after exchanging a point and marking ? Thanks. – Susheel Javadi Mar 11 '16 at 4:16

Either you can change the screen bindings or you can change the bindings of your shell. Assuming your shell is bash, the output of bind -p | grep \C-a should give you the current action binded to Ctrl+A. To bind this action to something else use the following form:

$ bind '"\C-p": beginning-of-line'

This will bind Ctrl+P to move the cursor to the beginning of the line. Remember the double-quotes inside the expression. To unset a binding you would just set it to nothing:

$ bind '"\C-a": '

To list all input sequences associated with the action, use:

$ bind -p | grep beginning-of-line

Lastly, to make the bindings permament you can put the statements in your ~/.bashrc file and issue source ~/.bashrc.

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.