How to swap the buffers in 2 windows emacs

前端 未结 8 1413
情深已故
情深已故 2020-12-22 20:51

I am using emacs I find that sometimes I have 2 files separated into 2 windows.

For example: I open 1 file using C-x C-f file1.c RET

and I split t

相关标签:
8条回答
  • 2020-12-22 20:58

    If you have prelude, you can use ace-window with S-w. From there you can do many things listed in their docs.

    You can also start by calling ace-window and then decide to switch the action to delete or swap etc. By default the bindings are:

    x - delete window

    m - swap (move) window

    c - split window fairly, either vertically or horizontally

    v - split window vertically

    b - split window horizontally

    n - select the previous window

    ...

    So it would be S-w m

    0 讨论(0)
  • 2020-12-22 21:07

    I use buffer-move for this. Now if you are working on the buffer on the left side, calling 'buf-move-right' will swap it with the one on the right. I guess this is what you want.

    0 讨论(0)
  • 2020-12-22 21:10

    I would contrive to open up file #2 in the desired location, i.e. after you hit c-x 3, move the cursor with c-x o before navigating to the second file.

    0 讨论(0)
  • 2020-12-22 21:11

    I'm not aware of any built-in function doing this.

    However, it does not seem too difficult to whip up some elisp for doing it. Devil is in the details though.

    (defun swap-buffers-in-windows ()
      "Put the buffer from the selected window in next window, and vice versa"
      (interactive)
      (let* ((this (selected-window))
         (other (next-window))
         (this-buffer (window-buffer this))
         (other-buffer (window-buffer other)))
        (set-window-buffer other this-buffer)
        (set-window-buffer this other-buffer)
        )
      )
    

    Notably, this may not be doing what you desire with respect to where the caret ends up. However, you'd first have to say what you want :p

    0 讨论(0)
  • 2020-12-22 21:12

    The transpose-frame library provides a pretty comprehensive set of functions for flipping or rotating the window arrangements in frames.

    M-x flop-frame RET does what this particular question needs.

    The following diagrams are from the commentary in the library (and its EmacsWiki page):

    ‘transpose-frame’ … Swap x-direction and y-direction
    
           +------------+------------+      +----------------+--------+
           |            |     B      |      |        A       |        |
           |     A      +------------+      |                |        |
           |            |     C      |  =>  +--------+-------+   D    |
           +------------+------------+      |   B    |   C   |        |
           |            D            |      |        |       |        |
           +-------------------------+      +--------+-------+--------+
    
    ‘flip-frame’ … Flip vertically
    
           +------------+------------+      +------------+------------+
           |            |     B      |      |            D            |
           |     A      +------------+      +------------+------------+
           |            |     C      |  =>  |            |     C      |
           +------------+------------+      |     A      +------------+
           |            D            |      |            |     B      |
           +-------------------------+      +------------+------------+
    
    ‘flop-frame’ … Flop horizontally
    
           +------------+------------+      +------------+------------+
           |            |     B      |      |     B      |            |
           |     A      +------------+      +------------+     A      |
           |            |     C      |  =>  |     C      |            |
           +------------+------------+      +------------+------------+
           |            D            |      |            D            |
           +-------------------------+      +-------------------------+
    
    ‘rotate-frame’ … Rotate 180 degrees
    
           +------------+------------+      +-------------------------+
           |            |     B      |      |            D            |
           |     A      +------------+      +------------+------------+
           |            |     C      |  =>  |     C      |            |
           +------------+------------+      +------------+     A      |
           |            D            |      |     B      |            |
           +-------------------------+      +------------+------------+
    
    ‘rotate-frame-clockwise’ … Rotate 90 degrees clockwise
    
           +------------+------------+      +-------+-----------------+
           |            |     B      |      |       |        A        |
           |     A      +------------+      |       |                 |
           |            |     C      |  =>  |   D   +--------+--------+
           +------------+------------+      |       |   B    |   C    |
           |            D            |      |       |        |        |
           +-------------------------+      +-------+--------+--------+
    
    ‘rotate-frame-anti-clockwise’ … Rotate 90 degrees anti-clockwise
    
           +------------+------------+      +--------+--------+-------+
           |            |     B      |      |   B    |   C    |       |
           |     A      +------------+      |        |        |       |
           |            |     C      |  =>  +--------+--------+   D   |
           +------------+------------+      |        A        |       |
           |            D            |      |                 |       |
           +-------------------------+      +-----------------+-------+
    
    0 讨论(0)
  • 2020-12-22 21:13

    In the Emacs 26.1 NEWS file there is the following entry:

    +++
    *** New command 'window-swap-states' swaps the states of two live
    windows.
    

    Which appears to offer similar functionality to crux-transpose-windows but can also do some height/width transpositions?

    0 讨论(0)
提交回复
热议问题