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.
Related
can anyone point me in the right direction to globally define the activation of shift select with the left mouse button?
I want to be able to select between the cursor point and the selected area...
It is possible to drag-select only, and it is possible to shift-select via keyboard only.
This unfortunately doesn't work (in ~/.emacs):
(define-key global-map (kbd "<S-down-mouse-1>") 'shift-selection)
Machine: Win7, Emacs-Version: 25.1.1 (i686-w64-mingw32) of 2016-09-17
Thanks.
(define-key global-map (kbd "<S-down-mouse-1>") 'mouse-save-then-kill)
https://superuser.com/questions/521223/shift-click-to-extend-marked-region
I am trying to override Meta + left / right arrow keys in my emacs config and cannot figure out how to refer to the key sequence.
If I interact with Emacs directly I can type
"M-x, global-set-key, M-, next-buffer", and it works fine. But I can't figure out how to type this into my init.el file. These are some things that I have tried:
(global-set-key "\M right" 'next-buffer)
(global-set-key "\M <right>" 'next-buffer)
(global-set-key [\M right] 'next-buffer)
(global-set-key [M right] 'next-buffer)
(global-set-key [M-right] 'next-buffer)
(global-set-key (kbd M-<right>) 'next-buffer)
(global-set-key [M (kbd <right>)] 'next-buffer)
etc.
More Info:
OK, this does work natively: (global-set-key [M-right] 'next-buffer) (thank you) - it's not working on iTerm2 in a VM (minor detail :)
And for that environment: M-x describe-key does not open help but in *Messages* prints: ESC <right> (translated from ESC M-[ C) is undefined
And that's why I was confused and was not able to just paste that into kbd.
And that's why I don't think it is being trumped by another mode.
The easiest way to specify a key binding is always to use kbd.
(global-set-key (kbd "<M-right>") 'next-buffer)
kbd takes as argument an external key description, i.e., what Emacs tells you when you use C-h k.
Use C-h k, press and hold the Meta (e.g. Alt) key, and hit the right arrow key. Buffer *Help* tells you that this key sequence is written "<M-right>". So that's what you pass to kbd.
Solved: (global-set-key (kbd "ESC <right>") 'next-buffer)
Thanks - I needed the combination of kbd and what to pass it.
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)
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
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.