https://wikemacs.org/api.php?action=feedcontributions&user=Cmpitg&feedformat=atomWikEmacs - User contributions [en]2024-03-29T10:26:51ZUser contributionsMediaWiki 1.35.14https://wikemacs.org/index.php?title=Key_Bindings&diff=2823Key Bindings2012-05-11T04:00:07Z<p>Cmpitg: /* Change key bindings */</p>
<hr />
<div>In Emacs, almost any keystroke, optionally combined with one or more modifier keys, or any sequence of such keystrokes, can be "bound" to any [[command]].<br />
<br />
== Modifier keys naming convention ==<br />
<br />
{| class="wikitable"<br />
|-<br />
! Modifier key<br />
! Abbr.<br />
! Remarks<br />
! Example<br />
! Action<br />
|-<br />
| Alt<br />
| A<br />
| Relatively seldom used in Emacs, because Meta is often "logically" mapped to the "physical" <tt>Alt</tt> key.<br />
| A-x<br />
| Type "x" while holding down the (non-Meta) Alt key<br />
|-<br />
| Control<br />
| C<br />
| <br />
| C-x C-f<br />
| While holding down Ctrl, type first "x" then "f". (This runs the command <tt>find-file</tt>).<br />
|-<br />
| Hyper<br />
| h<br />
| Often not mapped to any key (by default).<br />
| h-x<br />
| Type "x" while holding down hyper<br />
|-<br />
| Meta<br />
| M<br />
| Often mapped to <tt>Alt</tt> on your keyboard<br />
| M-x find-file RET<br />
| Either:<br />
* type "x" while holding down Meta, or<br />
* type "Esc" then "x"<br />
(M-x activates the [[minibuffer]])<br />
<br />
Then type "find-file" in the minibuffer, then Return.<br />
|-<br />
| Shift<br />
| S<br />
| <br />
| S-x<br />
| Type "x" while holding down Shift<br />
|-<br />
| Super<br />
| s<br />
| On OS X this is the Command ⌘ key.<br />
On other systems often not mapped to any key by default, or to <tt>Window</tt> or <tt>Menu</tt> if present<br />
| s-x<br />
| Type "x" while holding down super<br />
|-<br />
|}<br />
<br />
By convention, when multiple modifiers are specified, they go in alphabetical order: {{Keys|C-M-x}} not {{Keys|M-C-x}}.<br />
<br />
== Printable cheat sheet for popular modes ==<br />
Emacs ships with cheat sheets of common and useful key bindings.<br />
The {{File|pdf}} files are located in the {{Directory|refcards}} subdirectory of {{Variable|data-directory}}.<br />
<br />
== Change key bindings ==<br />
<br />
You can add, remove and change key bindings for any command by using the Emacs Lisp function <code>global-set-key</code> or <code>local-set-key</code>.<br />
<br />
; {{Command|global-set-key}} or {{Command|local-set-key}}<br />
: Hit the key sequence you want to bind<br />
: Type the command to bind to that key sequence<br />
: Invoke {{Keys|C-x ESC ESC|repeat-complex-command}}. The output you see is the full lisp command which does the binding. You can copy this to your {{EmacsConfigFile}}.<br />
<br />
'''Notes:'''<br />
<br />
* <code>global-set-key</code> bind keys globally (i.e. <code>global-mode-map</code>), which means other modes would override key bindings set by <code>global-set-key</code>.<br />
<br />
* <code>local-set-key</code> bind keys in the current buffer [[major mode]], which affects all buffers sharing the mode.<br />
<br />
== External Links ==<br />
<br />
* [http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/ Mastering Keybindings in Emacs]<br />
<br />
[[Category:Customization]]<br />
[[Category:Key Concepts]]</div>Cmpitg