While using GNU Screen in copy mode, I sometimes want to abort in the middle and go back to the prompt. What command will exactly achieve that ?
Abort copy mode in Screen
gnu-screen
Related Solutions
Put a line with
defnonblock on
in ~/.screenrc
Also recommend
defflow off
to pass Ctrl-Q and Ctrl-S to applications instead of blocking screen output.
Yes, there is. Although there is not (currently) a bindkey
flag that affects only copy-mode (not command-mode also) there is still a way to get similar results, though it means learning a new syntax for doing so.
The fix
The markkeys
command affects copy-mode only, and will not affect command-mode behaviors. It's pickier about what characters it will accept, but it's better than nothing, and gets the job done in this situation:
markkeys "$=\205"
markkeys "\^=\201"
The above tells screen
to alias the start-of-line and end-of-line and signals (which are sent by Home and End) to the ^ and $ movement keys respectively. ^
is written escaped as \^
in the string because it's normally used to set off escaped sequences but we mean the literal thing.
Note that if you would prefer Home to go all the way to the beginning/left instead of just to the first visible character, then replace markkeys "\^=\201"
with markkeys "0=\201"
.
Note also that you can still use g and G to get to the global beginning or end of a window's history while in copy mode.
How I found the fix
Although I still don't know of a complete reference that lays out all of the useful hex-escapes for such things, I was able to find the two relevant ones by running bindkey -m
within screen and then overriding the mappings there until I broke the behavior I was interested in. The relevant lines were:
kh -> stuff \201
kH -> stuff \205
With some help from the folks in irc://irc.freenode.net/screen I learned the lefthand codes can be looked up from the shell via man terminfo
, which has them listed in the Tcap column as
Variable Capname TCap Code Description
string
---------------------------------------------------------------------------
key_home khome kh home key
...
key_ll kll kH lower-left key (home down)
Putting two and two together and doing a bit of guesswork to get the binding right lead to the above fix.
Best Answer
I think you want to use the Esc key. At least, that is what I use to get out of copy mode in screen.
There are many alternative strategies as well, including hitting q, or hitting the Return key twice.