I have multiple windows open in emacs via C-X 2. However, sometimes I want to move a window at the top, down one, so that the window below it moves up, and that window I want to move goes down one place. I'm not talking about moving within windows, but moving the actual window. Is this possible in emacs?
Try this:
(require 'buffer-move)
(global-set-key (kbd "<C-S-up>") 'buf-move-up)
(global-set-key (kbd "<C-S-down>") 'buf-move-down)
(global-set-key (kbd "<C-S-left>") 'buf-move-left)
(global-set-key (kbd "<C-S-right>") 'buf-move-right)
Related
There are 2 windows open in the horizontally split Emacs frame. Now, using keyboard shortcut, i would like the input focus to shift to other window.
i think, select-window function does it programatically.
I think windmove would help you. There are function like windmove-left, windmove-right, etc., and you can bind the key strokes you like to use the functions. For example, I set them up like the following:
(global-set-key (kbd "M-s-<left>") 'windmove-left)
(global-set-key (kbd "M-s-<right>") 'windmove-right)
(global-set-key (kbd "M-s-<up>") 'windmove-up)
(global-set-key (kbd "M-s-<down>") 'windmove-down)
With these settings, you can move the cursor between windows with arrow keys. You can change key stroke as you like.
http://emacswiki.org/emacs/WindMove
If you're in one frame containing two windows, you can use C-x o, which is bound to other-window, to go between them.
This question already has answers here:
Emacs move around split windows in a specified direction?
(7 answers)
Closed 9 years ago.
I want to speed up when switching between different windows - sometimes C-x-o is just too slow when I have multiple windows. Say, I have 4 windows now, and I want to switch to the upper one by C-x-up arrow, to the left by C-x-left arrow, to the bottom by C-x-down arrow, to the right by C-x-right arrow. How should I code in .emacs?
Thanks very much!
The windmove package is designed for this.
By default, you can switch windows using Shift with the arrow keys. As outlined in the linked post, simply
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))
Of course, this is fully configurable. For instance, I bind it to the arrow keys without any modifier (I already use C-p, C-n, etc. for movement) like this:
(when (locate-library "windmove")
(global-set-key (kbd "<left>") 'windmove-left)
(global-set-key (kbd "<right>") 'windmove-right)
(global-set-key (kbd "<up>") 'windmove-up)
(global-set-key (kbd "<down>") 'windmove-down))
windmove is shipped with Emacs.
This is my final answer and it works elegantly! This is the first time I defined shortcuts myself in Emacs. Terrific! Thanks very much #Chris!
(when (locate-library "windmove")
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
)
PS my windmove package is autoloaded.
I'm using gdb-many-windows, which contains five windows to switch between. Is there a shortcut I can use to get to a specific window?
You probably already know that C-x o gets you to the next window. You can extend this to go to any arbitrary window with C-u <windowoffset> C-x o.
So, you can use C-u 2 C-x o to switch to the second window ahead of your current one.
This wraps around the window list (so in your case of 5 windows you could do C-u 4 c-x o to go back one.
You can also use negative numbers as well to go backwards.
Lastly, it takes a bit more setup, but Thomas's suggestion to use WindMove is very useful. It wasn't configured by default for me to any useful key binding. I add the following snippet to my (mac) .emacs file, whch lets me switch windows via control-arrow (you will need to reload .emacs by starting up or via 'M-x load-file')
(global-set-key (kbd "M-[ 5 d") 'windmove-left)
(global-set-key (kbd "M-[ 5 c") 'windmove-right)
(global-set-key (kbd "M-[ 5 a") 'windmove-up)
(global-set-key (kbd "M-[ 5 b") 'windmove-down)
Some people find WindMove more convenient than C-x o. It allows you to navigate between windows using Shift + arrow keys.
Possibly useful links:
http://www.emacswiki.org/emacs/WindowNumberingMode
http://www.emacswiki.org/emacs/NumberedWindows
Edit: If you decide to use WindowNumberingMode (that's what I use) you might find it useful to pin buffers to windows (so, for instance, Meta-1 switches to the buffer you expect it to switch to, not just the first window). One way of pinning is described in Pin Emacs buffers to windows (for cscope).
Window switching is so important in emacs, I have these settings.(Still feel these are not good enough)..
may help someone else..
(global-set-key "\M-t" 'other-window) ;; was transpose words
(global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ;; back one
(global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window 2))) ;; forward t
I use switch-window.el.
You can choose a window by visual way with 'switch-window'.
Image of using switch-window
I'm trying to define the following two keyboard shortcuts to move between windows in Emacs:
C-shift-n: Move to the next window
C-shift-b: Move to the previous window
I thought the following will do it but it doesn't.
(defun select-next-window ()
"Switch to the next window"
(interactive)
(select-window (next-window)))
(defun select-previous-window ()
"Switch to the previous window"
(interactive)
(select-window (previous-window)))
(global-set-key (kbd "C-<S-n>") 'select-next-window)
(global-set-key (kbd "C-<S-p>") 'select-previous-window)
The problem seems to be with the last two lines that define the actual keyboard shortcuts to the functions that switch the windows (if I use simpler keyboard shortcuts instead of Control-Shift-* it works).
So, how do I use kbd to define Control-Shift-n and Control-Shift-p?
Assuming you never use caps lock, here's a super simple solution:
(global-set-key (kbd "C-N") 'select-next-window)
or
(global-set-key (kbd "C-<S-N>") 'select-next-window)
The problem is that when you hit shift you're sending capital N.
Is there a way to zoom in and out (dynamically change the font size, quite smoothly) on emacs?
Try C-x C-+ and C-x C--; that is, Control-x Control-Minus/Control-Plus.
After one combination (C-x C-+ or C-x C--), successives + or - increase or decrease the text scale without typing C-x C- again.
Addition by sawa
I looked up the function that was assigned to the keys mentioned, and found out that they are text-scale-increase and text-scale-decrease. I added the following to my configuration file so that I can do Ctrl+Scroll to zoom in/out. It is useful.
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
The -very nice- answer of user173973 is binding the functions to non-generic mouse events. That is to say that for example on my windows system, the binding command is not valid.
To use it on windows (or probably anywhere) you can use these generic bindings :
(global-set-key [C-mouse-wheel-up-event] 'text-scale-increase)
(global-set-key [C-mouse-wheel-down-event] 'text-scale-decrease)
This config worked for me:
(global-set-key [C-wheel-up] 'text-scale-increase)
(global-set-key [C-wheel-down] 'text-scale-decrease)
In addition to sawa's accepted response, I prefer to use the keyboard exclusively. Here are some additions to my init.el file that meet that preference similarly to the short cuts found on Windows/MacOS desktops:
;; enable shortcuts (both keyboard and mouse) for zoom-in/zoom-out
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
(global-set-key [?\C-\+] 'text-scale-increase)
(global-set-key [?\C-\-] 'text-scale-decrease)
All windows
You'll often want to change your font size because you're showing something to others. Then you likely want all windows to zoom in (including mode-line). For this, default-text-scale is great.
I bind it as such:
(key-seq-define-global "q-" 'default-text-scale-decrease)
(key-seq-define-global "q+" 'default-text-scale-increase)
(global-set-key (kbd "C-M-_") 'default-text-scale-decrease)
(global-set-key (kbd "C-M-+") 'default-text-scale-increase)
Quick single window, and back
For a really quick heavy (16x) zoom-in, you can use: C-u C-u C-x C-+
For going to single-window mode, say for a org presentation: C-x 1
Then you can undo the single-window and return to whatever layout you had before with winner-undo: C-c <left>
Whole desktop
Relatedly, for sharing over a video call, it might be easiest to just change (lower) your desktop resolution. On linux, I pop up arandr for this before starting a sharing session.