Emacs Keys Basics
Here's list of basic emacs default keys.
Open, Save, Close, File
Copy Paste Undo
|Ctrl+_||Undo. (To redo, type Ctrl+g then undo. (all subsequent undo is redo, until you type something else.))|
Use the arrow keys ↑ ↓ ← →, and Home, End, PageUp, PageDown keys.
|Ctrl+← or Alt+b||Move cursor left by word.|
|Ctrl+→ or Alt+f||Move cursor right by word.|
|Ctrl+Home or Alt+<||Beginning of file.|
|Ctrl+End or Alt+>||End of document.|
|Ctrl+f||Move cursor right 1 char.|
|Ctrl+b||Move cursor left 1 char.|
|Alt+d||Delete the word to the right.|
|Alt+Backspace||Delete the previous word|
|Ctrl+k||Delete all characters from cursor to end of line|
|Ctrl+Space||Mark the starting point for copy/cut a text. (then move cursor to extend selection.)|
|Ctrl+x h||Select All|
|Ctrl+x 2||Split window top/bottom|
|Ctrl+x 3||Split window side by side|
|Ctrl+x 1||Remove all split panes|
|Ctrl+x o||Move cursor to the other pane|
To search a word, press Ctrl+s, then type your search text, emacs will move the cursor to the location of the matched text as you type. Press Ctrl+s again to jump to the next occurrence, press Ctrl+r to jump to the previous occurrence.
Once you found what you are looking for, press Enter to exit.
To exit search and leave the cursor at the place before search started, press Ctrl+g.
For detail, see: Emacs: Search Text in Current File.
Find Replace Text
Emacs: Find Replace in Current File
Standard Copy Paste Keys
To have standard keys for copy cut paste , turn on CUA mode,
cua-mode activates the following keyboard shortcuts:
- Ctrl+x for cut
- Ctrl+c for copy
- Ctrl+v for paste
- Ctrl+z for undo (emacs 23 () or later)
cua-mode always on, put the following in your emacs init.
;; use C-x for cut ;; C-c for copy ;; C-v for paste (cua-mode 1)
Everything is a Command
In emacs, every keystroke executes a command. For example, when you type a key e, emacs actually runs the command
Any key or key combination sequence you press ultimately calls a command.
There are over 3 thousand commands in emacs by default.
Most commonly used commands have a keyboard shortcut, such as moving the cursor, opening file, copy paste, close a file, search text.
To run a command by name, type Alt+x followed by the command name.
- Execute a command by name
- Cancel a command in progress, or cancel unfinished keyboard keystroke sequence
Find What a Key Do
- Prompt to type a key shortcut, then show command name and doc bound to that key.
Find a Command's Key
- Prompt to type a command name, it'll shows the command's key, if any.
How to Define Keys
You can define your own keys for any command.
Emacs: How to Define Keys