emacs - emacs 中有哪些好的自定义键绑定(bind)?

标签 emacs keyboard keyboard-shortcuts emacs23

Emacs 似乎已经将所有可能的键盘组合随机分布在它的命令中。 :p

如果我要定义新的键盘快捷键,我应该把它们放在哪里?我应该使用哪些前缀?

例如:我想为以下功能定义快捷方式:

  • 缩进缓冲区(C-c i,在我得到答案后)
  • 注释或取消注释区域 (C-c C)
  • rdebug (ruby 调试器) (C-c R)
  • rsense-complete (ruby 自动完成) (C-c e)

  • 你会把这些放在哪里?为什么?

    最佳答案

    我通常将全局键绑定(bind)放在单独的文件(我的配置的一部分)中,并将特定于模式的配置放在特定于模式的配置文件中。这样一来,一切都变得精简、紧凑且易于找到。您提到的某些内容(例如注释/取消注释)已经附加了键绑定(bind)。我已经使用绑定(bind)到标准 C-M-\缩进键的函数 indent-buffer-or-region(EDT 的一部分)实现了 indent-buffer。对于用户应该为他们的自定义键绑定(bind)使用哪些键,有正式的规则,当然也有常识。没有什么是一成不变的。

    以下是来自 Emacs Prelude 的一些示例:

    ;; 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)
    
    ;; 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
    
    ;; 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)
    
    ;; 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))))))
    
    ;; 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)
    
    ;; toggle input method
    (global-set-key (kbd "C-\\") 'toggle-bulgarian-input-method)
    
    ;; search with google
    (global-set-key (kbd "C-c g") 'google)
    
    ;; toggle menu-bar visibility
    (global-set-key (kbd "<f12>") (lambda () (interactive) (menu-bar-mode)))
    

    关于emacs - emacs 中有哪些好的自定义键绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5682631/

    相关文章:

    debugging - Emacs:我可以限制缓冲区中的行数吗

    Emacs - require-final-newline 本地值覆盖全局值

    visual-studio - Visual Studio 2019 键盘停止响应或不断重复字符

    ios - becomeFirstResponder 在 iOS 11 中不显示键盘

    Javascript动态调用shortcutjs插件的快捷键组合功能

    eclipse - 相当于eclipse中intelliJ的Ctrl + Shift + A?

    emacs - 如何在emacs的文本模式下更改缩进

    string - 如何在Emacs Lisp中将列表转换为字符串

    c# - Autohotkey:以下键的键码是什么

    intellij-idea - Command + 单击后 IntelliJ 返回