Simple use and configuration of Emacs

Source: Internet
Author: User
Tags save file

Use of Emacs

Ted Posted @ September 16, 2008 22:35 in Emacs with tags emacs, 5455 read

Introduction of Emacs Editor

The Emacs Editor is written in the C and Lisp languages. LISP (linked list processing language) is a functional programming language based on the lambda calculus created by John McCarthy in about 1960 years. We can use Lisp to expand Emacs to add more commands to Emacs. (Complement: EMACS-NW: Run emacs as a command line without starting the GUI interface)


* Auto Save function

If you have modified a file, but have not yet saved your computer to strike, then the changes you have made are likely to be lost. To avoid this unfortunate occurrence, Emacs periodically writes the file being edited to an "AutoSave" file. Automatically save the file's filename has a "#" character, such as the file you are editing is called "hello.c", then its auto-save file is called "#hello. C #". This file will be deleted by Emacs after the normal disk.
So, if the misfortune really happened, you can easily open the original file (note not automatically save the file) and then enter M-x recover file<return> to recover your AutoSave file. When prompted for confirmation, enter yes<return>.

* Other

    1. When Emacs loses its response, the C-G command can be used to end the execution of the note command. Its function is equivalent to CTRL + C in the shell

    2. Some Emacs commands are "disabled" to prevent the novice from being misused without knowing their exact functionality. If you use a command that is disabled, Emacs displays a message that tells you what the command is doing, asks if you want to continue, and executes the command after you've got your affirmation.


Ii. interface of the Emacs editor

1. Edit Area
The area used for text editing.

2. Echo Zone

If Emacs finds you are slow to enter a multi-character command, it will give you a hint at the bottom of the pane called the Echo zone. The Echo area is located on the bottom line of the screen.


3. Status bar

    1. The line that is directly above the Echo area is called the status bar. The asterisk (*) at the beginning of the status bar indicates that you have changed the text. The file you just opened must not have been altered, so the status bar does not display asterisks but short lines (-).

    2. The parentheses in the status bar are used to indicate the editing mode currently in use, the default is fundamental (main mode), and the main mode of Emacs includes the text mode and the Lisp mode of the editing program source.


Third, the working environment that Emacs can provide

    1. Emacs can execute shell commands

    2. Emacs can be used as directory Editor (dired)

    3. Emacs can edit, compile, and debug programs

    4. Emacs can edit documents on other hosts

    5. Emacs can print files

    6. Emacs has a calendar and diary features

    7. Emacs can be used to read the man page and info documents

    8. Emacs can send and receive e-mails

    9. Emacs can read the electronic bulletin Board (GNUS) on the network

    10. Emacs has version-controlled functionality (CVS)

    11. Emacs provides an entertainment environment (game function)

Emacs provides these features by first evoking the mode that represents this function. The Emacs mode is divided into the main mode (major mode) and the secondary (minor mode). Only one main mode can be used each time, and the main mode is required. In one main mode, Russia can be paired with more than one secondary mode. Using the secondary mode is equivalent to enabling the plug-in for that secondary mode.


Iv. Emacs Commands

    1. Each command in Emacs has a command name, which is the function name of the Lisp function that corresponds to the command. In Emacs, we can configure shortcut keys for these commands to achieve the purpose of quickly invoking commands.

    2. There are two ways to execute commands using Emacs: (1). Use the CTRL key (2). Use the META key. All Emacs commands can be represented by a meta key, which can be replaced with the ALT key or the ESC key if there is no meta key on the keyboard. Commonly used Emacs commands usually have a shortcut key attached to it. Shortcut keys are usually prefaced with Ctrl (C-x c-c). If you want to use the META key to express the same effect as "Ctrl-x ctrl-c", use "M-x save-buffers-kill-emacs". Using the META key, you can take advantage of Emacs's completion function. The completion functionality of Emacs is done by typing part of the string and then pressing the tab, space, or? key.
      (1). Tab: Fill in as many words as possible.
      (2). Space key: Fills the word before the delimiter (-).
      (3).? : List all possible completion selections.

    3. Since all commands in Emacs have a command name (the function name of the Lisp functions), we can use "m-x command name" to invoke all the commands in Emacs.

