Emacs Quick Reference

http://sean.wenzel.net/docs/emacs/quick_reference/

Emacs Quick Reference

Notation


It is important to understand the notation commonly used in Emacs documentation. Most of the commands used in Emacs consist of a modifier key, in conjuction with one or more other keys. The following are the common modifier keys:
 CTRL- (C) -The CONTROL key.
META- (M) -Depending upon the terminal this is the ALT key. You may also use the ESC key to send META.
ESC - (ESC) -The ESCAPE key.
SHIFT- (S) -The SHIFT key.
In Emacs documentation it is common to use an abbreviated syntax when describing key sequences. Instead of typing
 CTRL-x CTRL-c
You would type
 C-x C-c
This would represent holding down the CONTROL key and pressing the letter x, and then holding down the CONTROL key and pressing the letter c. (M-C-/ would represent holding down the the ALT key and CONTROL key and pressing the "/" key. You could also press and release the ESCAPE key hold down the CONTROL key and type the "/" key.)

The following is a table of notation for other keyboard characters.
 BACKSPCThe BACKSPACE key.
SPCThe SPACE bar.
ENTERThe Enter key.
RETThe Enter key.
TABThe TAB key.


Insert Mode?


This is a large place where Emacs differs from the Vi editor. In Vi you are either in Insert Mode or you are not. In order to execute commands other than key insertion you need to be out of Insertion Mode. By using CTRL to escape the key sequences, Emacs allows you to use the commands at any point in your session. For example, if you are in Vi and are inserting text you would have to type the following key sequence to save your file and return to Insert Mode:
 ESC : w i
In Emacs (which is essentially always in "Insert Mode") you would type the following:
 C-x C-s
When viewed from the insertion mode view point, Vi doesn't really save any keystrokes over Emacs as is commonly claimed by religious Vi advocates. (It actually requires more in most cases - the debate is really whether you're in Insert Mode more than you are in Command Mode.)

What is really happening on the backend


Emacs is really a bunch of lisp routines programmed to operate on the text in the buffers. These complex routines are accessed via key bindings on the front end. For example, when you type an "s" you are really telling Emacs to run the "self-insert-command" on the letter "s" which inserts the letter "s" at the current Point of Insertion (POI). These backend commands can be accessed by typing M-x and then the command. For example, you open a file with the key binding "C-x C-f". You can begin the same operation by typing "M-x find-file".

Keyboard Shortcuts - (Key Bindings)

 

Key BindingBackend FunctionWhat it does
Quiting Things
C-x C-cM-x save-buffers-kill-emacsQuit Emacs . Exits out of Emacs. If you have open buffers that have been modified you are prompted to save the changes or discard them.
C-gM-x keyboard-quitIf you are in a key request sequence that you can't get out of, this returns you to the main buffer.
ESC ESC ESCM-x keyboard-escape-quitDoes about the same thing as "C-g"
C-x kM-x kill-bufferKills the current buffer. If the buffer is modified you are prompted to save it.
Files and directories
C-x C-fM-x find-fileOpen a file . This prompts for the name of a file. Once you have typed the file it opens it in the current buffer. If the file doesn't exist, a blank buffer is created and Emacs allows you to begin typing (In this case the file will not exist on the system until you save it the first time). When you are typing the name of the file, you may use the tab key for filename completion. Also you may use M-p and M-n to go to the "previous" and "next" files that have been found using find-file.
C-x C-sM-x save-bufferSave a file . This saves the current buffer.
C-x dM-x dired (directory edit)More Here. This opens the directory specified (same way as find-file). It opens a buffer that lists the directory and allows you to perform operations on the files. listed in that directory. There are many features (to many to list here) that I will go into later. The most basic is to put the cursor on the file you want and hit ENTER. This does a find-file on that file.
C-x C-wM-x write-fileSave the current file as...
C-x iM-x insert-fileInsert a file
Buffers
C-x C-bM-x list-buffersThis lists all buffers that are open. Emacs will typically open a buffer for each file that you visit (if you visit a new file without closing an old one). This will give you a list of all of the currently open buffers and will allow you to choose one from the list to switch to. (You will notice there are a couple of buffers beginning with an *. These are buffers used by Emacs to store output. You may kill them if you like.) If you have a file opened multiple times, you will see it listed as "file" and "file <2>". This list of buffers is called the buffer ring
C-x bM-x switch-to-bufferSwitch buffers . Does just that. The default buffer to switch to is the last one that you came from. (Typing C-x b ENTER repeatedly swaps between the current and the last buffer like ALT-TAB in windows.) You may type a TAB to complete the buffer name or TAB TAB to see a list of all of the buffer names you can type.
C-x kM-x kill-bufferKills the current buffer. If the buffer is modified you are prompted to save it.
Windows and frames
C-x 0M-x delete-windowKills the current window if more than one is visible. The buffer contained in the window is put back to the buffer ring.
C-x 1M-x delete-other-windowsIf more than one window is visible in the current viewing frame, it removes all but the current window. Other buffers remain open but unviewed.
C-x 2M-x split-window-verticallySplits the current viewing window into two windows placed one over the other.
C-x 3M-x split-window-horizontallySplits the current viewing window into two windows placed side to side.
C-x oM-x other-windowSwitches between two windows.
Moving Around
C-p (up arrow)M-x previous-lineMoves to the previous line.
C-n (down arrow)M-x next-lineMoves to the next line.
C-f (right arrow)M-x forward-charMove forward one character
C-f (left arrow)M-x backward-charMove backward one character
M-fM-x forward-wordMove forward one word.
M-bM-x backward-wordMove backward one word.
C-aM-x beginning-of-lineMove to the beginning of the line.
C-eM-x end-of-lineMove to the beginning of the line.
M-aM-x backward-sentenceMove backward one sentence.
M-eM-x forward-sentenceMove forward one sentence.
C-vM-x scroll-upPage down one page.
M-vM-x scroll-downPage up one page.
M->M-x end-of-bufferMoves to the end of the buffer.
M-<M-x beginning-of-bufferMoves to the beginning of the buffer.
C-x ]M-x forward-pageIn most modes does the same as M->
C-x [M-x backward-pageIn most modes does the same as M-<
 M-x goto-lineGoto line . Does what it says. I can't believe that there is not a default key binding for this (there is in XEmacs). I usually set up in my .emacs file the line (global-set-key "/M-g" 'goto-line) which tells emacs to use M-g to run the command.
C-x oM-x other-windowSwitches between two windows.
C-x bM-x switch-to-bufferSwitch buffers . Does just that. The default buffer to switch to is the last one that you came from. (Typing C-x b ENTER repeatedly swaps between the current and the last buffer like ALT-TAB in windows.) You may type a TAB to complete the buffer name or TAB TAB to see a list of all of the buffer names you can type.
C-SPCM-x set-mark-commandSet Mark . Sets the mark to the current cursor location (point). Many commands are run on the region in between the point and mark.
C-x C-xM-x exchange-point-and-markExchanges the point (cursor location) and the mark.
Copying and Deleting stuff
C-_M-x undoUndo . Undoes the last command. Can be done repeatedly.
C-dM-x delete-charDelete . Deletes the character under the point (after the cursor location).
BACKSPCM-x delete-backward-charDelete . Deletes the character before the point (before the cursor location).
M-dM-x kill-wordKills the word after the cursor location. Places on the kill ring.
M-BACKSPCM-x backward-kill-wordKills the word before the cursor location. Places on the kill ring.
C-kM-x kill-lineKill . Kills from the point to the end of the line. If repeated in a row, all of kills go into the same kill ring entry. Doing this once does not kill the new line at the end of the line. Repeating kills the newline. (for example, to kill the entire current line you would type C-a to move to the beginning of the line, and C-k C-k to kill the line and the newline).
C-yM-x yankYank . Inserts the last entry from the kill ring. This can be done repeatedly.
M-yM-x yank-popCycle through the kill ring. Operates only if the last command was C-y
C-SPCM-x set-mark-commandSet Mark . Sets the mark to the current cursor location (point). Many commands are run on the region in between the point and mark.
C-wM-x kill-regionKills the text between the mark and the point. Places on the kill ring. If the buffer is read only, places text on kill ring but warns about not being able to modify buffer.
M-wM-x kill-ring-savePlaces text between mark and point on the kill ring without killing text.
M-zM-x zap-to-charDeletes the text from the point up to the first instance of the specifed character
Search and Replace
C-sM-x isearch-forwardSearches forward for the typed in text. C-s repeatedly searches forward multiple times. C-r switches direction of search.
C-rM-x isearch-backwardSearches backward for the typed in text. C-r repeatedly searches backward multiple times. C-s switches direction of search.
M-%M-x query-replaceRequests two patterns. Searches for first pattern and replaces with second pattern. Prompts at each match. (y for "yes replace", n for "no next", and ! for "replace all").
C-u C-sM-x isearch-forward-regexpSearch using a regular expression (as you type it).
M-C-%M-x query-replace-regexpQuery replaces using a regular expression as the match.
Fixing up the text
TABM-x indent-relative-maybeIndent the text according to the program mode you are in.
M-C-/M-x indent-regionRuns the "TAB" on all lines in the region.
M-uM-x upcase-wordUpper casifies from the point to the end of the word.
M-lM-x downcase-wordLower casifies from the point to the end of the word.
C-tM-x transpose-charsSwaps characters before and after point with one another.
M-tM-x transpose-wordsSwaps current and next word with one another.
Dired - Directory Editor
C-x dM-x dired (directory edit)This opens the directory specified (same way as find-file). It opens a buffer that lists the directory and allows you to perform operations on the files. listed in that directory. There are many features (to many to list here) that I will go into later. The most basic is to put the cursor on the file you want and hit ENTER. This does a find-file on that file.
All commands in this section will only operate when you are in dired mode.
ENTERM-x dired-advertised-find-fileRuns a C-x C-f (find-file) on the currently highlighted file. If the file is a directory, that directory will be opened in dired mode in a new buffer.
+M-x dired-create-directoryPrompts for a new directory name and creates it.
dM-x dired-flag-file-deletionFlags the current file for deletion.
~M-x dired-flag-backup-filesFlags all files ending with ~ for deletion (backup files)
xM-x dired-do-flagged-deleteDelete all files marked for deletion (lines beginning with a D
DM-x dired-do-deleteDeletes the currently highlighted file(s)
CM-x dired-do-copyCopies the currently highlighted file(s). Prompts for the destination.
RM-x dired-do-renameRenames the currently highlighted file(s). Prompts for the destination.
% RM-x dired-do-rename-regexRenames the currently highlighted file(s) using regular expressions. Prompts for a regex for from and to. (example - from regex /(.+/).txt , to regex /1.text )
mM-x dired-markMark the current file (marks with a * )
uM-x dired-unmarkUnmark the current file (marks with SPC - SPC is blank)
* c M-x dired-change-marksChanges marks from first prompted letter to second prompted letter (example - * c D SPC - this will clear the deletion flag)
!M-x dired-do-shell-commandExecute command on files marked with * . If your command contains a * , the list of marked files will be substituted in place and executed. Otherwise, the command will be played once with each marked file as the last argument.
gM-x revert-bufferRefreshes the current dired directory.
Help - Finding it
C-h tM-x help-with-tutorialBegins the Emacs built in Tutorial - highly recommended
C-h kM-x describe-keyAllows you to type in key strokes and see the backend function that they are running.
C-h fM-x describe-functionAllows you to type a function name and receive an explanation of what it does.
C-h vM-x describe-variableAllows you to type a Emacs variable name and see its contents
C-h bM-x describe-bindingsShow a table of all of the current key bindings.
C-h iM-x infoThis one is possibly the most important. It enters into the Emacs help browser which allows you to read in depth about just about any subject relating to Emacs. (Basic commands are "l" for last, "n" for next, and "p" for previous.) I'll talk more about this later.
Text Registers
C-x r sM-x copy-to-registerPrompts for register letter. Saves text between point and mark in the register.
C-x r iM-x insert-registerPrompts for register letter. Inserts the text saved in that register at point.
Position Registers
C-x r SPCM-x point-to-registerPrompts for register letter. Saves point in register.
C-x r jM-x jump-to-registerPrompts for register letter. Jumpts to point saved in that register.
Bookmarks
C-x r mM-x bookmark-setPrompts for bookmark name (default is buffer name). Saves point in a bookmark. This information is saved even if you close Emacs.
C-x r bM-x bookmark-jumpPrompts for bookmark name. Jumpts to point saved in that bookmark (Even if you had closed your emacs session).
C-x r lM-x bookmark-bmenu-listLists all saved bookmarks. Typing "j" when on a bookmark jumps to the file. Dired commands are used to delete bookmarks (Type "d" when on file - then "x" to delete bookmark).
Rectangles
C-x r oM-x open-rectangleOpens rectangle of whitespace between point and mark.
C-x r tM-x string-rectangleReplaces text between point and mark with rectangle of text (prompts for text). This is a major timesaver. Typing
C-x r t "Other Text" RET
would replace
<mark>Some Text
Some Text
Some Text<point>
   With   <mark>Other Text
Other Text
Other Text<point>
C-x r kM-x kill-rectangleKills text between point and mark and places in rectangle kill ring.
C-x r yM-x yank-rectangleInserts last killed rectangle at point.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值