Tmux keybinding to swap pane left or right












5















I'm aware that :swap-pane -U and :swap-pane -D will swap panes up or down, but I'd like a keybinding to swap panes left and right.



The only way I can think of to do this would be to first determine the pane index of the current pane, then run :select-pane -R or -L and determine its index, and finally run :swap-pane -s (first pane index) -t (second pane index).



I'm just not sure how to do this in .tmux.conf - is it possible to have subcommands which return something within another command?



For example, something like this:



bind-key -n C-{ swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -L'**



bind-key -n C-} swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -R'**










share|improve this question



























    5















    I'm aware that :swap-pane -U and :swap-pane -D will swap panes up or down, but I'd like a keybinding to swap panes left and right.



    The only way I can think of to do this would be to first determine the pane index of the current pane, then run :select-pane -R or -L and determine its index, and finally run :swap-pane -s (first pane index) -t (second pane index).



    I'm just not sure how to do this in .tmux.conf - is it possible to have subcommands which return something within another command?



    For example, something like this:



    bind-key -n C-{ swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -L'**



    bind-key -n C-} swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -R'**










    share|improve this question

























      5












      5








      5


      3






      I'm aware that :swap-pane -U and :swap-pane -D will swap panes up or down, but I'd like a keybinding to swap panes left and right.



      The only way I can think of to do this would be to first determine the pane index of the current pane, then run :select-pane -R or -L and determine its index, and finally run :swap-pane -s (first pane index) -t (second pane index).



      I'm just not sure how to do this in .tmux.conf - is it possible to have subcommands which return something within another command?



      For example, something like this:



      bind-key -n C-{ swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -L'**



      bind-key -n C-} swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -R'**










      share|improve this question














      I'm aware that :swap-pane -U and :swap-pane -D will swap panes up or down, but I'd like a keybinding to swap panes left and right.



      The only way I can think of to do this would be to first determine the pane index of the current pane, then run :select-pane -R or -L and determine its index, and finally run :swap-pane -s (first pane index) -t (second pane index).



      I'm just not sure how to do this in .tmux.conf - is it possible to have subcommands which return something within another command?



      For example, something like this:



      bind-key -n C-{ swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -L'**



      bind-key -n C-} swap-pane -s **get current pane ID** -t **get pane ID of 'select-pane -R'**







      tmux






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 22 '16 at 2:15









      DC_DC_

      787




      787






















          2 Answers
          2






          active

          oldest

          votes


















          7





          +50









          :bind-key -n C-{ select-pane -L ; swap-pane -s '!'



          This should tell tmux to select the left pane, and then swap with the previously active pane.



          Also, swap-pane -s {right-of} seems to work.

          Here is the list of ways to refer to other panes:



          {last} !       The last (previously active) pane
          {next} + The next pane by number
          {previous} - The previous pane by number
          {top} The top pane
          {bottom} The bottom pane
          {left} The leftmost pane
          {right} The rightmost pane
          {top-left} The top-left pane
          {top-right} The top-right pane
          {bottom-left} The bottom-left pane
          {bottom-right} The bottom-right pane
          {up-of} The pane above the active pane
          {down-of} The pane below the active pane
          {left-of} The pane to the left of the active pane
          {right-of} The pane to the right of the active pane


          See the online man page for reference.






          share|improve this answer


























          • Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

            – DC_
            May 25 '16 at 5:55








          • 1





            Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

            – Isaac Hanson
            May 25 '16 at 11:55











          • Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

            – lleaff
            Feb 17 '17 at 14:59



















          1














          One can also add following line to ~/.tmux.conf



          bind v swap-pane -s '!' -t $TMUX_PANE


          This will interchange current pane with the last visited pane. Consecutively go to the two panes needed to be interchanged and use <prefix>v (above command) to perform the swap. Note that <prefix>q shows the id of the panes. The additional advantage is that the swapping also works across different windows.






          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1079462%2ftmux-keybinding-to-swap-pane-left-or-right%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









            7





            +50









            :bind-key -n C-{ select-pane -L ; swap-pane -s '!'



            This should tell tmux to select the left pane, and then swap with the previously active pane.



            Also, swap-pane -s {right-of} seems to work.

            Here is the list of ways to refer to other panes:



            {last} !       The last (previously active) pane
            {next} + The next pane by number
            {previous} - The previous pane by number
            {top} The top pane
            {bottom} The bottom pane
            {left} The leftmost pane
            {right} The rightmost pane
            {top-left} The top-left pane
            {top-right} The top-right pane
            {bottom-left} The bottom-left pane
            {bottom-right} The bottom-right pane
            {up-of} The pane above the active pane
            {down-of} The pane below the active pane
            {left-of} The pane to the left of the active pane
            {right-of} The pane to the right of the active pane


            See the online man page for reference.






            share|improve this answer


























            • Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

              – DC_
              May 25 '16 at 5:55








            • 1





              Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

              – Isaac Hanson
              May 25 '16 at 11:55











            • Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

              – lleaff
              Feb 17 '17 at 14:59
















            7





            +50









            :bind-key -n C-{ select-pane -L ; swap-pane -s '!'



            This should tell tmux to select the left pane, and then swap with the previously active pane.



            Also, swap-pane -s {right-of} seems to work.

            Here is the list of ways to refer to other panes:



            {last} !       The last (previously active) pane
            {next} + The next pane by number
            {previous} - The previous pane by number
            {top} The top pane
            {bottom} The bottom pane
            {left} The leftmost pane
            {right} The rightmost pane
            {top-left} The top-left pane
            {top-right} The top-right pane
            {bottom-left} The bottom-left pane
            {bottom-right} The bottom-right pane
            {up-of} The pane above the active pane
            {down-of} The pane below the active pane
            {left-of} The pane to the left of the active pane
            {right-of} The pane to the right of the active pane


            See the online man page for reference.






            share|improve this answer


























            • Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

              – DC_
              May 25 '16 at 5:55








            • 1





              Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

              – Isaac Hanson
              May 25 '16 at 11:55











            • Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

              – lleaff
              Feb 17 '17 at 14:59














            7





            +50







            7





            +50



            7




            +50





            :bind-key -n C-{ select-pane -L ; swap-pane -s '!'



            This should tell tmux to select the left pane, and then swap with the previously active pane.



            Also, swap-pane -s {right-of} seems to work.

            Here is the list of ways to refer to other panes:



            {last} !       The last (previously active) pane
            {next} + The next pane by number
            {previous} - The previous pane by number
            {top} The top pane
            {bottom} The bottom pane
            {left} The leftmost pane
            {right} The rightmost pane
            {top-left} The top-left pane
            {top-right} The top-right pane
            {bottom-left} The bottom-left pane
            {bottom-right} The bottom-right pane
            {up-of} The pane above the active pane
            {down-of} The pane below the active pane
            {left-of} The pane to the left of the active pane
            {right-of} The pane to the right of the active pane


            See the online man page for reference.






            share|improve this answer















            :bind-key -n C-{ select-pane -L ; swap-pane -s '!'



            This should tell tmux to select the left pane, and then swap with the previously active pane.



            Also, swap-pane -s {right-of} seems to work.

            Here is the list of ways to refer to other panes:



            {last} !       The last (previously active) pane
            {next} + The next pane by number
            {previous} - The previous pane by number
            {top} The top pane
            {bottom} The bottom pane
            {left} The leftmost pane
            {right} The rightmost pane
            {top-left} The top-left pane
            {top-right} The top-right pane
            {bottom-left} The bottom-left pane
            {bottom-right} The bottom-right pane
            {up-of} The pane above the active pane
            {down-of} The pane below the active pane
            {left-of} The pane to the left of the active pane
            {right-of} The pane to the right of the active pane


            See the online man page for reference.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 17 '17 at 15:30









            lleaff

            1034




            1034










            answered May 24 '16 at 18:39









            Isaac HansonIsaac Hanson

            47327




            47327













            • Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

              – DC_
              May 25 '16 at 5:55








            • 1





              Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

              – Isaac Hanson
              May 25 '16 at 11:55











            • Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

              – lleaff
              Feb 17 '17 at 14:59



















            • Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

              – DC_
              May 25 '16 at 5:55








            • 1





              Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

              – Isaac Hanson
              May 25 '16 at 11:55











            • Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

              – lleaff
              Feb 17 '17 at 14:59

















            Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

            – DC_
            May 25 '16 at 5:55







            Awesome! I had no idea that you could reference those variables, that's super useful. I'll award the bounty as soon as it allows me to, thanks! I was referring to this man page which I guess is probably outdated because my local tmux manpage lists these variables while that one doesn't.

            – DC_
            May 25 '16 at 5:55






            1




            1





            Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

            – Isaac Hanson
            May 25 '16 at 11:55





            Great! this is the man page I used. also has similar info for "windows" in addition to "panes".

            – Isaac Hanson
            May 25 '16 at 11:55













            Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

            – lleaff
            Feb 17 '17 at 14:59





            Those variables are a god-send. How come so few answers and tutorials mention them, I wish I knew about this earlier.

            – lleaff
            Feb 17 '17 at 14:59













            1














            One can also add following line to ~/.tmux.conf



            bind v swap-pane -s '!' -t $TMUX_PANE


            This will interchange current pane with the last visited pane. Consecutively go to the two panes needed to be interchanged and use <prefix>v (above command) to perform the swap. Note that <prefix>q shows the id of the panes. The additional advantage is that the swapping also works across different windows.






            share|improve this answer






























              1














              One can also add following line to ~/.tmux.conf



              bind v swap-pane -s '!' -t $TMUX_PANE


              This will interchange current pane with the last visited pane. Consecutively go to the two panes needed to be interchanged and use <prefix>v (above command) to perform the swap. Note that <prefix>q shows the id of the panes. The additional advantage is that the swapping also works across different windows.






              share|improve this answer




























                1












                1








                1







                One can also add following line to ~/.tmux.conf



                bind v swap-pane -s '!' -t $TMUX_PANE


                This will interchange current pane with the last visited pane. Consecutively go to the two panes needed to be interchanged and use <prefix>v (above command) to perform the swap. Note that <prefix>q shows the id of the panes. The additional advantage is that the swapping also works across different windows.






                share|improve this answer















                One can also add following line to ~/.tmux.conf



                bind v swap-pane -s '!' -t $TMUX_PANE


                This will interchange current pane with the last visited pane. Consecutively go to the two panes needed to be interchanged and use <prefix>v (above command) to perform the swap. Note that <prefix>q shows the id of the panes. The additional advantage is that the swapping also works across different windows.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 3 at 17:01

























                answered Jan 3 at 7:40









                Nishan JainNishan Jain

                112




                112






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • 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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1079462%2ftmux-keybinding-to-swap-pane-left-or-right%23new-answer', 'question_page');
                    }
                    );

                    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







                    Popular posts from this blog

                    Список кардиналов, возведённых папой римским Каликстом III

                    Deduzione

                    Mysql.sock missing - “Can't connect to local MySQL server through socket”