* Basic Cursor control

    1. C-V: Flip down screen, same as PageDown effect (v-> vertical)

    2. M-V: Flip up screen, same as PageUp effect

    3. C-l: Redraw the screen and place the line of the cursor in the center of the screen

    4. C-b: Cursor moves forward one cell (B->backward)

    5. C-F: Move the cursor one cell backward (F->forward)

    6. C-P: Cursor moves forward one line (p->previous)

    7. C-N: Cursor moves backward one line (N->next)

    8. M-b: Cursor moves forward one word

    9. M-F: Cursor moves backward one word

    10. C-A: Cursor moves to the beginning of the line

    11. C-E: Cursor moves to end of line

    12. M-<: Cursor moves to the beginning of the article (Note: "<" input to shift key, actual alt+shift+<)

    13. M->: Cursor moves to the end of the article

    14. C-u: Pass parameters to the command. For example: "C-u 2 c-d" means delete two characters

    15. M-x goto-line n RET: Transfer to Nth row

* Edit Command

    1. c-d: Delete a character after the cursor

    2. C-k: Delete characters from cursor to end of line (K->KILLL)

    3. C-x U:undo (want to redo, just type a character, at Undo)

    4. C-SPC, [email protected], m-x Set-mark-command: Setting up Mark

    5. C-x h: Sets the entire buffer to a region

    6. C-W: Delete the text of the area and put it in the yanking ring. A region is the text between Mark and point, which is referred to as the position where the cursor is located.

    7. M-w: Copy area to yanking ring

    8. C-y: Inserts the last area of the yanking ring into the current buffer

    9. M-j: Enter and generate appropriate indent to the next line

    10. M-M: Moves the cursor over the first non-whitespace character of the current line

    11. m;: Generating generic annotations

    12. M-x comment-region: Comment out the block

    13. M-x kill-comment: removing annotations

* Find and replace

    1. C-s: Backward Search, the cursor will stop at the first matching string. Press once again c-s will continue searching for the next matching string. If you want to stop the search, use C-G, where the cursor will return to the beginning of the search

    2. C-r: Search Forward

    3. M-x replace-string: Replace

* File operation

    1. C-x c-f: Open file, create if file does not exist

    2. C-x c-s: Save the file. When the first disk is saved, Emacs renames the file to back it up. The rule for a heavy command is usually to add a "~" character after the original file name. If you want to turn off the automatic backup feature for Emacs, use m-x customize-variable <Return> make-backup-files <Return>

    3. C-x c-w: "Save File as"

    4. C-x c-v: Opens a new file and closes the current buffer

    5. C-x c-r: Open file in read-only mode

    6. C-x i: Inserting a file into the cursor's current position

* Buffer

    1. Emacs places the files in each edit in a place called buffer. For each file opened, Emacs creates a buffer within it to hold the data for the open file. The ESC ESC ESC command can be used to exit a small open buffer, such as a command prompt pane, etc.

    2. C-x c-b List all current buffers (B->buffer)

    3. C-x b buffer Name: Switch to the specified buffer (for example: C-x b m<tab>: Switch to buffer beginning with M)

    4. C-x s: Save all buffers in Emacs (S->save)

    5. C-x right: Switch to the next buffer

    6. C-x left: Switch to the previous buffer

    7. C-x c-c: Quit Emacs and ask the user whether to save

    8. C-x k: Close buffer

    9. C-z: Suspends emacs and then returns to the shell without exiting Emacs. After that, we can use the%emacs or FG command to return to Emacs.


* Window

Emacs can have more than one pane, and each pane displays different text.

    1. C-x 0: Close the window where the cursor is located

    2. C-x 1: Keep the pane where the cursor is located and expand it to the entire screen while turning off all other panes

    3. C-x 2: Split the current window horizontally

    4. C-x 3: Split the current window vertically

    5. C-x o: Toggle in Emacs's Pane (O->other)

    6. C-m-v: Scrolls below the pane. Typically used when we use the lower pane for reference, without having to switch the cursor to the next pane


