How to not switch past the edge of panes in tmux
By default, tmux passes over edge of a pane. For example, suppose there are two panes, pane 1
and pane 2
. Suppose you're at pane 1
and you do Ctrl+b →, you're at the pane 2
. If you again do Ctrl+b →, you'll be again at pane 1
. How can I disable that feature so, when I'm navigating from the last pane, I don't go anywhere?
tmux
add a comment |
By default, tmux passes over edge of a pane. For example, suppose there are two panes, pane 1
and pane 2
. Suppose you're at pane 1
and you do Ctrl+b →, you're at the pane 2
. If you again do Ctrl+b →, you'll be again at pane 1
. How can I disable that feature so, when I'm navigating from the last pane, I don't go anywhere?
tmux
add a comment |
By default, tmux passes over edge of a pane. For example, suppose there are two panes, pane 1
and pane 2
. Suppose you're at pane 1
and you do Ctrl+b →, you're at the pane 2
. If you again do Ctrl+b →, you'll be again at pane 1
. How can I disable that feature so, when I'm navigating from the last pane, I don't go anywhere?
tmux
By default, tmux passes over edge of a pane. For example, suppose there are two panes, pane 1
and pane 2
. Suppose you're at pane 1
and you do Ctrl+b →, you're at the pane 2
. If you again do Ctrl+b →, you'll be again at pane 1
. How can I disable that feature so, when I'm navigating from the last pane, I don't go anywhere?
tmux
tmux
edited 8 mins ago
klaus
asked Jun 23 '18 at 8:26
klausklaus
2199
2199
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
This is a bit of a hack but might be good enough for you. From version 2.3 you can find the x and y co-ordinate of each pane's borders. For example, display -p #{pane_right}
for a pane at the right-hand edge of an 80 column terminal would be 79. If you give the command to move right to the next pane, and the new pane's pane_right
is, for example, 39, then you have moved left, so you will want to move back to the previous pane with select-pane -l
.
You can run most tmux commands from a shell script, so create the following file mytmux
in your PATH and make it executable (chmod +x mytmux
):
#!/bin/bash
# https://unix.stackexchange.com/a/451473/119298
restrict(){
case $1 in
U) d=-U p=pane_top cmp=-gt ;;
D) d=-D p=pane_bottom cmp=-lt ;;
L) d=-L p=pane_left cmp=-gt ;;
R) d=-R p=pane_right cmp=-lt ;;
*) exit 1 ;;
esac
old=$(tmux display -p "#{$p}")
tmux select-pane "$d"
new=$(tmux display -p "#{$p}")
[ "$new" "$cmp" "$old" ] && tmux select-pane -l
exit 0
}
case $1 in
-restrict)shift
restrict "${1?direction}" ;;
esac
then setup the following bindings in your ~/.tmux.conf
:
bind-key -r -T prefix Up run-shell 'mytmux -restrict U'
bind-key -r -T prefix Down run-shell 'mytmux -restrict D'
bind-key -r -T prefix Left run-shell 'mytmux -restrict L'
bind-key -r -T prefix Right run-shell 'mytmux -restrict R'
You will need to extend this if you want to handle multiple sessions, for example.
add a comment |
The PrefixArrow keys are by default bound like
bind-key -r -T prefix Up select-pane -U
bind-key -r -T prefix Down select-pane -D
bind-key -r -T prefix Left select-pane -L
bind-key -r -T prefix Right select-pane -R
The select-pane
function does not have an option that tells it "don't cycle when you've reached the last pane in that direction".
Looking at the source code that is executed for select-pane
, it looks like the cycling left/right and top/bottom is hard-coded in, which means that it's unlikely to be easy to stop it from behaving in this way.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451437%2fhow-to-not-switch-past-the-edge-of-panes-in-tmux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is a bit of a hack but might be good enough for you. From version 2.3 you can find the x and y co-ordinate of each pane's borders. For example, display -p #{pane_right}
for a pane at the right-hand edge of an 80 column terminal would be 79. If you give the command to move right to the next pane, and the new pane's pane_right
is, for example, 39, then you have moved left, so you will want to move back to the previous pane with select-pane -l
.
You can run most tmux commands from a shell script, so create the following file mytmux
in your PATH and make it executable (chmod +x mytmux
):
#!/bin/bash
# https://unix.stackexchange.com/a/451473/119298
restrict(){
case $1 in
U) d=-U p=pane_top cmp=-gt ;;
D) d=-D p=pane_bottom cmp=-lt ;;
L) d=-L p=pane_left cmp=-gt ;;
R) d=-R p=pane_right cmp=-lt ;;
*) exit 1 ;;
esac
old=$(tmux display -p "#{$p}")
tmux select-pane "$d"
new=$(tmux display -p "#{$p}")
[ "$new" "$cmp" "$old" ] && tmux select-pane -l
exit 0
}
case $1 in
-restrict)shift
restrict "${1?direction}" ;;
esac
then setup the following bindings in your ~/.tmux.conf
:
bind-key -r -T prefix Up run-shell 'mytmux -restrict U'
bind-key -r -T prefix Down run-shell 'mytmux -restrict D'
bind-key -r -T prefix Left run-shell 'mytmux -restrict L'
bind-key -r -T prefix Right run-shell 'mytmux -restrict R'
You will need to extend this if you want to handle multiple sessions, for example.
add a comment |
This is a bit of a hack but might be good enough for you. From version 2.3 you can find the x and y co-ordinate of each pane's borders. For example, display -p #{pane_right}
for a pane at the right-hand edge of an 80 column terminal would be 79. If you give the command to move right to the next pane, and the new pane's pane_right
is, for example, 39, then you have moved left, so you will want to move back to the previous pane with select-pane -l
.
You can run most tmux commands from a shell script, so create the following file mytmux
in your PATH and make it executable (chmod +x mytmux
):
#!/bin/bash
# https://unix.stackexchange.com/a/451473/119298
restrict(){
case $1 in
U) d=-U p=pane_top cmp=-gt ;;
D) d=-D p=pane_bottom cmp=-lt ;;
L) d=-L p=pane_left cmp=-gt ;;
R) d=-R p=pane_right cmp=-lt ;;
*) exit 1 ;;
esac
old=$(tmux display -p "#{$p}")
tmux select-pane "$d"
new=$(tmux display -p "#{$p}")
[ "$new" "$cmp" "$old" ] && tmux select-pane -l
exit 0
}
case $1 in
-restrict)shift
restrict "${1?direction}" ;;
esac
then setup the following bindings in your ~/.tmux.conf
:
bind-key -r -T prefix Up run-shell 'mytmux -restrict U'
bind-key -r -T prefix Down run-shell 'mytmux -restrict D'
bind-key -r -T prefix Left run-shell 'mytmux -restrict L'
bind-key -r -T prefix Right run-shell 'mytmux -restrict R'
You will need to extend this if you want to handle multiple sessions, for example.
add a comment |
This is a bit of a hack but might be good enough for you. From version 2.3 you can find the x and y co-ordinate of each pane's borders. For example, display -p #{pane_right}
for a pane at the right-hand edge of an 80 column terminal would be 79. If you give the command to move right to the next pane, and the new pane's pane_right
is, for example, 39, then you have moved left, so you will want to move back to the previous pane with select-pane -l
.
You can run most tmux commands from a shell script, so create the following file mytmux
in your PATH and make it executable (chmod +x mytmux
):
#!/bin/bash
# https://unix.stackexchange.com/a/451473/119298
restrict(){
case $1 in
U) d=-U p=pane_top cmp=-gt ;;
D) d=-D p=pane_bottom cmp=-lt ;;
L) d=-L p=pane_left cmp=-gt ;;
R) d=-R p=pane_right cmp=-lt ;;
*) exit 1 ;;
esac
old=$(tmux display -p "#{$p}")
tmux select-pane "$d"
new=$(tmux display -p "#{$p}")
[ "$new" "$cmp" "$old" ] && tmux select-pane -l
exit 0
}
case $1 in
-restrict)shift
restrict "${1?direction}" ;;
esac
then setup the following bindings in your ~/.tmux.conf
:
bind-key -r -T prefix Up run-shell 'mytmux -restrict U'
bind-key -r -T prefix Down run-shell 'mytmux -restrict D'
bind-key -r -T prefix Left run-shell 'mytmux -restrict L'
bind-key -r -T prefix Right run-shell 'mytmux -restrict R'
You will need to extend this if you want to handle multiple sessions, for example.
This is a bit of a hack but might be good enough for you. From version 2.3 you can find the x and y co-ordinate of each pane's borders. For example, display -p #{pane_right}
for a pane at the right-hand edge of an 80 column terminal would be 79. If you give the command to move right to the next pane, and the new pane's pane_right
is, for example, 39, then you have moved left, so you will want to move back to the previous pane with select-pane -l
.
You can run most tmux commands from a shell script, so create the following file mytmux
in your PATH and make it executable (chmod +x mytmux
):
#!/bin/bash
# https://unix.stackexchange.com/a/451473/119298
restrict(){
case $1 in
U) d=-U p=pane_top cmp=-gt ;;
D) d=-D p=pane_bottom cmp=-lt ;;
L) d=-L p=pane_left cmp=-gt ;;
R) d=-R p=pane_right cmp=-lt ;;
*) exit 1 ;;
esac
old=$(tmux display -p "#{$p}")
tmux select-pane "$d"
new=$(tmux display -p "#{$p}")
[ "$new" "$cmp" "$old" ] && tmux select-pane -l
exit 0
}
case $1 in
-restrict)shift
restrict "${1?direction}" ;;
esac
then setup the following bindings in your ~/.tmux.conf
:
bind-key -r -T prefix Up run-shell 'mytmux -restrict U'
bind-key -r -T prefix Down run-shell 'mytmux -restrict D'
bind-key -r -T prefix Left run-shell 'mytmux -restrict L'
bind-key -r -T prefix Right run-shell 'mytmux -restrict R'
You will need to extend this if you want to handle multiple sessions, for example.
edited Jun 23 '18 at 14:42
answered Jun 23 '18 at 14:23
meuhmeuh
32.3k12054
32.3k12054
add a comment |
add a comment |
The PrefixArrow keys are by default bound like
bind-key -r -T prefix Up select-pane -U
bind-key -r -T prefix Down select-pane -D
bind-key -r -T prefix Left select-pane -L
bind-key -r -T prefix Right select-pane -R
The select-pane
function does not have an option that tells it "don't cycle when you've reached the last pane in that direction".
Looking at the source code that is executed for select-pane
, it looks like the cycling left/right and top/bottom is hard-coded in, which means that it's unlikely to be easy to stop it from behaving in this way.
add a comment |
The PrefixArrow keys are by default bound like
bind-key -r -T prefix Up select-pane -U
bind-key -r -T prefix Down select-pane -D
bind-key -r -T prefix Left select-pane -L
bind-key -r -T prefix Right select-pane -R
The select-pane
function does not have an option that tells it "don't cycle when you've reached the last pane in that direction".
Looking at the source code that is executed for select-pane
, it looks like the cycling left/right and top/bottom is hard-coded in, which means that it's unlikely to be easy to stop it from behaving in this way.
add a comment |
The PrefixArrow keys are by default bound like
bind-key -r -T prefix Up select-pane -U
bind-key -r -T prefix Down select-pane -D
bind-key -r -T prefix Left select-pane -L
bind-key -r -T prefix Right select-pane -R
The select-pane
function does not have an option that tells it "don't cycle when you've reached the last pane in that direction".
Looking at the source code that is executed for select-pane
, it looks like the cycling left/right and top/bottom is hard-coded in, which means that it's unlikely to be easy to stop it from behaving in this way.
The PrefixArrow keys are by default bound like
bind-key -r -T prefix Up select-pane -U
bind-key -r -T prefix Down select-pane -D
bind-key -r -T prefix Left select-pane -L
bind-key -r -T prefix Right select-pane -R
The select-pane
function does not have an option that tells it "don't cycle when you've reached the last pane in that direction".
Looking at the source code that is executed for select-pane
, it looks like the cycling left/right and top/bottom is hard-coded in, which means that it's unlikely to be easy to stop it from behaving in this way.
answered Jun 23 '18 at 9:37
KusalanandaKusalananda
132k17253416
132k17253416
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451437%2fhow-to-not-switch-past-the-edge-of-panes-in-tmux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown