aserowy / tmux.nvim

tmux integration for nvim features pane movement and resizing from within nvim.
MIT License
642 stars 40 forks source link

Add functions to swap panes / windows across tmux / nvim #128

Open voskresenie opened 2 weeks ago

voskresenie commented 2 weeks ago

I realized the other day that it would be nice to have a feature that allows swapping tmux panes and nvim windows (splits) with the same keybinding without conflicting. This can't work perfectly seamlessly the way move does, because you can't intermix tmux panes with nvim windows, so I would understand if it's not something you're interested in adding to the plugin, but it could at least enable using the same binding for swapping panes as swapping windows.

Here is how I was thinking the logic would work:

swap_[direction]:
- if current pane is not nvim, then swap with pane in [direction] (if present) using tmux swap-pane
Example:
    From PaneA, call swap_right()
    -----------------      -----------------
    | Tmux  | Tmux  | ---> | Tmux  | Tmux  |
    | PaneA | PaneB | ---> | PaneB | PaneA |
    -----------------      -----------------

- if current pane /is/ nvim, and [direction] is another window inside the same nvim instance, swap the two windows, mimicking functionality of tmux pane swapping as closely as possible (not built in to nvim afaik)
Example:
    From WinA, call swap_right()
    ----------------------      ----------------------
    | Nvim | Nvim | Tmux | ---> | Nvim | Nvim | Tmux |
    | WinA | WinB | Pane | ---> | WinB | WinA | Pane |
    ----------------------      ----------------------

- if current pane is /nvim/, and [direction] is a different tmux pane (ie current nvim window is on the [direction] border of the current pane), swap current pane with [direction] pane using tmux swap-pane
Example:
    From WinB, call swap_right()
    ----------------------      ----------------------
    | Nvim | Nvim | Tmux | ---> | Tmux | Nvim | Nvim |
    | WinA | WinB | Pane | ---> | Pane | WinA | WinB |
    ----------------------      ----------------------

So, it would be pretty much how you would expect swapping to behave if nvim windows and tmux panes were all the same thing, except that instead of swapping an nvim window and tmux pane when on the border, it would have to swap the entire pane the nvim window is a part of (which may appear, visually, as if several panes were swapped at once). I realize that this aspect may be a poor experience and understand if it's not something you'd be interested in having in this plugin, but if you are interested, I have a version I can tidy up and send for PR.

aserowy commented 1 week ago

to be clear: pr are welcome! It would be cool, to get unit tests up and running and an extended readme.

tyvm Alexander