* Use Help

    1. C-h C Shortcut: A brief description of the display shortcut key

    2. C-h K Shortcut: Displays the command name corresponding to the shortcut key and its detailed description

    3. C-h a keyword: Displays commands with the specified keyword

    4. C-h I: View info document


* Run shell commands in Emacs

    1. m-! CMD RET: Opens a window named "*shell command output*" and displays the execution results of the command. You can close this window by pressing the "C-x 1" key combination. Since the output of the shell command is in an edit buffer, we can edit it, save it, and so on.

    2. m-| CMD RET: Runs the shell command and uses the selected area of the edit window as input to the shell command, and optionally replaces the selected area in the editing window with the output of the shell command.

    3. C-u m-! CMD RET: Executes a shell command and places its output in the edit area where the cursor is located without outputting it to the shell command Output window.

    4. M-x Shell: Run a child shell that corresponds to a buffer named "*shell*" in Emacs, and then we can run the shell command interactively.

    5. M-x Term: Runs a child shell that corresponds to a buffer named "*terminal*" in Emacs. The child shell obtained using this command is a full shell simulation, with no difference in how we operate directly in the shell.

    6. M-x Eshell: Run emacs Shell. The shell is a shell implemented by Emacs itself, and the shell running in front of it is the shell program in the system (for example:/BIN/CSH, etc.). We can set the default shell used by Emacs by setting the variable shell-file-name

* Dired function

    1. The dired (directory Editor) feature of Emacs enables the Emacs buffer to be used to display a directory listing and can be used to access subdirectories of the directory. The dired buffer is read-only and cannot be modified.

    2. C-x d: Enter dired


* Emacs Configuration file

The Emacs profile is usually located in the $HOME directory of the computer, if it is MS windows (Windows $, Windows XP or above), the default is C:\Documents and Settings\username\application Data\, this applies to versions above EMACS22. EMACS21 the default $HOME directory in C: \. Of course, you can also reset the environment variable $HOME, in short, in the more popular operating system, you can c-x c-f ~/.emacs to edit your personalization profile.

;; Show time

(Display-time)

;; Show line Numbers

(Column-number-mode t)

(Show-paren-mode t)

;; Set tab width to 4

(setq default-tab-width 4)

;; The following settings indent

(setq c-indent-level 4)

(setq c-continued-statement-offset 4)

(setq c-brace-offset-4)

(setq c-argdecl-indent 4)

(setq c-label-offset-4)

(setq c-basic-offset 4)

(Global-set-key "\c-m" ' reindent-then-newline-and-indent)

(setq indent-tabs-mode Nil)

(setq standard-indent 4)

;; Turn on syntax highlighting.

(Global-font-lock-mode 1)

;; Set the default working directory

(setq default-directory "/home/test/source/")

;; Remove scroll bar

(Set-scroll-bar-mode Nil)

;; Turn off the open screen

(setq inhibit-startup-message T)

(setq Indent-tabs-mode T)

;; Do not produce backup files

(setq make-backup-files Nil)

;; Set Custom variables

(Custom-set-variables

' (Column-number-mode t)

' (current-language-environment "UTF-8")

' (Display-time-mode t)

' (ecb-options-version "2.32")

' (Mouse-1-click-in-non-selected-windows t)

' (Mouse-drag-copy-region t)

' (Mouse-yank-at-point t)

' (Save-place t Nil (saveplace))

' (Show-paren-mode t)

' (Transient-mark-mode t))

(custom-set-faces

;; Select the Mini toolbar icon

(tool-bar-mode-1)



///////////////////////////////////////

Also attached is a concise tutorial on Emacs Lisp, the water-wood Tsinghua produced,, Tut

http://smacs.github.io/elisp/

Simple use and configuration of Emacs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.