什么是emacs中的好的自定义键绑定? [英] What are good custom keybindings in emacs?

查看:134
本文介绍了什么是emacs中的好的自定义键绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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




  • indent-buffer(Cc i,得到答案后)

  • comment-or-uncomment-region(Cc C)

  • rdebug(ruby debugger)(Cc R)

  • rsense-complete(ruby autocomplete)(Cc e)



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

解决方案

Emacs实际上具有非常明确的绑定模式,这个答案显示了一些。



至于你应该定义键,如果您查看文档约定,您将看到 Cc a (其中 a 是任何大写或大写字符)为用户保留。



另外,如果您正在定义一个真正只在特定模式下有意义的键,那么您应该在该键盘映射中定义它。



例如, M - / 绑定到 dabbrev-expand ,这是一个方便的方式来自动填写你输入的单词。使用 rsense-complete 可能非常有用,但是当您使用红宝石时,只能使用。在这种情况下,您可以这样做:

 (add-hook'ruby-mode-hook 
(lambda )(define-key ruby​​-mode-map(kbdM- /)'rsense-complete)))

只有当您在 ruby​​-mode 中时,它将覆盖 M - / 的绑定,并保持不变(或可用)其余的模式。


Emacs seems to have all the possible keyboard combinations already randomly distributed among it's commands. :p

If I am to define new keyboard shortcuts, where should I put them? Which prefixes should I use?

For instance: I want to define shortcuts for the following functions:

  • indent-buffer (C-c i, after I got the answer)
  • comment-or-uncomment-region (C-c C)
  • rdebug (ruby debugger) (C-c R)
  • rsense-complete (ruby autocomplete) (C-c e)

Where would you put these? Why?

解决方案

Emacs actually has a very definite pattern to its bindings, this answer shows some.

As far as where you should define keys, if you take a look at the documentation for conventions, you'll see that C-c a (where a is any lower or upper case character) is reserved for users.

Plus, if you're defining a key that really only makes sense in a particular mode, then you should define it in that keymap.

For example, M-/ is bound to dabbrev-expand, which is a handy way of autocompleting the word you're typing. It might very well make sense to use rsense-complete instead, but only when you're in ruby. In which case, you can do this:

(add-hook 'ruby-mode-hook
     (lambda () (define-key ruby-mode-map (kbd "M-/") 'rsense-complete)))

That will override the binding for M-/ only when you're in ruby-mode, and leave it unchanged (or available) for the rest of the modes.

这篇关于什么是emacs中的好的自定义键绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