2010-06-26 19 views
25

mina son:¿Cuáles son tus encuadernaciones de teclas globales favoritas en emacs?

(global-set-key [f6] 'compile-buffer) 
(global-set-key [f7] 'kmacro-start-macro-or-insert-counter) 
(global-set-key [f8] 'kmacro-end-and-call-macro) 
(global-set-key [f9] 'call-last-kbd-macro) 
(global-set-key [f10] 'name-and-insert-last-kbd-macro) 
(global-set-key [f12] 'menu-bar-open) ; originally bound to F10 
(global-set-key "\C-cR" 'rename-current-file-or-buffer) 
(global-set-key "\C-cD" 'Delete-current-file-or-buffer) 

El name-and-insert-last-keyboard-macro es de another Stack Overflow question.

Respuesta

25

Resulta que tengo un buen montón de ellos:

;; You know, like Readline. 
(global-set-key (kbd "C-M-h") 'backward-kill-word) 

;; Align your code in a pretty way. 
(global-set-key (kbd "C-x \\") 'align-regexp) 

;; Perform general cleanup. 
(global-set-key (kbd "C-c n") 'cleanup-buffer) 

;; Font size 
(define-key global-map (kbd "C-+") 'text-scale-increase) 
(define-key global-map (kbd "C--") 'text-scale-decrease) 

;; Use regex searches by default. 
(global-set-key (kbd "C-s") 'isearch-forward-regexp) 
(global-set-key (kbd "\C-r") 'isearch-backward-regexp) 
(global-set-key (kbd "C-M-s") 'isearch-forward) 
(global-set-key (kbd "C-M-r") 'isearch-backward) 

;; Jump to a definition in the current file. (This is awesome.) 
(global-set-key (kbd "C-x C-i") 'ido-imenu) 

;; File finding 
(global-set-key (kbd "C-x M-f") 'ido-find-file-other-window) 
(global-set-key (kbd "C-x C-M-f") 'find-file-in-project) 
(global-set-key (kbd "C-x f") 'recentf-ido-find-file) 
(global-set-key (kbd "C-c r") 'bury-buffer) 
(global-set-key (kbd "M-`") 'file-cache-minibuffer-complete) 

;; Window switching. (C-x o goes to the next window) 
(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 two 

;; Indentation help 
(global-set-key (kbd "C-x ^") 'join-line) 
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer) 

;; Start proced in a similar manner to dired 
(global-set-key (kbd "C-x p") 'proced) 

;; Start eshell or switch to it if it's active. 
(global-set-key (kbd "C-x m") 'eshell) 

;; Start a new eshell even if one is active. 
(global-set-key (kbd "C-x M") (lambda() (interactive) (eshell t))) 

;; Start a regular shell if you prefer that. 
(global-set-key (kbd "C-x M-m") 'shell) 

;; If you want to be able to M-x without meta 
(global-set-key (kbd "C-x C-m") 'execute-extended-command) 

;; Fetch the contents at a URL, display it raw. 
(global-set-key (kbd "C-x C-h") 'view-url) 

;; Help should search more than just commands 
(global-set-key (kbd "C-h a") 'apropos) 

;; Should be able to eval-and-replace anywhere. 
(global-set-key (kbd "C-c e") 'eval-and-replace) 

;; Magit rules! 
(global-set-key (kbd "C-x g") 'magit-status) 

;; This is a little hacky since VC doesn't support git add internally 
(eval-after-load 'vc 
    (define-key vc-prefix-map "i" '(lambda() (interactive) 
            (if (not (eq 'Git (vc-backend buffer-file-name))) 
             (vc-register) 
            (shell-command (format "git add %s" buffer-file-name)) 
            (message "Staged changes."))))) 

;; Activate occur easily inside isearch 
(define-key isearch-mode-map (kbd "C-o") 
    (lambda() (interactive) 
    (let ((case-fold-search isearch-case-fold-search)) 
     (occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))) 

;; Org 
(define-key global-map "\C-cl" 'org-store-link) 
(define-key global-map "\C-ca" 'org-agenda) 

;; program shortcuts - s stands for windows key(super) 
(global-set-key (kbd "s-b") 'browse-url)   ;; Browse (W3M) 
(global-set-key (kbd "s-f") 'browse-url-firefox) ;; Firefox... 
(global-set-key (kbd "s-l") 'linum-mode)   ;; show line numbers in buffer 
(global-set-key (kbd "s-r") 're-builder)   ;; build regular expressions 

;; Super + uppercase letter signifies a buffer/file 
(global-set-key (kbd "s-S")      ;; scratch 
       (lambda()(interactive)(switch-to-buffer "*scratch*"))) 
(global-set-key (kbd "s-E")      ;; .emacs 
       (lambda()(interactive)(find-file "~/emacs/dot-emacs.el"))) 

;; cycle through buffers 
(global-set-key (kbd "<C-tab>") 'bury-buffer) 

;; use hippie-expand instead of dabbrev 
(global-set-key (kbd "M-/") 'hippie-expand) 

;; spell check Bulgarian text 
(global-set-key (kbd "C-c B") 
       (lambda()(interactive) 
        (ispell-change-dictionary "bulgarian") 
        (flyspell-buffer))) 

;; replace buffer-menu with ibuffer 
(global-set-key (kbd "C-x C-b") 'ibuffer) 

;; interactive text replacement 
(global-set-key (kbd "C-c C-r") 'iedit-mode) 

;; swap windows 
(global-set-key (kbd "C-c s") 'swap-windows) 

;; duplicate the current line or region 
(global-set-key (kbd "C-c d") 'duplicate-current-line-or-region) 

;; rename buffer & visited file 
(global-set-key (kbd "C-c r") 'rename-file-and-buffer) 

;; open an ansi-term buffer 
(global-set-key (kbd "C-x t") 'visit-term-buffer) 

;; macros 
(global-set-key [f10] 'start-kbd-macro) 
(global-set-key [f11] 'end-kbd-macro) 
(global-set-key [f12] 'call-last-kbd-macro) 

(provide 'bindings-config) 

que en realidad tienen todo un archivo Emacs Lisp dedicada a combinaciones de teclas globales :-)

+0

que es un poco más! – Vivi

+2

Deberías ver mi otra configuración ;-) –

+0

Mnogo blagodaria! – Hut8

5

de crédito para este va a Steve Yegge en http://sites.google.com/site/steveyegge2/effective-emacs

(global-set-key "\C-w" 'backward-kill-word) 
(global-set-key "\C-x\C-k" 'kill-region) 
(global-set-key "\C-c\C-k" 'kill-region) 

Realmente es maravilloso tener Ctrl-w media de lo que estoy acostumbrado a tener que decir.

(También puedes ver ese artículo para más)

7

Algunos de mis fijaciones más inusuales:

(global-set-key [pause] 'emms-pause) 

Primera buen uso para el pausa ¡clave en mucho tiempo!

(global-set-key [(super \\)] 'find-file-at-point) 

Simplemente todo útil.

(global-set-key [(super s)] 'shell) 
(global-set-key [(meta p)] 'shell) 

con la unión en su lugar segundo, puedo escribir rápidamente M-p M-p RET para volver a la memoria intermedia de cáscara y repetir el último comando mecanografié allí.

Luego están los unbindings:

(global-unset-key "\C-x\C-n") 

realmente nunca tuvo un uso de set-goal-column, y siempre mantuvo tropezar con él.

(when window-system (global-unset-key "\C-z")) 

lo odio cuando accidentalmente escribo C-z y Iconify mi marco.

Ahora tenemos una pequeña meta:

(defmacro global-set-key* (keys &rest body) 
    `(global-set-key ,keys (lambda() (interactive) ,@body))) 

Sólo un pequeño dispositivo de ahorro de pulsaciones de teclas que me permite escribir cosas como:

(global-set-key* [(shift control n)] (next-line) (scroll-up 1)) 
(global-set-key* [(shift control p)] (previous-line) (scroll-down 1)) 
4

Uno de mis favoritos fue algo recomendado por un compañero de trabajo que Inicialmente pensé que odiaría:

Las teclas de flecha (arriba/abajo/izquierda/derecha) se reasignan para desplazarse por la ventana actual. Para mover el cursor, aún tiene C-n/p/f/b (o isearch, o tags, o lo que sea).

2

(global-set-key [(control w)] 'kill-this-buffer)

ya estaba pulsando Ctrl-W por instinto para cerrar un buffer - personalización de los emacs vinculantes hecho más fácil para mí.

Sí, me doy cuenta de que esto delata mi origen como un tipo de Windows. Todos cometemos errores ...

+7

El problema inverso es bastante peor: cierro las aplicaciones de Windows de forma bastante regular, cuando solo quería cortar/eliminar texto. – phils

3
(bind "C-t" (lookup-key global-map (kbd "C-x"))) 

Nunca transpongo caracteres, por lo que lo retuerzo para que signifique C-x cuando se utiliza como una tecla de prefijo. No puedo soportar llegar a la tecla "x" en Dvorak.

También estoy usando esta macro desde hoy:

(defmacro bind (key fn) 
    `(global-set-key (kbd ,key) ,(if (listp fn) fn `',fn))) 
+1

Es curioso, creo que C-x es más fácil en Dvorak. :-) – Ken

+0

+1 para el ejemplo que muestra cómo crear una clave de prefijo adicional. – Matt

1

(-configuración de teclas global (KBD "Cc k") 'browse-kill-ring)
(-set-key mundial (KBD "M- . ") 'etags-select-find-tag)
(-set-teclas global (KBD "Ms l")' loccur)
(-set-teclas global (KBD "Ms /") 'multi-ocurrir-en-coincidentes-buffers)
(global-set-key (kbd "Cx Mb") 'bury-buffer)
(global-set-key (kbd) "C-x C-b") 'ibuffer)
(global-set-key (kbd "M- /")' hippie-expand)

;; Alternar show-trailing-whitespace.
(global-set-key (kbd "C-c M-w") (function (lambda() (interactive) (setq show-trailing-whitespace (not show-trailing-whitespace)))))

;; Use framemove, integrado con windmove.
(windmove-default-keybindings) ;default modifier is <SHIFT>
(when (require 'framemove nil :noerror) (setq framemove-hook-into-windmove t))

1
;; Generally useful 
(global-set-key [(meta ?/)] 'hippie-expand) 
(global-set-key [(super ?i)] 'imenu) 

;; Emacs Lisp navigation 
(global-set-key (kbd "C-c f") 'find-function) 
(global-set-key [(super ?l)] 'find-library) 

;; Compiling things, navigating to errors 
(global-set-key [print] 'recompile) 
(global-set-key [(shift print)] 'compile) 
(global-set-key (kbd "M-p") 'previous-error) 
(global-set-key (kbd "M-n") 'next-error) 
(global-set-key (kbd "s-p") 'flymake-goto-prev-error) 
(global-set-key (kbd "s-n") 'flymake-goto-next-error) 

;; Open URLs in Firefox. Still not sure which binding I like most... 
(global-set-key (kbd "s-<kp-5>") 'browse-url-firefox) 
(global-set-key (kbd "s-<kp-begin>") 'browse-url-firefox) 
(global-set-key (kbd "s-t") 'browse-url-firefox) 

;; EMMS (music player) 
(global-set-key [Scroll_Lock] 'emms-pause) 
(global-set-key (kbd "<S-Scroll_Lock>") 'emms-next) 
(global-set-key (kbd "<C-Scroll_Lock>") 'emms-show) 

;; Navigation between and within buffers 
(global-set-key (kbd "C-<backspace>") 'bury-buffer) 

(defun scroll-down-one-line() 
    "Scroll down one line." 
    (interactive) 
    (scroll-down 1)) 

(defun scroll-up-one-line() 
    "Scroll up one line." 
    (interactive) 
    (scroll-up 1)) 

(global-set-key [(super up)] 'scroll-down-one-line) 
(global-set-key [(super down)] 'scroll-up-one-line) 

(global-set-key [(super right)] 'next-buffer) 
(global-set-key [(super left)] 'previous-buffer) 

(defun other-window-backwards() 
    (interactive) 
    (other-window -1)) 

(global-set-key [(control super down)] 'other-window) 
(global-set-key [(control super up)] 'other-window-backwards) 
0
;Nice list. Here's my block. 

(global-set-key [f1] 'revert-buffer) 
(global-set-key [f2] 'emacs-wiki-find-file) ; moved to xemacsinit 
(global-set-key [f3] 'insert-current-time) 
(global-set-key [f4] 'replace-regexp) 
(global-set-key [f5] 'replace-string) 
(global-set-key [f6] 'goto-line) 
(global-set-key [f10] 'linum-mode) 
(global-set-key [f11] 'my-shell-command-on-region) 
(global-set-key [f12] 'eval-region) 
(global-set-key [home] 'beginning-of-buffer) 
(global-set-key [end] 'end-of-buffer) 
(global-set-key "\C-x\C-n" 'other-window) 
(global-set-key "\C-x\C-p" 'other-window-backward) 
(global-set-key "\C-z" 'scroll-one-line-ahead) 
(global-set-key "\C-q" 'scroll-one-line-behind) 
(global-set-key "\C-x\C-q" 'quoted-insert) 
(global-set-key "\M-," 'point-to-top) 
(global-set-key "\M-." 'point-to-bottom) 
(global-set-key "\C-x," 'tags-loop-continue) 
(global-set-key "\C-x." 'find-tag) 
(global-set-key [(control tab)] 'other-window) 
(global-set-key [(control shift right)] 'other-window-backward) 
2

No enumerar estos en mi primera respuesta, pero en retrospectiva, siempre he encontrado útiles, y veo a menudo preguntas de la gente que podría resolverse fácilmente mediante el uso de las funciones apropos, ¡así que creo que cualquier cosa que las haga más visibles es algo bueno! (También vi que apropos-library ha aparecido desde añadí primera éstos, por lo que escribir esta respuesta era útil para mí :)

;; Make apropos searches also find unbound symbols, and 
;; set new key-bindings for various other apropos commands. 
(setq apropos-do-all t) 
(global-set-key (kbd "C-h a") 'apropos-command) 
(define-prefix-command 'Apropos-Prefix nil "Apropos (a,d,f,l,v,C-v)") 
(global-set-key (kbd "C-h C-a") 'Apropos-Prefix) 
(define-key Apropos-Prefix (kbd "a") 'apropos) 
(define-key Apropos-Prefix (kbd "C-a") 'apropos) 
(define-key Apropos-Prefix (kbd "d") 'apropos-documentation) 
(define-key Apropos-Prefix (kbd "f") 'apropos-command) 
(define-key Apropos-Prefix (kbd "l") 'apropos-library) 
(define-key Apropos-Prefix (kbd "v") 'apropos-variable) 
(define-key Apropos-Prefix (kbd "C-v") 'apropos-value) 

Con estos enlaces, escribo C-h C-a cuando quiero buscar algo , seguido de el personaje apropiado según el tipo específico de búsqueda que requiera (con un aviso que me ayude si no puedo recordar las posibilidades). Si no sé exactamente lo que estoy buscando, entonces un segundo C-a (o simple a) en el indicador ejecutará un apropos omnipresente.

Si no puedo recordar lo que realmente significan los caracteres de solicitud, teclear C-h nuevamente en el indicador (es decir, C-h C-a C-h) mostrará una lista de los enlaces.

3

Breadcrumb:

(require 'breadcrumb) 
(global-set-key [(control f2)]   'bc-set) 
(global-set-key [(f2)]     'bc-previous) 
(global-set-key [(shift f2)]   'bc-next) 
(global-set-key [(meta f2)]    'bc-list) 
0

mina tiene un par de combinaciones de teclas de Windows o Eclipse:

(global-set-key (kbd "<C-tab>") 'helm-mini) 
(global-set-key [M-f4]   'kill-emacs) 
(global-set-key (kbd "C-w")  'kill-this-buffer) 
(global-set-key (kbd "C-o")  'imenu) 
1
(global-set-key "\M-n" 'next-buffer) 
(global-set-key "\M-p" 'previous-buffer) 
(global-set-key (kbd "C-c w") (quote copy-word)) 
(global-set-key (kbd "C-c l") (quote copy-line)) 
(global-set-key (kbd "C-c p") (quote copy-paragraph)) 
(global-set-key (kbd "C-c s") (quote thing-copy-string-to-mark)) 
(global-set-key (kbd "C-c a") (quote thing-copy-parenthesis-to-mark)) 

(global-set-key "\C-o" 'other-window) 
(global-set-key "\M-o" 'other-window) 

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.") 
(define-key my-keys-minor-mode-map (kbd "C-,") 'beginning-of-buffer) 
(define-key my-keys-minor-mode-map (kbd "C-.") 'end-of-buffer) 
(define-minor-mode my-keys-minor-mode 
    "A minor mode so that my key settings override annoying major modes." 
    t " my-keys" 'my-keys-minor-mode-map) 
(my-keys-minor-mode 1) 
Cuestiones relacionadas