How to swap the buffers in 2 windows emacs

emacs switch-window
emacs buffer-move
emacs ace-window
spacemacs swap windows
emacs switch between files
emacs close buffer
spacemacs ace-window
emacs open two buffers

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?

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.

How to swap the buffers in 2 windows emacs, Check out ace-window . From the GitHub link, after invoking ace-window , you can press m , and then the key corresponding to the window you  To swap the top and bottom windows when two windows are open, use a sequence of seven keys, ‘C-x 0 C-x 4 b’. More likely you are in the bottom window and want its buffer to be in the top window. In that case, use ‘C-x 0 C-x 2 C-x b RET’.

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            |      |                 |       |
       +-------------------------+      +-----------------+-------+

How to swap buffers between two frames?, Similar, but select buffer in another window ( switch-to-buffer-other-window ). C-x 5 b buffer <RET>: Similar, but select buffer in a separate frame ( switch  If you just want to swap windows (independent on the selected one), you can use the following (defun win-swap () "Swap windows using buffer-move.el" (interactive) (if (null (windmove-find-other-window 'right)) (buf-move-left) (buf-move-right))) – mefiX Nov 29 '10 at 12:00

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?

Select Buffer, They do not change the value of point in any other Emacs window, even one showing the same buffer. The same is true for commands such as C-x b to change  When there are more than two windows, repeated invocations will make the selected buffer appear in each windows successively. (defun swap-buffer () (interactive) (cond ((one-window-p) (display-buffer (other-buffer))) ((let* ((buffer-a (current-buffer)) (window-b (cadr (window-list))) (buffer-b (window-buffer window-b))) (set-window-buffer window-b buffer-a) (switch-to-buffer buffer-b) (other-window 1)))))

If you are using Prelude you can just use C-c s (prelude-swap-windows). From the Prelude documentation:

C-c s runs the command crux-swap-windows (found in prelude-mode-map), which is an alias for crux-transpose-windows in crux.el.

GNU Emacs Manual, In general, “switching to a buffer” means to (1) show the buffer in some window, (​2) make that window the selected window (and its frame the selected frame),  Is there a way to swap if buffer is open in other frame, swap frame buffers instead of having two frames with the same buffer. My use case is this, I usually have emacs split into three vertical frames (left, center, and right) and I prefer editing in the middle buffer while using the right for reference and the left for compilation, testing, etc.

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

Switching Buffers - GNU Emacs Lisp Reference Manual, 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  A window will open that shows a list of current buffers. Press C-x o to switch windows (or click on the new window), move to the buffer called scratch, and press Enter. That window should change to a view of another buffer, which by default is there as a scratchpad.

How to swap the buffers in 2 windows emacs - emacs - iOS, Indeed, you could have two windows open to the same buffer or you could have buffers hidden away in the background. To see all running buffers, use C-x C-b. This is because Emacs tracks buffer positions using that data type. For typical 64-bit machines, this maximum buffer size is 2^61 - 2 bytes, or about 2 EiB. For typical 32-bit machines, the maximum is usually 2^29 - 2 bytes, or about 512 MiB. Buffer sizes are also limited by the amount of memory in the system.

How to switch between two visible Emacs windows while browsing , Switching between files is much more comfortable within a single emacs session. Much better to use the multiple buffer feature of emacs. If you are editing the  After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it.

Editing more than one file at once, Figure 4-2 shows a single frame displaying two Emacs windows, one on top of the The buffer name and the filename, if any, are the same unless you change​  To select a buffer in a window other than the current one (see Windows), type C-x 4 b(switch-to-buffer-other-window). This prompts for a buffer name using the minibuffer, displays that buffer in another window, and

Comments
  • This also works (tested in emacs24): Transposing Two Buffers It seems similar to Bahbar answer
  • This solution is perfect, and the comments are very clear - just make sure you read them :)
  • If you just want to swap windows (independent on the selected one), you can use the following (defun win-swap () "Swap windows using buffer-move.el" (interactive) (if (null (windmove-find-other-window 'right)) (buf-move-left) (buf-move-right)))
  • buffer-move didn't work for me with the layout of just two windows but with win-swap it worked just fine, thanks!
  • Inside that buffer-move source you'll see a comment about the all-important mappings for C-S-up to buf-move-up etc.
  • flop-frame works only when the split between the windows is vertical, for horizontal split you need flip-frame. However, rotate-frame works irrespectively; one command to swap the buffers between two windows, no matter what the split orientation :)
  • prelude looks like a mouthful (and it's not packaged anywhere - curl | sh = wtf?), but crux sure looks nice and does a bunch of stuff i rolled on my own in the first place.
  • i know what curl | sh is, what i am saying is: it's evil.
  • I copied and pasted this code, and it doesn't seem to do anything.
  • Oh, sorry, it does do something, it swaps the top and bottom parts of the Emacs window. I was expecting it to swap the frames.
  • ok. You're confusing me. you mentioned C-x 3. This is to create 2 emacs windows, not 2 emacs frames. Are you using frames or windows ? What do you call windows and what do you call frames?
  • also, you did not talk about top and bottom parts. Do you have more than 2 buffers showing at once ?
  • I'm not the person who asked the question, I'm just an interloper. I had never used C-x 3 before I saw this question, but as you say it splits the Emacs window, rather than creating a new frame.
  • For Spacemacs users, ace-swap-window is bound to SPC w M. This functionality is available by default.