-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using hotkeys to move between tmux panes #116
Comments
By windows, you mean tmux windows (tabs)? So basically, for example when you select pane on the right, and there's no pane there, you want to go to next window? |
If yes, you can bind it directly in tmux with something like this:
|
No by windows I mean windows of whatever program is open, e.g. switching between my terminal and browser and so on. That's why it's so tricky, I somehow have to tell skhd to switch windows (between programs) only if the window is not a terminal with an istance of tmux open and a pane open in that direction. So for example consider this situation. If I'm focusing firefox and I press Finally, if I'm focusing the top tmux pane and I press |
Ok, I get it. I see you're using yabai or chunkwm. I think you would need to do something like this in tmux.conf:
I used prefix C-hjkl here, but it doesn't matter in the end. And now, in skhd you would need to bind |
Don't do that. Do this instead:
It's important that you use different keybindings here, otherwise you end up in an infinite loop. |
Personally, I have vim splits nested in tmux panes nested in yabai managed windows and it leads me to question my sanity (Easing management of vim splits in tmux is pretty well documented, though) |
That should work while in a tmux session, but what if I'm not? I'm gonna send an |
Set up the keybinding not in your tmux configuration, but rather in your zshrc/bashrc, and have it act differently depending on whether you're in a multiplexer or not. |
Ok I solved it. The solution was a lot simpler than I was thinking. Instead of spreading parts between my alacritty, shell, tmux and skhd config files, everything can be done within skhd. Simply using
works like a charm. Also setting up the keybindings in my zshrc wouldn't work when I'm in vim or any other program that is not a shell. Thanks everyone! |
I'm reopening this issue because I've come across a problem with the solution I had which I've been trying to solve for the last few hours, clearly without any success. The problem is that (using the
only checks if the pane currently focused in the tmux session is at the bottom, but doesn't check if the alacritty window has a tmux session running inside it. So consider this situation: the top window is not running any tmux sessions, while the bottom one has a session with two panes, one below the other. I'm focusing the top window, and the last focused pane in the bottom window is the top one.
is going to return 0, and instead of switching windows I switch panes, while still focusing the top window. Now the focused pane is the bottom one so I need a way to tell if I'm a tmux session or not, which is not too hard since tmux sets the I'm sorry to be asking more of your time, but I really couldn't come up with a solution myself. |
Im interested to know whether this helps you, https://superuser.com/questions/410017/how-do-i-know-current-tmux-session-name-by-running-tmux-command Some of these solutions rely on the env vars but it looks like some are a bit more robust |
@mstr3336 I don't think those solutions apply here. The issue is not that using the I need a way to say: hey Right now I'm saying: hey |
@synchronizing I'm not trying to share the same keybindings between tmux panes and vim splits, I'm trying to share them between tmux panes and all the other programs (browser, pdf viewer, etc...) |
Could you set the title of the terminal window to be e.g. "TMUX" when you run tmux? Then, if you use yabai as a window manager you can query the title of the focused window as is done here koekeishiya/yabai#75 |
I'm trying to make it also work seamlessy with vim following https://www.codeography.com/2013/06/19/navigating-vim-and-tmux-splits this guide and placing in my skhdrc:
This still works for tmux but not for vim :( Does anyone know how could we solve this ? ctrl - h sometimes seems to work |
Maybe it's because skhd keys have higher priority than vim keys, but if we're in vim should we let vim do the work ? |
https://github.com/christoomey/vim-tmux-navigator Hm, seems like you're asking tmux directly to do the work. I'm not sure that that really gives vim a chance to pick up the keypress and then delegate to the function |
Tried it but couldn't get it to work :( |
Does vim tmux navigator work correctly without skhd being involved? I'll share my dotfiles soon |
Yes, works fine |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@danielfalbo link to commits are broken? |
Yeah, they're broken because I switched to a bare dotfiles repo and deleted the old one. Anyway, I'm not using the vim-tmux-yabai thing anymore, I'm now using iTerm's built-in tmux integration, so I just create new native iTerm windows, which are managed by tmux, and simply use yabai to jump between the windows. Screen.Recording.2021-06-05.at.15.04.32.movIt's not quite the same and it may or may not be the best solution based on your workflow, so if you're still trying to achieve vim-tmux-yabai navigation, try the following.
|
@danielfalbo Thank you! I really appreciate your help. |
Please provide an example scenario so I can reproduce the issue 👍 |
@danielfalbo It happens when in one screen I have 2 browser windows open and I open an Alacritty window, I move around find till I activate the Alacritty window, then the shortcuts doesn't work and I can't leave the Alacritty window Also the error I mentioned above happens when I have one Alacritty window running 2 tmux panes and vim is running in one (with multiple splits) and one is running a script (for example a dev server running and watching files) then the stdout of the server gets clear and I see the error message |
Oh, I see. It doesn't work if the terminal emulator is not running tmux, and I'm not sure it works if there are multiple terminal emulator windows running different tmux sessions. Right now I can't think of a solution to this, solving this would probably also solve the issue discussed above. A temporary workaround may be mapping 'Ctrl+{h, j, k, l}' to 'yabai -m window --focus {west, south, north, east}' in your shell when the variable
Try giving execution permissions to the script by running |
@danielfalbo Did you ever find a solution for this when multiple tmux sessions are open? |
@jdrupal-dev unfortunately not 😄 |
Actually, I just tried rebooting after implementing your code, and now it works with multiple monitors and multiple open tmux sessions. |
haha sounds great to hear after years that solution is still good |
I'd like to use the same keys I use to switch focus between windows (
alt - up
,alt - down
etc...)to switch focus between tmux panes.
Now I don't know if this is a): possible at all, and b): something to be handled by skhd, but I'll try to explain what I do now and hopefully someone can put me on the right track.
Switching focus between tmux panes is done by pressing the prefix key, by default
ctrl - b
, followed by the arrow key (up, down etc...) corresponding with the direction of the window one wants to focus.Instead of pressing ctrl-b and an arrow key all the time, in my alacritty config file I have set a key binding so that when I press, for example,
cmd + alt - up
, alacritty sends the code\x02\x1b\x5b\x41
, which corresponds toctrl - b
followed by an up arrow.So to switch between windows I need to press
alt - up
and to switch between panes I need to presscmd + alt - up
. While this is an improvement from the default way, it's still counterintuitive.Is there a way to implement this?
The text was updated successfully, but these errors were encountered: