Emacs Keys Basics
Don't forget, all the basics such as copy, paste, open, save … are in the graphical menus. The menu also shows you their keyboard shortcuts.
Standard Copy Paste Keys
First, turn on the “CUA” mode, under the menu 〖Options ▸ C-x/C-c/C-v Cut and Paste (CUA)〗.
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)
Basic Keyboard Shortcuts
Open, Save, Close
|【Ctrl+x Ctrl+f】||Open a new file|
|【Ctrl+x Ctrl+s】||Save file|
|【Ctrl+x k】||Close current file|
Use the arrow keys ↑ ↓ ← →, and ↖ Home, ↘ End, ⇞ Page Up, ⇟ Page Down keys.
|【Ctrl+←】||Move cursor left by word.|
|【Ctrl+→】||Move cursor right by word.|
|【Ctrl+↖ Home】 or 【Alt+<】||Beginning of file.|
|【Ctrl+↘ End】 or 【Alt+>】||End of document.|
|【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|
Copy Paste Undo
|【Ctrl+/】||Undo. (To redo, type any character then do undo twice.)|
|【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 / Highlight Words.
Find Replace Text
Principle of Emacs
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.
|【Alt+x】||execute a command by name|
|【Ctrl+g】||Cancel a command in progress, or cancel unfinished keyboard keystroke sequence|
Finding a Command's Name or Keyboard Shortcut
If you know a command's name, you can find out its keyboard shortcut (if there is one). Call
If you know a keyboard shortcut, you can find out what command it calls. Call
|【Ctrl+h k】||Find the command name of a key|
|【Ctrl+h f】||Find the key of a command|
Example of Useful Commands
In emacs, a selection of text is called region. (aka text selection.)
Many commands acts on the selected text. Here are some examples of commands that act on the region.
Not all commands acts on region. Here are some commands that do not necessary need a region:
list-matching-lines(acts on whole file)
delete-matching-lines(acts on region if exist, else work from cursor point to end of file.)
delete-non-matching-lines(acts on region if exist, else work from cursor point to end of file.)
The above are just some examples of commands.
or, buy something from Best Keyboard for Emacs