Switch between horizontal and vertical splitting?
From time to time, by mistake, I split my screen vertically C-x 3
(binded to split-window-right
), whereas I originally wanted a horizontal splitting C-x 2
(binded to split-window-below
).
Question: is there a function to switch between vertical <-> horizontal splitting?
note: for the moment, I hide the buffer C-x 0
and re-split with the right C-x 2
(instead of C-x 3
) and reselect the buffer... which is clearly not optimal.
window-splitting
add a comment |
From time to time, by mistake, I split my screen vertically C-x 3
(binded to split-window-right
), whereas I originally wanted a horizontal splitting C-x 2
(binded to split-window-below
).
Question: is there a function to switch between vertical <-> horizontal splitting?
note: for the moment, I hide the buffer C-x 0
and re-split with the right C-x 2
(instead of C-x 3
) and reselect the buffer... which is clearly not optimal.
window-splitting
add a comment |
From time to time, by mistake, I split my screen vertically C-x 3
(binded to split-window-right
), whereas I originally wanted a horizontal splitting C-x 2
(binded to split-window-below
).
Question: is there a function to switch between vertical <-> horizontal splitting?
note: for the moment, I hide the buffer C-x 0
and re-split with the right C-x 2
(instead of C-x 3
) and reselect the buffer... which is clearly not optimal.
window-splitting
From time to time, by mistake, I split my screen vertically C-x 3
(binded to split-window-right
), whereas I originally wanted a horizontal splitting C-x 2
(binded to split-window-below
).
Question: is there a function to switch between vertical <-> horizontal splitting?
note: for the moment, I hide the buffer C-x 0
and re-split with the right C-x 2
(instead of C-x 3
) and reselect the buffer... which is clearly not optimal.
window-splitting
window-splitting
asked Dec 18 '18 at 14:31
Picaud VincentPicaud Vincent
32517
32517
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
I use the following for this:
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
I picked that up from Magnars Sveen of Emacs Rocks fame.
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
3
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I findace-swap-windows
from the ace-window package is also quite handy.
– Tyler
Dec 18 '18 at 14:49
add a comment |
You can roll your own as @Tyler suggested, but there are some packages that support this. Check out the transpose-frame package on MELPA: https://melpa.org/#/transpose-frame
This handles the simple 2-window case, but can also handle more complex arrangements where you flip or rotate the windows around.
add a comment |
I've not tried the transpose-frame
package so I don't know how it compares, but I use the package https://melpa.org/#/rotate . Combined that with https://melpa.org/#/smartrep using the config:
(use-package smartrep
:config
(setq smartrep-mode-line-active-bg nil))
(use-package rotate
:config
(smartrep-define-key global-map "C-|"
'(("w" . rotate-window)
("l" . rotate-layout))))
And then C-|
w
w
w
w...
etc. rotates through assigning buffers to windows, and C-|
l
l
l
l...
etc. rotates through layouts (such as your use case of flipping between a vertical and horizontal split).
add a comment |
I use C-x 0 (or C-x 1) and then C-x 4 b. The buffer I just closed is offered as the default, so it is still quick to do.
2
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to useC-x 4 b
, but yes, that does not solve the problem.
– Picaud Vincent
Dec 19 '18 at 9:15
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "583"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f46664%2fswitch-between-horizontal-and-vertical-splitting%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I use the following for this:
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
I picked that up from Magnars Sveen of Emacs Rocks fame.
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
3
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I findace-swap-windows
from the ace-window package is also quite handy.
– Tyler
Dec 18 '18 at 14:49
add a comment |
I use the following for this:
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
I picked that up from Magnars Sveen of Emacs Rocks fame.
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
3
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I findace-swap-windows
from the ace-window package is also quite handy.
– Tyler
Dec 18 '18 at 14:49
add a comment |
I use the following for this:
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
I picked that up from Magnars Sveen of Emacs Rocks fame.
I use the following for this:
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
I picked that up from Magnars Sveen of Emacs Rocks fame.
answered Dec 18 '18 at 14:37
TylerTyler
11.9k12251
11.9k12251
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
3
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I findace-swap-windows
from the ace-window package is also quite handy.
– Tyler
Dec 18 '18 at 14:49
add a comment |
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
3
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I findace-swap-windows
from the ace-window package is also quite handy.
– Tyler
Dec 18 '18 at 14:49
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
Thanks! Just tested it, it works. I will wait a little to see if other solutions working with more than 2 windows are suggested.
– Picaud Vincent
Dec 18 '18 at 14:43
3
3
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I find
ace-swap-windows
from the ace-window package is also quite handy.– Tyler
Dec 18 '18 at 14:49
sure thing. I never thought about this until Magnars mentioned it somewhere, and now it's indispensible. For tweaking more complex layouts I find
ace-swap-windows
from the ace-window package is also quite handy.– Tyler
Dec 18 '18 at 14:49
add a comment |
You can roll your own as @Tyler suggested, but there are some packages that support this. Check out the transpose-frame package on MELPA: https://melpa.org/#/transpose-frame
This handles the simple 2-window case, but can also handle more complex arrangements where you flip or rotate the windows around.
add a comment |
You can roll your own as @Tyler suggested, but there are some packages that support this. Check out the transpose-frame package on MELPA: https://melpa.org/#/transpose-frame
This handles the simple 2-window case, but can also handle more complex arrangements where you flip or rotate the windows around.
add a comment |
You can roll your own as @Tyler suggested, but there are some packages that support this. Check out the transpose-frame package on MELPA: https://melpa.org/#/transpose-frame
This handles the simple 2-window case, but can also handle more complex arrangements where you flip or rotate the windows around.
You can roll your own as @Tyler suggested, but there are some packages that support this. Check out the transpose-frame package on MELPA: https://melpa.org/#/transpose-frame
This handles the simple 2-window case, but can also handle more complex arrangements where you flip or rotate the windows around.
answered Dec 18 '18 at 15:13
glucasglucas
14.8k12757
14.8k12757
add a comment |
add a comment |
I've not tried the transpose-frame
package so I don't know how it compares, but I use the package https://melpa.org/#/rotate . Combined that with https://melpa.org/#/smartrep using the config:
(use-package smartrep
:config
(setq smartrep-mode-line-active-bg nil))
(use-package rotate
:config
(smartrep-define-key global-map "C-|"
'(("w" . rotate-window)
("l" . rotate-layout))))
And then C-|
w
w
w
w...
etc. rotates through assigning buffers to windows, and C-|
l
l
l
l...
etc. rotates through layouts (such as your use case of flipping between a vertical and horizontal split).
add a comment |
I've not tried the transpose-frame
package so I don't know how it compares, but I use the package https://melpa.org/#/rotate . Combined that with https://melpa.org/#/smartrep using the config:
(use-package smartrep
:config
(setq smartrep-mode-line-active-bg nil))
(use-package rotate
:config
(smartrep-define-key global-map "C-|"
'(("w" . rotate-window)
("l" . rotate-layout))))
And then C-|
w
w
w
w...
etc. rotates through assigning buffers to windows, and C-|
l
l
l
l...
etc. rotates through layouts (such as your use case of flipping between a vertical and horizontal split).
add a comment |
I've not tried the transpose-frame
package so I don't know how it compares, but I use the package https://melpa.org/#/rotate . Combined that with https://melpa.org/#/smartrep using the config:
(use-package smartrep
:config
(setq smartrep-mode-line-active-bg nil))
(use-package rotate
:config
(smartrep-define-key global-map "C-|"
'(("w" . rotate-window)
("l" . rotate-layout))))
And then C-|
w
w
w
w...
etc. rotates through assigning buffers to windows, and C-|
l
l
l
l...
etc. rotates through layouts (such as your use case of flipping between a vertical and horizontal split).
I've not tried the transpose-frame
package so I don't know how it compares, but I use the package https://melpa.org/#/rotate . Combined that with https://melpa.org/#/smartrep using the config:
(use-package smartrep
:config
(setq smartrep-mode-line-active-bg nil))
(use-package rotate
:config
(smartrep-define-key global-map "C-|"
'(("w" . rotate-window)
("l" . rotate-layout))))
And then C-|
w
w
w
w...
etc. rotates through assigning buffers to windows, and C-|
l
l
l
l...
etc. rotates through layouts (such as your use case of flipping between a vertical and horizontal split).
answered Dec 18 '18 at 23:13
Marty NealMarty Neal
1796
1796
add a comment |
add a comment |
I use C-x 0 (or C-x 1) and then C-x 4 b. The buffer I just closed is offered as the default, so it is still quick to do.
2
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to useC-x 4 b
, but yes, that does not solve the problem.
– Picaud Vincent
Dec 19 '18 at 9:15
add a comment |
I use C-x 0 (or C-x 1) and then C-x 4 b. The buffer I just closed is offered as the default, so it is still quick to do.
2
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to useC-x 4 b
, but yes, that does not solve the problem.
– Picaud Vincent
Dec 19 '18 at 9:15
add a comment |
I use C-x 0 (or C-x 1) and then C-x 4 b. The buffer I just closed is offered as the default, so it is still quick to do.
I use C-x 0 (or C-x 1) and then C-x 4 b. The buffer I just closed is offered as the default, so it is still quick to do.
answered Dec 19 '18 at 3:10
DanDan
111
111
2
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to useC-x 4 b
, but yes, that does not solve the problem.
– Picaud Vincent
Dec 19 '18 at 9:15
add a comment |
2
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to useC-x 4 b
, but yes, that does not solve the problem.
– Picaud Vincent
Dec 19 '18 at 9:15
2
2
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
That doesn't "switch between horizontal and vertical splitting"; it just gives you the default split.
– phils
Dec 19 '18 at 4:04
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to use
C-x 4 b
, but yes, that does not solve the problem.– Picaud Vincent
Dec 19 '18 at 9:15
@phil I think @Dan was referring to the "note" section of question where I say I was reselecting the buffer. The trick is to use
C-x 4 b
, but yes, that does not solve the problem.– Picaud Vincent
Dec 19 '18 at 9:15
add a comment |
Thanks for contributing an answer to Emacs Stack Exchange!
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f46664%2fswitch-between-horizontal-and-vertical-splitting%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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