HomeMathComputingArtsWordsLiteratureMusictwitter facebook webfeed

Emacs Intermediate Tips

Advertise Here For Profit

Xah Lee, 2005, 2009, 2010-05-05, 2010-08-28

If you are a emacs beginner, see Emacs Basics.

Don't forget, all the basics such as copy, paste, open, save … are in the graphical user 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 and paste shortcuts called CUA mode. Mac screenshot

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 Up, Page Down 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 cancel the search and leave your cursor there. To exit search and leave the cursor at its original place, 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 about 3000 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
Ctrl+h kdescribe-keyFind the command name of a shortcut
Ctrl+h fdescribe-functionFind the shortcut 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 3k commands out of the box.

blog comments powered by Disqus