James Owers
James Owers

Reputation: 8335

GNU Screen: Reverse focus tabbing

Is it possible to bind Ctrl+a Shift+Tab to switch focus to the previous window in the list (much like Ctrl+a p but changing the focus)?

Specifically, I want to skip from the first to the last. For example, here is a screen profile:

# Vertical split with two on right
#
# +---+---+
# |   |   |
# |   |---|
# |   |   |
# +---+---+
#
split -v
screen bash
title "main"
focus
split
screen bash
title "script"
focus
screen bash
title "interpreter"
focus left

# ctrl+a navigating regions
bind j focus down
bind k focus up
bind h focus left
bind l focus right

Focus starts in the top left screen. I'd like to jump straight to the bottom right. I can do this by hitting Ctrl+a Tab twice. Is there a single command and, if so, how could I bind this to Ctrl+a Shift+Tab?

Edit

Have just found Ctrl+a Ctrl+i switches to the next window as well (strangely not info). I'm on Screen version 4.01.00devel (GNU) 2-May-06

Good workaround

Add the following to your screen profile (or ~/.screenrc)

## ctrl+a navigating regions
bindkey "^j" focus down
bindkey "^k" focus up
bindkey "^h" focus left
bindkey "^l" focus right

Now you can zip around quickly by holding Ctrl + h/j/k/l in a vim-esque style.

Upvotes: 3

Views: 1280

Answers (3)

waddles
waddles

Reputation: 61

focus prev and focus next can switch region no matter it's the last or first

Also you can use multiple focus in one bind, add below to .screenrc can replace focus left and right when use a 3x2 region layout

bindkey "^a^o" eval "focus next" "focus next"
bindkey "^a^y" eval "focus prev" "focus prev"

Upvotes: 0

Jason
Jason

Reputation: 719

Here is my ~/.screenrc

bindkey "^k" focus prev
bindkey "^l" focus next

Need to activate if ~/.screenrc does not already exist: Ctrl+a, Shift+:, source ~/.screenrc

Then we can:

Ctrl+l to cycle to the next split screen

Ctrl+k for cycle to the previous split screen!

UPDATE:

Having used this screen config for a day, I find that I somehow messed up other keyboard shortcuts. For example, when I press "Esc" in Vim to come out of editing mode, the screen was focusing on the previous screen instead!

So I cancelled the shortcuts I created by coming out of all the split screens, removing the ~/.screenrc file and starting again.

To be honest, I can live with just using Crtl-a, Shift to cycle though split screens, given the consequences of messing up other shortcut keys!

Upvotes: 0

14mRh4X0r
14mRh4X0r

Reputation: 155

The command you're looking for is focus prev.

Unfortunately, there is no way to bind Shift+Tab, since bind does not allow for modifier keys, and Tab is equivalent to Ctrl+i (which also explains why it's bound to focus instead of info), so you'd have to bind it to a different key.

Upvotes: 4

Related Questions