How to swap the buffers in 2 windows emacs

Viewed 34736

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 the frame into two windows: C-x 3

I then open another file C-x C-f file2.c RET

So I have 2 files:

window 1 (left) file1.c

window 2 (right) file2.c

I am wondering if there is any key combination to swap the files over? Normally I like to work on the left window when I have 2 window. I know I can easily do C-x oto move the cursor to the right window.

However, I am just wondering if I can swap the files so that file2.c is in the left window and file1.c is in the right window?

10 Answers

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?

As current emacs 29 version. We have windmove , its like magic of swapping windows.

windmove-swap-states-right windmove-swap-states-up windmove-swap-states-left windmove-swap-states-down

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

If you use Ace window, which I highly recommend, you can swap buffers with ace-swap-window.

Related