ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

Emacs Intermediate Tips

Xah Lee, 2005, …,

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)〗. The CUA mode will activate the following shortcuts:

Also, it will highlight when a region of a text is selected. And, when a text is selected, typing any text will automatically replace the current selection. Pressing the ⌫ Backspace key will also delete the selection.

emacs cua mode menu
The emacs's 〖Options〗 menu. You can turn on standard copy & paste shortcuts called CUA mode.
emacs basic options
Emacs on Mac.

Basic Keyboard Shortcuts

Open, Save, Close

Ctrl+x Ctrl+fOpen a new file
Ctrl+x Ctrl+sSave file
Ctrl+x kClose the current file

Moving Cursor

Use the arrow keys    , and ↖ Home, ↘ End, ⇞ Page △, ⇟ Page ▽ keys.

Ctrl+Move cursor left by word.
Ctrl+Move cursor right by word.
Ctrl+↖ HomeBeginning of document.
Ctrl+↘ EndEnd of document.

Deleting Text

Alt+dDelete the next word
Alt+⌫ BackspaceDelete the previous word
Ctrl+kDelete all characters from cursor to end of line

Copy Paste Undo

First pull the menu 〖Options ▸ C-x/C-c/C-v Cut and Paste (CUA)〗, then pull the menu 〖Options ▸ Save Options〗.

Ctrl+zUndo. (To redo, type any character then do undo twice.)
Ctrl+cCopy
Ctrl+xCut
Ctrl+vPaste
Ctrl+x hSelect All
Ctrl+SpaceMark the starting point for copy/cut a text

Split Window

Ctrl+x 2Split window into 2 panes
Ctrl+x 1Make the cursor pane fill window
Ctrl+x oMove cursor to the other pane

Searching Text

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 a arrow key to exit.

To exit search and leave the cursor at the place before search started, press 【Ctrl+g】.

Find/Replace Text

See: advanced emacs tips.

Basic Principles of Emacs

Everything Is a Command

In emacs, every keystroke actually executes a command. For example, when you type a key e, emacs actually runs the command self-insert-command. Any key or key combination sequence you press ultimately calls a command. There are 2.5k commands in emacs. 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.

ShortcutCommand NameDescription
Ctrl+gkeyboard-quitCancel a command in progress, or cancel unfinished keyboard keystroke sequence
Alt+xexecute-extended-commandexecute a command by name

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).

If you know a keyboard shortcut, you can find out what command it calls.

The commands for these are describe-key and describe-function.

ShortcutCommand NameDescription
F1 kdescribe-keyFind the command name of a key
F1 fdescribe-functionFind the key of a command

Example of Useful Commands

In emacs, a selection of text is called “region”. 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:

The above are just some examples. There are 2.5k commands in emacs by default.

blog comments powered by Disqus