Currently, I am using GUD in the newest version of Emacs. The keybinding has changed since the old Emacs. Now it is "\C-x \C-a \C-b" for setting a breakpoint but it was \C-[space].
I was wondering if there is anyway to change the keybinding to the old format? (For some reason I cannot change my Emacs version)
I am using Emacs 24.5
Here is my .emacs file:
;; .emacs
;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)
;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))
;; enable visual feedback on selections
;(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs#" (system-name)))
;; default to unified diffs
(setq diff-switches "-u")
;; always end a file with a newline
;(setq require-final-newline 'query)
;; Show main source buffer when using gdb
(setq gdb-show-main t)
;; Show all debugging frames in GDB
(setq gdb-many-windows t)
;; see buffer list on the same frame
(global-set-key "\C-x\C-b" 'buffer-menu)
;; old keybinding for breakoint in GUD
(require 'gud)
(define-key gud-mode-map "\C-x SPC" 'gud-break)
Changing your Emacs version should not be necessary. Try this:
(require 'gud)
(define-key gud-mode-map (kbd "C-SPC") 'gud-break)
This will allow you to trigger gud-break with C-SPC. If you are not talking about the gud-break command, replace it with the command you are referring too.
Generally, the answer to the question "can I change this keybinding?" is always "yes" in Emacs.
Somehow I was able to fix it with this:
(require 'gud)
(global-set-key [24 32] (quote gud-break))
I'm working with directories full of images, which are photographs of documents in an archive. I'm writing org files with notes on the content of these, and I would like to make it quicker and easier to browse the images (e.g. with image-dired) and copy links into the org-mode file alongside my notes.
My working setup looks like this:
My questions are:
How can I automatically copy a link for the currently displayed image into org?
Is there any easy way to control the image-dired picture (browsing backwards and forwards, rotating) from within the org windows?
Are there any other modes or tools that I should be looking at?
Here is a little code to make working with images easier. Just copy it into your *scratch* buffer and run M-x eval-buffer.
(defun my-next-image ()
(interactive)
(save-excursion
(with-current-buffer "*image-dired*"
(image-dired-forward-image)
(image-dired-display-thumbnail-original-image))))
(defun my-prev-image ()
(interactive)
(save-excursion
(with-current-buffer "*image-dired*"
(image-dired-backward-image)
(image-dired-display-thumbnail-original-image))))
(defun my-insert-current-image-path ()
(interactive)
(insert
(concat
"[["
(save-excursion
(with-current-buffer "*image-dired*"
(image-dired-original-file-name)))
"]]")))
(define-key org-mode-map (kbd "<f9> n") 'my-next-image)
(define-key org-mode-map (kbd "<f9> p") 'my-prev-image)
(define-key org-mode-map (kbd "<f9> i") 'my-insert-current-image-path)
Press F9 n to switch to the next image while in org mode, press F9 i to insert a link to the current image. Rebind keys to your liking.
I want to customize Emacs so that pressing
ESC : n RET
takes me to line number n
and
ESC : $ RET
takes me to the last line. (That's how the vi editor works.)
How can I achieve this inside my Emacs configuration file? Currently I have this in my .emacs:
(global-set-key (kbd "M-9") 'prev-window)
(global-set-key (kbd "M-0") 'other-window)
I don't want to use any of the off-the-shelf solutions (eg. evil) because they are bloated and mess with my existing shortcuts.
Put this in a file and load it (load means execute):
(defun vi-goto-line (arg)
(interactive "sLine:")
(message arg)
(if (string= "$" arg)
(end-of-buffer)
(goto-line (string-to-int arg))
)
)
(global-set-key (kbd "M-:") 'vi-goto-line)
To load it you can use M-xload-file and then enter interactively the path to the file.
Keep in mind that the key combo M-: (which is the same as ESC:) already has a meaning in Emacs, so this now gets cloaked.
Of course you also can load the file from your .emacs by putting (load-file "/path/to/my/file") into the .emacs or put these lines directly into your .emacs file (or any other configuration file which gets loaded)
In emacs, is there an M-x command or key combo to render all current open buffers into different windows?
For clarity, let's suppose I have four open buffers, and I am only seeing one currently being displayed, and I would like in one step to show each buffer in one quadrant.
I recommend ibuffer. M-x ibuffer is probably what you want. Here's my ibuffer configuration:
;; *Messages* is so annoying. Also, I really like ibuffer
(require 'ibuf-ext)
(add-to-list 'ibuffer-never-show-predicates "^\\*Messages")
(add-to-list 'ibuffer-never-show-predicates "^\\*Completions")
(global-set-key (kbd "C-b") 'ibuffer)
(kill-buffer "*scratch*")
('ibuffer)
(switch-to-buffer "*Ibuffer*")
You will be able to start with the following code if there is not an already-known way to do it:
(defun buffer-in-window-list ()
(let (buffers)
(walk-windows (lambda (window) (push (window-buffer window) buffers)) t t)
buffers))
(defun display-all-buffers ()
(interactive)
(let (buffers-in-window (buffer-in-window-list))
(dolist (buffer (buffer-list))
(when (and (not (string-match "\\`[[:space:]]*\\*" (buffer-name buffer)))
(not (memq buffer buffers-in-window)))
(set-window-buffer (split-window (get-largest-window)) buffer)))
(balance-windows)))
The display-all-buffers command opens a new window for each buffer that is not currently displayed anywhere (including other frames). For usability, it ignores buffers whose names start with * (optionally, prefixed with whitespace characters) because they are usually for internal use only.
Note that Emacs does not allow a user to make too small a window. So, when there are too many buffers to display, the command will display as many buffers as possible in order of most recent display or selection and signal an error.
In Emacs, C-x o takes me to the next window.
What keyboard macro takes me to the previous window in Emacs?
You might also want to try using windmove which lets you navigate to the window of your choice based on geometry. I have the following in my .emacs file to change windows using C-x arrow-key.
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
That'd be C-- C-x o
In other words, C-x o with an argument of -1. You can specify how many windows to move by inserting a numeric argument between C-u and the command, as in C-u 2 C-x o. (C-- is a shortcut for C-u - 1)
Personally I prefer to use window-number.el
To select a different window, use Ctrl-x, Ctrl-j n
Where n is the number of the window, the modeline of each window shows it's number, as shown in the screenshot.
Just download window-number.el, place it in your emacs load-path and use the following in your .emacs
(autoload 'window-number-mode "window-number"
"A global minor mode that enables selection of windows according to
numbers with the C-x C-j prefix. Another mode,
`window-number-meta-mode' enables the use of the M- prefix."
t)
There's another similar mode called switch-window.el which gives you big numbers in the windows... (pressing the number switches the window and reverts the display.)
(source: tapoueh.org)
If you work with multiple emacs windows (>3) a lot and you will want to save some keystrokes add this to your init file and you'll be better off:
(defun frame-bck()
(interactive)
(other-window-or-frame -1)
)
(define-key (current-global-map) (kbd "M-o") 'other-window-or-frame)
(define-key (current-global-map) (kbd "M-O") 'frame-bck)
Now just cycle quickly thru the windows with M-o
There are some very good and complete answers here, but to answer the question in a minimalist fashion:
(defun prev-window ()
(interactive)
(other-window -1))
(define-key global-map (kbd "C-x p") 'prev-window)
Base on idea from #Nate but slightly modified to support backwards cycling between windows
;; Windows Cycling
(defun windmove-up-cycle()
(interactive)
(condition-case nil (windmove-up)
(error (condition-case nil (windmove-down)
(error (condition-case nil (windmove-right) (error (condition-case nil (windmove-left) (error (windmove-up))))))))))
(defun windmove-down-cycle()
(interactive)
(condition-case nil (windmove-down)
(error (condition-case nil (windmove-up)
(error (condition-case nil (windmove-left) (error (condition-case nil (windmove-right) (error (windmove-down))))))))))
(defun windmove-right-cycle()
(interactive)
(condition-case nil (windmove-right)
(error (condition-case nil (windmove-left)
(error (condition-case nil (windmove-up) (error (condition-case nil (windmove-down) (error (windmove-right))))))))))
(defun windmove-left-cycle()
(interactive)
(condition-case nil (windmove-left)
(error (condition-case nil (windmove-right)
(error (condition-case nil (windmove-down) (error (condition-case nil (windmove-up) (error (windmove-left))))))))))
(global-set-key (kbd "C-x <up>") 'windmove-up-cycle)
(global-set-key (kbd "C-x <down>") 'windmove-down-cycle)
(global-set-key (kbd "C-x <right>") 'windmove-right-cycle)
(global-set-key (kbd "C-x <left>") 'windmove-left-cycle)
Just to add to #Nate, #aspirin and #Troydm's answer I find this to be a very helpful addition if you decide to bind the windmove commands to whatever key combination you choose:
(setq windmove-wrap-around t)
With the default configuration you will get an error when you get to attempt to move to a window that doesn't exist which becomes kind of annoying after a while. However when windmove-wrap-around is set then attempting to move off the bottom of the frame for example will instead select the topmost window in the frame. This may be a more intuitive behaviour for you.
M-n and M-p makes the most sense to me, since they are analogous to C-n (next-line) and C-p (previous-line):
(define-key global-map (kbd "M-p") 'previous-multiframe-window)
(define-key global-map (kbd "M-n") 'other-window)
(inspired by to this and that)
In reference to Nate's answer, I replaced the arrow keys to use the traditional p for going up, n for going down, f for going right and b for going left. I also replaced the Ctrl with Super key as C-p, C-n, C-f and C-b are the default movement keys. This combination with M lets you jump characters and lines instead of going through just one by one after each keystroke. Thus Super key felt the best choice to keep it an easy key binding. Also, now you don't have to take your hand off the home row any more!
(global-set-key (kbd "s-p") `windmove-up)
(global-set-key (kbd "s-n") `windmove-down)
(global-set-key (kbd "s-f") `windmove-right)
(global-set-key (kbd "s-b") `windmove-left)
Hope it helps!
(global-unset-key (kbd "M-j"))
(global-unset-key (kbd "M-k"))
(global-set-key (kbd "M-j") (lambda () (interactive) (other-window 1)))
(global-set-key (kbd "M-k") (lambda () (interactive) (other-window -1)))
altj and altk will cycle through your visibles buffers. Forwards and backwards, to be exact.
There is already a package that lets you switch windows by using M-. check this website. Add this to your init file:
(require 'windmove)
(windmove-default-keybindings 'meta) ;; or use 'super to use windows key instead alt
(global-set-key (kbd "C-x a") 'ace-swap-window)
(global-set-key (kbd "C-x q") 'ace-select-window)
download ace-window from the melpa repo if you don't know how to do that
put this in your .emacs file if you don't have one create it
(package-initialize)
(require 'package)
(add-to-list 'package-archives '("melpa" , "http://melpa.org/packages/"))
(package-initialize)
then "m-x list-packages"
The fastest method I have found for switching to the previous window is to mash a couple keys together as a "key-chord". The following lets you use your left pinky+ring fingers together to go to previous window:
(key-chord-define-global "qw" 'prev-window)
(key-chord-define-global "'y" 'other-window) ; bonus for my colemak, adjust otherwise
(key-chord-define-global ";'" 'other-window) ; probably normal
(This is possible because Emacs key chords are order independent, meaning that qw is the same as wq.)