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
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
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
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 (-).
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
Emacs can execute shell commands
Emacs can be used as directory Editor (dired)
Emacs can edit, compile, and debug programs
Emacs can edit documents on other hosts
Emacs can print files
Emacs has a calendar and diary features
Emacs can be used to read the man page and info documents
Emacs can send and receive e-mails
Emacs can read the electronic bulletin Board (GNUS) on the network
Emacs has version-controlled functionality (CVS)
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
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.
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.
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
C-V: Flip down screen, same as PageDown effect (v-> vertical)
M-V: Flip up screen, same as PageUp effect
C-l: Redraw the screen and place the line of the cursor in the center of the screen
C-b: Cursor moves forward one cell (B->backward)
C-F: Move the cursor one cell backward (F->forward)
C-P: Cursor moves forward one line (p->previous)
C-N: Cursor moves backward one line (N->next)
M-b: Cursor moves forward one word
M-F: Cursor moves backward one word
C-A: Cursor moves to the beginning of the line
C-E: Cursor moves to end of line
M-<: Cursor moves to the beginning of the article (Note: "<" input to shift key, actual alt+shift+<)
M->: Cursor moves to the end of the article
C-u: Pass parameters to the command. For example: "C-u 2 c-d" means delete two characters
M-x goto-line n RET: Transfer to Nth row
* Edit Command
c-d: Delete a character after the cursor
C-k: Delete characters from cursor to end of line (K->KILLL)
C-x U:undo (want to redo, just type a character, at Undo)
C-SPC, [email protected], m-x Set-mark-command: Setting up Mark
C-x h: Sets the entire buffer to a region
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.
M-w: Copy area to yanking ring
C-y: Inserts the last area of the yanking ring into the current buffer
M-j: Enter and generate appropriate indent to the next line
M-M: Moves the cursor over the first non-whitespace character of the current line
m;: Generating generic annotations
M-x comment-region: Comment out the block
M-x kill-comment: removing annotations
* Find and replace
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
C-r: Search Forward
M-x replace-string: Replace
* File operation
C-x c-f: Open file, create if file does not exist
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>
C-x c-w: "Save File as"
C-x c-v: Opens a new file and closes the current buffer
C-x c-r: Open file in read-only mode
C-x i: Inserting a file into the cursor's current position
* Buffer
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.
C-x c-b List all current buffers (B->buffer)
C-x b buffer Name: Switch to the specified buffer (for example: C-x b m<tab>: Switch to buffer beginning with M)
C-x s: Save all buffers in Emacs (S->save)
C-x right: Switch to the next buffer
C-x left: Switch to the previous buffer
C-x c-c: Quit Emacs and ask the user whether to save
C-x k: Close buffer
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.
C-x 0: Close the window where the cursor is located
C-x 1: Keep the pane where the cursor is located and expand it to the entire screen while turning off all other panes
C-x 2: Split the current window horizontally
C-x 3: Split the current window vertically
C-x o: Toggle in Emacs's Pane (O->other)
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
C-h C Shortcut: A brief description of the display shortcut key
C-h K Shortcut: Displays the command name corresponding to the shortcut key and its detailed description
C-h a keyword: Displays commands with the specified keyword
C-h I: View info document
* Run shell commands in Emacs
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.
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.
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.
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.
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.
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
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.
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