I used C-x 3 to split to left and right windows. The cursor is in left window and I can use C-n, C-p to move the cursor. How can I stay in the left window and move the code in right window up and down?
I have done this before but I lost all my emacs files. So I cannot figure it out right now. Thanks.
I've googled for the answer, Re: How to scroll other window backwards? C-M-v does forwards
Still, use scroll-other-window function and add parameters to it. Below are the details:
(defun scroll-other-window-up-line ()
"Scroll the other window one line up."
(interactive)
(scroll-other-window -1))
(defun scroll-other-window-down-line ()
"Scroll the other window one line down."
(interactive)
(scroll-other-window 1))
(global-set-key (kbd "M-p") 'scroll-other-window-up-line)
(global-set-key (kbd "M-n") 'scroll-other-window-down-line)
Hope it can help.
scroll-other-window is your friend, bound to C-M-v by default.
Related
In Terminal Emacs (no mouse), I'm using split windows to work with multiple buffers at the same time. I'm finding moving between the split windows much more painful than how I do it in Vim. Reading the documentation it looks like I'm doing it correctly (C-x o), but that just cycles around the windows in a clockwise direction. If I move to an adjacent window to make a quick edit, I need to hit C-x o a few times before I'm back where I was. Sometimes I accidentally press it too many times in a hurry and have to cycle all the way back through the windows again.
Far from install yet-another-external-package, is there any way I can just either move directly to a window (by, say, a number), or at least cycle around the windows in the opposite direction?
In Vim C-w C-w is like C-x o in Emacs, but there's also C-w ARROW to move in a specified direction... something like that? :)
Add this to your init file:
(windmove-default-keybindings)
Then you can use SHIFT+arrow to move to the next adjacent window in the specified direction.
You can specify a different modifier if you prefer, by passing an argument (defaults to 'shift).
Or just bind whatever you like to these functions:
windmove-up
windmove-down
windmove-left
windmove-right
You can also add FrameMove to the mix, to make this work transparently across multiple frames.
For numbered window navigation, there's switch-window.el.
Add this to your init file (e.g. ~/.emacs):
(windmove-default-keybindings)
Then do SHIFT+arrow to move to the window in that direction.
You can give a prefix argument to C-x o like this C-u -1 C-x o. This way you can go any number of windows forward or backward. Personally I think it's easier to create a special key for moving back one window. I have this in my .emacs:
(defun other-window-backward ()
"Goto previous window"
(interactive)
(other-window -1))
(global-set-key (kbd "\C-x p") 'other-window-backward)
I use the following to navigate to the next (same as C-x o), previous, first, and last window:
(defun my-previous-window ()
"Previous window"
(interactive)
(other-window -1))
(global-set-key "\C-xp" 'my-previous-window)
(global-set-key "\C-xn" 'other-window)
(defun my-select-first-window ()
(interactive)
(select-window (frame-first-window)))
(defun my-select-last-window ()
(interactive)
(select-window (previous-window (frame-first-window))))
(global-set-key "\C-x<" 'my-select-first-window)
(global-set-key "\C-x>" 'my-select-last-window)
Use window-jump, e.g.:
;; C-x <direction> to switch windows
(use-package window-jump
:bind (("C-x <up>" . window-jump-up)
("C-x <down>" . window-jump-down)
("C-x <left>" . window-jump-left)
("C-x <right>" . window-jump-right)))
For help with use-package, see https://github.com/jwiegley/use-package/blob/master/README.md.
For the sake of completion, there is window-numbering and ace-window too
I wrote an elisp module a while back to expand on windmove to make it a bit more useful: http://samograd.ca/stumpwm.el. You can bind stumpwm-move-window-[left/right/up/down] to whatever keys you want and the windows will move in the correct direction, even into another another frame (tested with 2 frames). There's also an stumpwm-interactive-resize-window for handy interactive window resizing using C-n/C-p/C-f/C-b with Return to end resizing.
In Emacs we can scroll inactive window using certain commands
But not all details are listed in the manual.
C-M-v can scroll down the other window
my intention is to scroll up the other window, how could I do that ?
Try C-M-S-v, which is scroll-other-window-down.
You can find such key bindings by doing C-h b (describe-bindings) which populates the *Help* buffer with a list of all the key bindings and associated commands for the current buffer. A quick search through that for scroll-other showed the binding you mentioned, as well as the one I listed.
On many terminals you can do M-PageUp and M-PageDn to scroll the other window. It's nice if you're already used to using PageUp/PageDn for scrolling.
You can alternatively give a negative argument to C-M-v.
Negative arguments can be given with almost any modifier combination.
In that case you can type C-M-- C-M-v.
I use this (everyday) :
(define-key global-map [(meta up)] '(lambda() (interactive) (scroll-other-window -1)))
(define-key global-map [(meta down)] '(lambda() (interactive) (scroll-other-window 1)))
scroll down,
(scroll-other-window)
scroll up,
(scroll-other-window '-)
scroll-other-window is the native C API of Emacs, so it should work out of the box. Check its documentation.
Feel free to assign hot key for them
You could do C-u - C-M-v (i.e. scroll-other-window with ARG -) if C-M-S-v (i.e. scroll-other-window-down) does not work for you, as could happen when using Emacs in a terminal.
Excerpt from C-h f scroll-other-window:
Negative ARG means scroll downward. If ARG is the atom '-', scroll downward by nearly full screen.
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.
app on Mac OS X on a MacBook. Most applications on the computer allow me to scroll both vertically and horizontally with a two-finger drag on the trackpad. I would like to use this ability to position the cursor in emacs.
Adding the following lines to .emacs allows me to move the cursor vertically:
(global-set-key [wheel-up] 'previous-line)
(global-set-key [wheel-down] 'next-line)
I don't know of an equivalent setting for wheel-left or wheel-right. Can anyone help?
Put this in your .emacs-file:
;; Turn on horizontal scrolling with mouse wheel
(global-set-key (kbd "<mouse-6>") 'scroll-right)
(global-set-key (kbd "<mouse-7>") 'scroll-left)
When you first use it, emacs will ask you if you want to activate the restricted command scroll-left. That's just because some users find it confusing at first.
this slightly simpler version works for me:
(global-set-key [wheel-right] 'scroll-left)
(global-set-key [wheel-left] 'scroll-right)
or for osx reversed scroll directions:
(global-set-key [wheel-right] 'scroll-left)
(global-set-key [wheel-left] 'scroll-right)
(global-set-key (kbd "<mouse-7>")
(lambda () (interactive) (message "WHEEEEEL")))
That worked for me. Try C-h c and then scroll the mouse the way you intend to to see what event is triggered. It will tell you in the echo area.
In version 26.2 I can set these variables from the mouse customize group:
'(mouse-wheel-flip-direction t) ;; correct left-right scroll direction for OS X
'(mouse-wheel-tilt-scroll t) ;; enable left-right scroll from trackpad
In emacs 25.1 check out the *Messages* buffer when you swipe left and right on the trackpad. By the looks of it the key bindings are wheel-right and wheel-left with double and triple variants.
For example:
(global-set-key (kbd "<triple-wheel-right>")
(lambda () (interactive) (message "wheeling right")))
(global-set-key (kbd "<triple-wheel-left>")
(lambda () (interactive) (message "wheeling left")))
For me these values are not reversed in macOS