87

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?

user11498
  • 2,441

3 Answers3

100

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

enzotib
  • 51,661
angus
  • 12,321
  • 3
  • 45
  • 40
  • 11
    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: http://aperiodic.net/screen/quick_reference – Yzmir Ramirez Nov 05 '15 at 22:21
13

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.

  • 8
    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 04:16
6

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.