Customize your Emacs key bindings
As you know, Emacs functions are bound to keystroke combinations called key bindings; the standard Emacs bindings are made to be easy to use and remember—there's often a mnemonic hint associated with the key used in a binding—and fast to employ—they're set up so you can type any given keystroke combination quickly and with a minimum of hand motion.
But if you don't like them, you can change them. You can customize every key
binding Emacs has: You can, if you desire, make A type a Z, or make
C-f move the cursor backward and
C-b move it forward. Although these aren't likely to
be useful changes for most users, there could be many reconfigurations that you
personally might find handy. Furthermore, Emacs has many, many more functions
than it has default bindings—and many possible keystroke combinations aren't
bound to any function.
If you use a particular function or group of functions frequently and they aren't bound to a keystroke (or if the keystrokes are bound to are less convenient than others), you can redefine them. Or if there's a function you don't use, you can remove its binding, freeing that keystroke for something else.
global-set-key function binds a given function
to a given keystroke, and makes it effective across all modes and buffers. Use it
next to make a number of customizations and fixes.
The Home and End keys are usually configured in two common ways in Emacs: Either they move the cursor to the beginning and ending of the current line, or they move the cursor to the beginning and ending of the current buffer.
See which of the two ways yours are bound: Press Home and End a few times each in your bee buffer.
Now that you know what these keys are bound to, try changing their bindings:
If your Home and End keys are bound to move to the beginning and ending of the current line, type:
M-x global-set-key Enter Set key globally: Home Set key <home> to command: beginning-of-buffer M-x global-set-key Set key globally: End Set key <home> to command: end-of-buffer
If your Home and End keys are bound to move to the beginning and ending of the current buffer, type:
M-x global-set-key Set key globally: Home Set key <home> to command: beginning-of-line M-x global-set-key Set key globally: End Set key <home> to command: end-of-line
Test Home and End in this buffer a few times, and then try them in the cee buffer to show that the changes you just made were global:
Home End Home End C-x b cee Enter Home End Home End
On some configurations for Emacs, the Del key is bound to the same function as the
delete-backward-char. This isn't the
value most people want or expect; with most software, the Del key deletes the
character following the cursor, not behind it.
Test your Del key:
C-x b *scratch* Enterto move to the scratch buffer.
Type some text:
M-bso that the cursor is on the m character.
If your Del key is bound correctly, the m was deleted. If you deleted the blank space between the two words instead, then you can fix your Del with the following:
M-x global-set-key Set key globally: Del Set key C-d to command: delete-char
To define a new binding for a keystroke that's currently undefined, run the
global-set-key function, give the new keystroke,
and then the command to run.
For example, the M-F1keystrock is, by default, undefined. You type this keystroke by pressing and holding Alt (or whatever is the Meta key on your keyboard), pressing the F1 key, and releasing both keys. Try it—the only thing that should happen when you do is that Emacs beeps, indicating that this keystroke has been defined to no function.
You can define this keystroke to run the
phases-of-moon function, which opens a new buffer
window showing the current phases of the Moon.
M-x global-set-key Set key globally: M-F1 Set key <M-F1> to command: phases-of-moon
Try your new key binding: Type
M-F1. After you do,
you should see a new buffer window open with the current phases of the moon.